Skip to content

--project=@script does not activate script project if outside of the Project Directory #55069

@awadell1

Description

@awadell1

Launching a script with julia --project=@script foo.jl does not activate the script project if ran outside the containing folder.

In test_at_script.jL

#!/usr/bin/env -S julia --project=@script
@info "Check Active Env" Base.active_project() PROGRAM_FILE LOAD_PATH Base.load_path_expand("@script")

# Check that ../Project.toml got activated
active_project = realpath(Base.active_project())
expected = realpath(joinpath(@__DIR__, "..", "Project.toml"))
@assert active_project == expected  "$active_project != $expected"

Expected Directory Structure:

Documents/
    julia_at_script_issue/
        Project.toml
        bin/
            test_at_script.jl

Alternatively, run script.sh in the attached achieve: julia_at_script_issue.zip

Running from Documents/julia_at_script_issue/ with julia --startup-file=no --project=@script bin/test_at_script.jl or ./bin/test_at_script.jl gives the following (expected) output:

❯ julia --startup-file=no --project=@script bin/test_at_script.jl
┌ Info: Check Active Env
│   Base.active_project() = "/Users/alexwadell/Documents/julia_at_script_issue/Project.toml"
│   PROGRAM_FILE = "bin/test_at_script.jl"
│   LOAD_PATH =
│    3-element Vector{String}:
│     "@""@v#.#""@stdlib"
└   Base.load_path_expand("@script") = "Project.toml"

However, running from outside of Documents/julia_at_script_issue activates the default environment instead:

❯ julia --project=@script --startup-file=no julia_at_script_issue/bin/test_at_script.jl
┌ Info: Check Active Env
│   Base.active_project() = "/Users/alexwadell/.julia/environments/v1.11/Project.toml"
│   PROGRAM_FILE = "julia_at_script_issue/bin/test_at_script.jl"
│   LOAD_PATH =
│    3-element Vector{String}:
│     "@""@v#.#""@stdlib"
└   Base.load_path_expand("@script") = "julia_at_script_issue/Project.toml"
ERROR: LoadError: AssertionError: /Users/alexwadell/.julia/environments/v1.11/Project.tom
l != /Users/alexwadell/Documents/julia_at_script_issue/Project.toml
Stacktrace:
 [1] top-level scope
   @ ~/Documents/julia_at_script_issue/bin/test_at_script.jl:5
in expression starting at /Users/alexwadell/Documents/julia_at_script_issue/bin/test_at_scr
ipt.jl:5

Oddly, enough Base.load_path_expand("@cript") resolves the correct project file.

Setting JULIA_LOAD_PATH directly does result in the expect behavior outside the project directory:

❯ JULIA_LOAD_PATH=@script julia --startup-file=no julia_at_script_issue/bin/test_at_script.jl
┌ Info: Check Active Env
│   Base.active_project() = "julia_at_script_issue/Project.toml"
│   PROGRAM_FILE = "julia_at_script_issue/bin/test_at_script.jl"
│   LOAD_PATH =
│    1-element Vector{String}:
│     "@script"
└   Base.load_path_expand("@script") = "julia_at_script_issue/Project.toml"

Julia Info

Julia Version 1.11.0-rc1
Commit 3a35aec36d1 (2024-06-25 10:23 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_PKG_USE_CLI_GIT = true

Related PRs

#50864
#53356

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions