Skip to content
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

Add directory to $PATH #2572

Closed
woutervh opened this issue Jan 13, 2025 · 6 comments
Closed

Add directory to $PATH #2572

woutervh opened this issue Jan 13, 2025 · 6 comments

Comments

@woutervh
Copy link

using just 1.38.0:

Usecase: I want to add the bin-directory of my python virtualenv to $PATH for all recipes:

venv_bin_dir := justfile_directory() + "/.venv/bin"   # resolves to correct folder

export PATH := "{{venv_bin_dir}}:${PATH}"  # error


demo:
    @ echo "abs venv_bin: {{venv_bin_dir}}"

but this fails with:

error: Recipe `demo` could not be run because just could not find the shell: No such file or directory (os error 2)

This also fails:

venv_bin_dir := justfile_directory() + "/.venv/bin"
OLD_PATH := env("PATH")
export PATH := "{{venv_bin_dir}}:{{OLD_PATH}}"

am I using the wrong syntax?
Is this a bug? Or not implemented?

@laniakea64
Copy link
Contributor

  1. Interpolations in strings are not currently implemented, see Allow interpolation inside of backticks and strings #11

  2. Shell-expanded strings are prefixed with x.

So try this? -

venv_bin_dir := justfile_directory() / ".venv/bin"
export PATH := venv_bin_dir + x':${PATH}'

@casey
Copy link
Owner

casey commented Jan 14, 2025

@laniakea64's suggestion should work. This does make me think that perhaps we should provide a cross-paltform function to add directories to PATH, since windows uses ;.

@casey casey closed this as completed Jan 14, 2025
@woutervh
Copy link
Author

this syntax indeed works

venv_bin_dir := justfile_directory() / ".venv/bin"
export PATH := venv_bin_dir + x':${PATH}'

but again the same error when tying to make it crossplatform with:

export PATH := if os_family() == "windows" { venv_bin_dir + ";${PATH}" } else { venv_bin_dir + ":${PATH}" }

@laniakea64
Copy link
Contributor

That line is missing the x prefix on the strings intended to be shell-expanded:

export PATH := if os_family() == "windows" { venv_bin_dir + x";${PATH}" } else { venv_bin_dir + x":${PATH}" }

@woutervh
Copy link
Author

As Homer would say "Dooh!"
Many thanks.

@woutervh
Copy link
Author

see also #2597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants