-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow --project=@scriptdir
for easier co-packaging of scripts and p…
#50864
Conversation
…rojects I have a directory with a number of runnable scripts and a Project.toml that applies to all of them. I was hoping to have a simple shebang line for these, but there didn't really seem to be a good way to set the `--project` without forcing the script to be invoked with a specific cwd or playing complicated shebang games. With this PR, you can simply write: ``` #!/usr/bin/env -S julia --project=@scriptdir/.. ``` and everything will work out of the box. Perhaps we already have a good mechanism for this, but if so, I was unable to find it, so in that case, consider this a documentation issue instead ;).
The CLI docs calls the "script" argument as "programfile". So should it be "programdir"? |
I don't really care about the name, but a little worried that |
The feature itself seems reasonable to me. Most scripts resort to using |
SGTM. I guess the only issue is that GNU only added this Random thought: could we potentially detect if the interpreter and script (
Or could we simply make something like this the default when handling a given script as the argument, unless specified otherwise? |
We could, but I don't think it's clear that we always know which is the correct Project to use. We could potentially consider doing our own shebang parsing so you could do something like:
but that seems orthogonal. I also think it's fine to rely on |
Busybox in particular does not have options for |
The reason this is not done is AFAIU to prevent a malicious Manifest file that's been accidentally downloaded into e.g. |
Seems like people generally agree that this could be reasonably useful, so I'm just gonna get this in so people can play with it. If people want a different name, we can still change it until the 1.11 release. |
I think this should be documented and get a NEWS entry. Currently on 1.9 this syntax activates a shared environment named ❯ julia --project=@scriptdir
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
(@scriptdir) pkg> st
Status `~/.julia/environments/scriptdir/Project.toml` (empty project) That seems somewhat of an edge case but a NEWS entry would probably at least help alert folks to this change if they happen to be using a shared environment with that name. |
While this is unlikely to break anyone's workflow in practice, it would be nice if we systematized this right away and had a clear distinction between "This refers to a shared environment" vs "This refers to special keyword (like scriptdir) that has specific behaviour". Some options are:
Adopting any one of these will help both in making it highly unlikely that these special options clash with existing shared environments, and with making it clear immediately at a glance that this is a custom value being given to the option. |
We have an convention already of
|
Yes, That's why I'm suggesting that it should have unique syntax indicating that something new is going on here, and not just a usual shared environment activation. |
I like this idea! A little thought though, what about instead of doing |
What happens if I have a global shared environment called "scriptdir". Normally, I would access it via |
I like passing arguments via the initial comment block. There is precedent for this in SLURM. https://slurm.schedmd.com/sbatch.html
|
…rojects
I have a directory with a number of runnable scripts and a Project.toml that applies to all of them. I was hoping to have a simple shebang line for these, but there didn't really seem to be a good way to set the
--project
without forcing the script to be invoked with a specific cwd or playing complicated shebang games. With this PR, you can simply write:and everything will work out of the box. Perhaps we already have a good mechanism for this, but if so, I was unable to find it, so in that case, consider this a documentation issue instead ;).