Skip to content

Commit

Permalink
Automatically add compat bounds when adding package in non-shared env
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Nov 29, 2024
1 parent 83e1363 commit 08595b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,12 @@ function _resolve(io::IO, env::EnvCache, registries::Vector{Registry.RegistryIns
end
end

# A shared environment lives in the "environments" subdirectory of a depot.
function is_shared_env(project_file::String)
parent_parent = dirname(dirname(project_file))
return basename(parent_parent) == "environments" && dirname(parent_parent) in Base.DEPOT_PATH
end

function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
allow_autoprecomp::Bool=true, preserve::PreserveLevel=default_preserve(), platform::AbstractPlatform=HostPlatform(),
target::Symbol=:deps)
Expand Down Expand Up @@ -1658,8 +1664,8 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
# and ensure they are all downloaded and unpacked as well:
download_artifacts(ctx, platform=platform, julia_version=ctx.julia_version)

# if env is a package add compat entries
if ctx.env.project.name !== nothing && ctx.env.project.uuid !== nothing
# If the environment isn't a shared one add compat entries
if !is_shared_env(ctx.env.project_file)
compat_names = String[]
for pkg in pkgs
haskey(ctx.env.project.compat, pkg.name) && continue
Expand Down
2 changes: 1 addition & 1 deletion src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Add a package to the current project. This package will be available by using th
`import` and `using` keywords in the Julia REPL, and if the current project is
a package, also inside that package.
If the active environment is a package (the Project has both `name` and `uuid` fields) compat entries will be
If the active environment is not a shared one compat entries will be
added automatically with a lower bound of the added version.
To add as a weak dependency (in the `[weakdeps]` field) set the kwarg `target=:weakdeps`.
Expand Down
2 changes: 1 addition & 1 deletion src/REPLMode/command_declarations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ are of the form `@1`, `@1.2` or `@1.2.3`, allowing any version with a prefix
that matches, or ranges thereof, such as `@1.2-3.4.5`. A git revision can be
specified by `#branch` or `#commit`.
If the active environment is a package (the Project has both `name` and `uuid` fields) compat entries will be
If the active environment is not a shared one compat entries will be
added automatically with a lower bound of the added version.
If a local path is used as an argument to `add`, the path needs to be a git repository.
Expand Down

0 comments on commit 08595b3

Please sign in to comment.