Skip to content

Commit 5d8bd50

Browse files
committed
call it standalone
1 parent 6bbc2c9 commit 5d8bd50

File tree

12 files changed

+48
-43
lines changed

12 files changed

+48
-43
lines changed

base/client.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function exec_options(opts)
277277

278278
if arg_is_program && PROGRAM_FILE != "-" && Base.active_project(false) === nothing
279279
script_path = abspath(PROGRAM_FILE)
280-
Base.is_script(script_path) && Base.set_active_project(script_path)
280+
Base.is_standalone_script(script_path) && Base.set_active_project(script_path)
281281
end
282282

283283
# Load Distributed module only if any of the Distributed options have been specified.
@@ -347,12 +347,12 @@ function exec_options(opts)
347347
include_string(Main, read(stdin, String), "stdin")
348348
else
349349
abs_script_path = abspath(PROGRAM_FILE)
350-
if is_script(abs_script_path)
351-
set_script_state(abs_script_path)
350+
if is_standalone_script(abs_script_path)
351+
set_standalone_script_state(abs_script_path)
352352
try
353353
include(Main, PROGRAM_FILE)
354354
finally
355-
global script_state_global = nothing
355+
global standalone_script_state_global = nothing
356356
end
357357
else
358358
include(Main, PROGRAM_FILE)

base/initdefs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
288288
program_file = program_file != C_NULL ? unsafe_string(program_file) : nothing
289289
isnothing(program_file) && return nothing # User did not pass a script
290290

291-
# Check if the program file itself is a script first
292-
if env == "@script" && Base.is_script(program_file)
291+
# Check if the program file itself is a standalone script first
292+
if env == "@script" && Base.is_standalone_script(program_file)
293293
return abspath(program_file)
294294
end
295295

@@ -333,7 +333,7 @@ load_path_expand(::Nothing) = nothing
333333
active_project()
334334
335335
Return the path of the active project (either a `Project.toml` file or a julia
336-
file when using a [script](@ref scripts)).
336+
file when using a [standalone script](@ref standalone-scripts)).
337337
See also [`Base.set_active_project`](@ref).
338338
"""
339339
function active_project(search_load_path::Bool=true)
@@ -364,7 +364,7 @@ end
364364
set_active_project(projfile::Union{AbstractString,Nothing})
365365
366366
Set the active `Project.toml` file to `projfile`. The `projfile` can be a path to a traditional
367-
`Project.toml` file, a [script](@ref scripts) with inline metadata, or `nothing`
367+
`Project.toml` file, a [standalone script](@ref standalone-scripts) with inline metadata, or `nothing`
368368
to clear the active project. See also [`Base.active_project`](@ref).
369369
370370
!!! compat "Julia 1.8"
@@ -386,7 +386,7 @@ end
386386
active_manifest(project_file::AbstractString)
387387
388388
Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`.
389-
When a [script](@ref scripts) is active, this returns the script path itself.
389+
When a [standalone script](@ref standalone-scripts) is active, this returns the script path itself.
390390
391391
In a stacked environment (where multiple environments exist in the load path), this returns the manifest
392392
file for the primary (active) environment only, not the manifests from other environments in the stack.

base/loading.jl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,36 +323,36 @@ function extract_inline_section(path::String, type::Symbol)
323323
end
324324
end
325325

326-
function is_script(path::String)::Bool
326+
function is_standalone_script(path::String)::Bool
327327
for line in eachline(path)
328328
stripped = lstrip(line)
329-
# Only whitespace and comments allowed before #!script
329+
# Only whitespace and comments allowed before #!standalone
330330
if !isempty(stripped) && !startswith(stripped, '#')
331331
return false
332332
end
333-
if startswith(stripped, "#!script")
333+
if startswith(stripped, "#!standalone")
334334
return true
335335
end
336336
end
337337
return false
338338
end
339339

340340

341-
struct ScriptState
341+
struct StandaloneScriptState
342342
path::String
343343
pkg::PkgId
344344
end
345345

346-
script_state_global::Union{ScriptState, Nothing} = nothing
346+
standalone_script_state_global::Union{StandaloneScriptState, Nothing} = nothing
347347

348-
function set_script_state(abs_path::Union{Nothing, String})
348+
function set_standalone_script_state(abs_path::Union{Nothing, String})
349349
pkg = project_file_name_uuid(abs_path, splitext(basename(abs_path))[1])
350350

351351
# Verify the project and manifest delimiters:
352352
parsed_toml(abs_path)
353353
parsed_toml(abs_path; manifest=true)
354354

355-
global script_state_global = ScriptState(abs_path, pkg)
355+
global standalone_script_state_global = StandaloneScriptState(abs_path, pkg)
356356
end
357357

358358

@@ -385,7 +385,7 @@ function parsed_toml(toml_file::AbstractString, toml_cache::TOMLCache, toml_lock
385385
manifest::Bool=false, project::Bool=!manifest)
386386
manifest && project && throw(ArgumentError("cannot request both project and manifest TOML"))
387387
lock(toml_lock) do
388-
# Script?
388+
# Standalone script?
389389
if endswith(toml_file, ".jl") && isfile_casesensitive(toml_file)
390390
kind = manifest ? :manifest : :project
391391
cache_key = "$(toml_file)::$(kind)"
@@ -451,8 +451,8 @@ Same as [`Base.identify_package`](@ref) except that the path to the environment
451451
is also returned, except when the identity is not identified.
452452
"""
453453
function identify_package_env(where::Module, name::String)
454-
if where === Main && script_state_global !== nothing
455-
return identify_package_env(script_state_global.pkg, name)
454+
if where === Main && standalone_script_state_global !== nothing
455+
return identify_package_env(standalone_script_state_global.pkg, name)
456456
end
457457
return identify_package_env(PkgId(where), name)
458458
end
@@ -780,7 +780,12 @@ function env_project_file(env::String)::Union{Bool,String}
780780
elseif basename(env) in project_names && isfile_casesensitive(env)
781781
project_file = env
782782
elseif endswith(env, ".jl") && isfile_casesensitive(env)
783-
project_file = is_script(env) ? env : false
783+
if is_standalone_script(env)
784+
project_file = env
785+
end
786+
#else
787+
# error("$env is missing #!standalone marker")
788+
#end
784789
else
785790
project_file = false
786791
end
@@ -1038,7 +1043,7 @@ function project_file_manifest_path(project_file::String)::Union{Nothing,String}
10381043
end
10391044
end
10401045
if manifest_path === nothing && endswith(project_file, ".jl") && has_file
1041-
# script: manifest is the same file as the project file
1046+
# standalone script: manifest is the same file as the project file
10421047
manifest_path = project_file
10431048
end
10441049
if manifest_path === nothing

doc/src/manual/code-loading.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,13 @@ are stored in the manifest file in the section for that package. The dependency
397397
a package are the same as for its "parent" except that the listed triggers are also considered as
398398
dependencies.
399399

400-
### [Scripts](@id scripts)
400+
### [Standalone Scripts](@id standalone-scripts)
401401

402-
Julia also understands *scripts* that can embed their own `Project.toml` (and optionally `Manifest.toml`) so they can be executed as self-contained environments. A script is identified by a `#!script` marker at the top of the file (only whitespace and comments may appear before it). The embedded project and manifest data are placed inside comment fences named `#!project` and `#!manifest`:
402+
Julia also understands *standalone scripts* that can embed their own `Project.toml` (and optionally `Manifest.toml`) so they can be executed as self-contained environments. A standalone script is identified by a `#!standalone` marker at the top of the file (only whitespace and comments may appear before it). The embedded project and manifest data are placed inside comment fences named `#!project` and `#!manifest`:
403403

404404
```julia
405405
#!/usr/bin/env julia
406-
#!script
406+
#!standalone
407407

408408
using Markdown
409409
println(md"# Hello, single-file world!")
@@ -424,9 +424,9 @@ println(md"# Hello, single-file world!")
424424
#!manifest end
425425
```
426426

427-
Lines inside the fenced blocks should be commented with `#` (as in the example) or be plain TOML lines. The `#!script` marker must appear at the top of the file, with only whitespace and comments (including an optional shebang) allowed before it. The `#!project` and `#!manifest` sections can appear anywhere in the file (by convention at the bottom), but `#!project` must come before `#!manifest` if both are present.
427+
Lines inside the fenced blocks should be commented with `#` (as in the example) or be plain TOML lines. The `#!standalone` marker must appear at the top of the file, with only whitespace and comments (including an optional shebang) allowed before it. The `#!project` and `#!manifest` sections can appear anywhere in the file (by convention at the bottom), but `#!project` must come before `#!manifest` if both are present.
428428

429-
Running `julia hello.jl` automatically activates the embedded project if the file contains a `#!script` marker. The dependency loading rules for such a script is the same as for a package with the same project and manifest file. The `--project=@script` flag also expands to the script itself if the `#!script` marker is present. Using `--project=script.jl` explicitly requires that the script contains the `#!script` marker.
429+
Running `julia hello.jl` automatically activates the embedded project if the file contains a `#!standalone` marker. The dependency loading rules for such a standalone script is the same as for a package with the same project and manifest file. The `--project=@script` flag also expands to the script itself if the `#!standalone` marker is present. Using `--project=script.jl` explicitly requires that the script contains the `#!standalone` marker.
430430

431431
### [Workspaces](@id workspaces)
432432

test/loading.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ module M58272_to end
18711871
@eval M58272_to import ..M58272_1: M58272_2.y, x
18721872
@test @eval M58272_to x === 1
18731873

1874-
@testset "Scripts" begin
1874+
@testset "Standalone Scripts" begin
18751875
# Test with line-by-line comment syntax and path dependencies
18761876
script = joinpath(@__DIR__, "project", "scripts", "script.jl")
18771877
output = read(`$(Base.julia_cmd()) --startup-file=no $script`, String)
@@ -1893,14 +1893,14 @@ module M58272_to end
18931893
@test occursin("✓ Random.rand()", output_cm)
18941894
@test occursin("✓ All checks passed!", output_cm)
18951895

1896-
# Test @script behavior with script
1896+
# Test @script behavior with standalone script
18971897
# When using --project=@script, it should use the script file as the project
18981898
output_script = read(`$(Base.julia_cmd()) --startup-file=no --project=@script $script`, String)
18991899
@test occursin("Active project: $script", output_script)
19001900
@test occursin("Active manifest: $script", output_script)
19011901
@test occursin("✓ Random (stdlib) loaded successfully", output_script)
19021902

1903-
# Test that regular Julia files (without #!script) can be set as active project
1903+
# Test that regular Julia files (without #!standalone) can be set as active project
19041904
regular_script = joinpath(@__DIR__, "project", "scripts", "regular_script.jl")
19051905

19061906
# Running the script with --project= should set it as active project
@@ -1921,7 +1921,7 @@ module M58272_to end
19211921
@test !success(result)
19221922
@test occursin("Package Rot13 not found in current path", String(take!(err_output)))
19231923

1924-
# Test 1: #!script marker not at top (has code before it) - runs as regular script
1924+
# Test 1: #!standalone marker not at top (has code before it) - runs as regular script
19251925
invalid_project_not_first = joinpath(@__DIR__, "project", "scripts", "invalid_project_not_first.jl")
19261926
result = run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no $invalid_project_not_first`)))
19271927
@test success(result)
@@ -1933,22 +1933,22 @@ module M58272_to end
19331933
@test !success(result)
19341934
@test occursin("#!manifest section must come after #!project section", String(take!(err_output)))
19351935

1936-
# Test 3: Code before #!script marker with --project - should error
1936+
# Test 3: Code before #!standalone marker with --project - should error
19371937
invalid_both = joinpath(@__DIR__, "project", "scripts", "invalid_both.jl")
19381938
err_output = IOBuffer()
19391939
result = run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --project=$invalid_both -e "using Test"`), stderr=err_output))
19401940
@test !success(result)
1941-
@test occursin("is missing #!script marker", String(take!(err_output)))
1941+
@test occursin("is missing #!standalone marker", String(take!(err_output)))
19421942

19431943
# Test 4: Code between sections is now valid
19441944
valid_code_between = joinpath(@__DIR__, "project", "scripts", "valid_code_between.jl")
19451945
result = run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no $valid_code_between`)))
19461946
@test success(result)
19471947

1948-
# Test 5: Using --project on a non-script file errors when loading packages
1948+
# Test 5: Using --project on a non-standalone script file errors when loading packages
19491949
regular_script = joinpath(@__DIR__, "project", "scripts", "regular_script.jl")
19501950
err_output = IOBuffer()
19511951
result = run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --project=$regular_script -e "using Test"`), stderr=err_output))
19521952
@test !success(result)
1953-
@test occursin("is missing #!script marker", String(take!(err_output)))
1953+
@test occursin("is missing #!standalone marker", String(take!(err_output)))
19541954
end

test/project/scripts/invalid_both.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function foo()
22
return 42
33
end
44

5-
#!script
5+
#!standalone
66

77
#!project begin
88
#!project end

test/project/scripts/invalid_manifest_not_last.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!script
1+
#!standalone
22

33
#!manifest begin
44
# julia_version = "1.11.0"

test/project/scripts/invalid_project_not_first.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Some code before #!script marker
1+
# Some code before #!standalone marker
22

33
x = 1
44

5-
#!script
5+
#!standalone
66

77
#!project begin
88
# name = "Test"

test/project/scripts/script.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env julia
2-
#!script
2+
#!standalone
33

44
#!project begin
55
# name = "PortableScriptTest"
@@ -15,7 +15,7 @@ using Random
1515
using Test
1616
using Rot13
1717

18-
# Verify the script environment is active
18+
# Verify the standalone script environment is active
1919
println("Active project: ", Base.active_project())
2020
println("Active manifest: ", Base.active_manifest())
2121
println()

test/project/scripts/script_custom_manifest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env julia
2-
#!script
2+
#!standalone
33

44
#!project begin
55
# name = "PortableScriptCustomManifestTest"

0 commit comments

Comments
 (0)