Execute consecutive scripts

Is there a simple way to execute either multiple scripts consecutively, or execute a script with some additional imports? Consider this use case: I have a NN training script, and if I import CUDA, it trains on the GPU. Currently the script looks like this:

#import CUDA
using Flux, StatsBase
...

When I want to run this on the GPU, I uncomment the first line, but this is cumbersome. Ideally I want to trigger the GPU behaviour by specifying import CUDA in the command line:

julia --eval "import CUDA" ./nn.jl

but this does not achieve my objective.

This sounds like an XY problem. For your example the most straightforward approach would be to use ARGS (or e.g. ArgParse.jl) to supply an option (like --device CUDA) via the command-line. See also Command-line Interface · The Julia Language.

This isn’t an XY problem. In my setup I have a master project that has no GPU package dependency, and there are derived projects based on CUDA and AMDGPU. The reason I do this is one monolithic project having all the CUDA/AMDGPU dependencies would have to download a ton of artefacts and create huge docker images.

I don’t think you can conditionally import a package. If you import the CUDA package while in the AMDGPU or master project environment it will give you an error. This is why I don’t think the command line approach would work.

Could you provide a MWE showing what the environment structure looks like, and how nn.jl makes the switch between CUDA, AMDGPU and the CPU fallback?

Perhaps you could write package extensions for CUDA.jl and AMDGPU.jl?