Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/toml-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ UUIDs etc.
[Code Loading](https://docs.julialang.org/en/v1/manual/code-loading/)
in the Julia manual.


## `Project.toml`

The project file describes the project on a high level, for example, the package/project
Expand Down Expand Up @@ -542,3 +541,10 @@ uuid = "edca9bc6-334e-11e9-3554-9595dbb4349c"

There is now an array of the two `B` packages, and the `[deps]` section for `A` has been
expanded to be explicit about which `B` package `A` depends on.
## Portable scripts

Julia scripts can embed project and manifest data inline with fenced
comments such as `#!project … #!project end` and `#!manifest … #!manifest end`.
When the active project is set to a `.jl` file, Pkg reads and writes inline project metadata
from that file. All commands that modify the project or manifest
content (e.g. `Pkg.add`, `Pkg.rm`, `Pkg.update`) will update the inline sections accordingly.
41 changes: 30 additions & 11 deletions ext/REPLExt/REPLExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ function projname(project_file::String)
nothing
end
if project === nothing || project.name === nothing
name = basename(dirname(project_file))
# For .jl files, use the filename with extension as fallback
# For directories/Project.toml, use the directory name
if endswith(project_file, ".jl")
name = basename(project_file)
else
name = basename(dirname(project_file))
end
else
name = project.name::String
# For portable scripts, include .jl extension to make it clear
if endswith(project_file, ".jl")
name = project.name::String * ".jl"
else
name = project.name::String
end
end
for depot in Base.DEPOT_PATH
envdir = joinpath(depot, "environments")
Expand All @@ -94,17 +105,25 @@ function promptf()
else
project_name = projname(project_file)
if project_name !== nothing
root = Types.find_root_base_project(project_file)
rootname = projname(root)
if root !== project_file
path_prefix = "/" * dirname(Types.relative_project_path(root, project_file))
# For portable scripts (.jl files), don't show directory path
if endswith(project_file, ".jl")
if textwidth(project_name) > 30
project_name = first(project_name, 27) * "..."
end
prefix = "($(project_name)) "
else
path_prefix = ""
end
if textwidth(rootname) > 30
rootname = first(rootname, 27) * "..."
root = Types.find_root_base_project(project_file)
rootname = projname(root)
if root !== project_file
path_prefix = "/" * dirname(Types.relative_project_path(root, project_file))
else
path_prefix = ""
end
if textwidth(rootname) > 30
rootname = first(rootname, 27) * "..."
end
prefix = "($(rootname)$(path_prefix)) "
end
prefix = "($(rootname)$(path_prefix)) "
prev_prefix = prefix
prev_project_timestamp = mtime(project_file)
prev_project_file = project_file
Expand Down
8 changes: 6 additions & 2 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,10 @@ function activate(; temp = false, shared = false, prev = false, io::IO = stderr_
end
Base.ACTIVE_PROJECT[] = nothing
p = Base.active_project()
p === nothing || printpkgstyle(io, :Activating, "project at $(pathrepr(dirname(p)))")
if p !== nothing
loc = endswith(p, ".jl") ? pathrepr(p) : "$(pathrepr(dirname(p)))"
printpkgstyle(io, :Activating, "project at $loc")
end
add_snapshot_to_undo()
return nothing
end
Expand Down Expand Up @@ -1465,7 +1468,8 @@ function activate(path::AbstractString; shared::Bool = false, temp::Bool = false
p = Base.active_project()
if p !== nothing
n = ispath(p) ? "" : "new "
printpkgstyle(io, :Activating, "$(n)project at $(pathrepr(dirname(p)))")
loc = endswith(p, ".jl") ? pathrepr(p) : "$(pathrepr(dirname(p)))"
printpkgstyle(io, :Activating, "$(n)project at $loc")
end
add_snapshot_to_undo()
return nothing
Expand Down
8 changes: 4 additions & 4 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,8 @@ end
################################

function prune_manifest(env::EnvCache)
# if project uses another manifest, only prune project entry in manifest
if isempty(env.workspace) && dirname(env.project_file) != dirname(env.manifest_file)
# if project uses another manifest (and we are not a portable script), only prune project entry in manifest
if isempty(env.workspace) && dirname(env.project_file) != dirname(env.manifest_file) && !endswith(env.project_file, ".jl")
proj_entry = env.manifest[env.project.uuid]
proj_entry.deps = env.project.deps
else
Expand Down Expand Up @@ -3477,8 +3477,8 @@ function git_head_env(env, project_dir)
git_path = LibGit2.path(repo)
project_path = relpath(env.project_file, git_path)
manifest_path = relpath(env.manifest_file, git_path)
new_env.project = read_project(GitTools.git_file_stream(repo, "HEAD:$project_path", fakeit = true))
new_env.manifest = read_manifest(GitTools.git_file_stream(repo, "HEAD:$manifest_path", fakeit = true))
new_env.project = read_project(GitTools.git_file_stream(repo, "HEAD:$project_path", fakeit = true); source_file = project_path)
new_env.manifest = read_manifest(GitTools.git_file_stream(repo, "HEAD:$manifest_path", fakeit = true); source_file = manifest_path)
return new_env
end
catch err
Expand Down
Loading
Loading