Skip to content
Open
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
25 changes: 17 additions & 8 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ function add(
return
end

function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode = PKGMODE_PROJECT, all_pkgs::Bool = false, kwargs...)
function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode = PKGMODE_PROJECT, all_pkgs::Bool = false, workspace::Bool = false, kwargs...)
Context!(ctx; kwargs...)
Operations.ensure_manifest_registries!(ctx)
check_readonly(ctx)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
append_all_pkgs!(pkgs, ctx, mode)
append_all_pkgs!(pkgs, ctx, mode; workspace)
else
require_not_empty(pkgs, :rm)
end
Expand Down Expand Up @@ -414,12 +414,20 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode = PKGMODE_PROJECT, all
end


function append_all_pkgs!(pkgs, ctx, mode)
function append_all_pkgs!(pkgs, ctx, mode; workspace::Bool = false)
if mode == PKGMODE_PROJECT || mode == PKGMODE_COMBINED
for (name::String, uuid::UUID) in ctx.env.project.deps
path, repo = get_path_repo(ctx.env.project, ctx.env.project_file, ctx.env.manifest_file, name)
push!(pkgs, PackageSpec(name = name, uuid = uuid, path = path, repo = repo))
end
if workspace
for (_, project) in ctx.env.workspace
for (name::String, uuid::UUID) in project.deps
path, repo = get_path_repo(project, ctx.env.project_file, ctx.env.manifest_file, name)
push!(pkgs, PackageSpec(name = name, uuid = uuid, path = path, repo = repo))
end
end
end
end
if mode == PKGMODE_MANIFEST || mode == PKGMODE_COMBINED
for (uuid, entry) in ctx.env.manifest
Expand All @@ -436,6 +444,7 @@ function up(
preserve::Union{Nothing, PreserveLevel} = isempty(pkgs) ? nothing : PRESERVE_ALL,
update_registry::Bool = true,
skip_writing_project::Bool = false,
workspace::Bool = false,
kwargs...
)
Context!(ctx; kwargs...)
Expand All @@ -451,7 +460,7 @@ function up(
end
Operations.prune_manifest(ctx.env)
if isempty(pkgs)
append_all_pkgs!(pkgs, ctx, mode)
append_all_pkgs!(pkgs, ctx, mode; workspace)
else
mode == PKGMODE_PROJECT && project_deps_resolve!(ctx.env, pkgs)
mode == PKGMODE_MANIFEST && manifest_resolve!(ctx.env.manifest, pkgs)
Expand All @@ -472,13 +481,13 @@ function resolve(ctx::Context; skip_writing_project::Bool = false, kwargs...)
return nothing
end

function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool = false, kwargs...)
function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool = false, workspace::Bool = false, kwargs...)
Context!(ctx; kwargs...)
Operations.ensure_manifest_registries!(ctx)
check_readonly(ctx)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
append_all_pkgs!(pkgs, ctx, PKGMODE_MANIFEST)
append_all_pkgs!(pkgs, ctx, PKGMODE_MANIFEST; workspace)
else
require_not_empty(pkgs, :pin)
end
Expand Down Expand Up @@ -514,13 +523,13 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool = false, kw
return
end

function free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool = false, kwargs...)
function free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool = false, workspace::Bool = false, kwargs...)
Context!(ctx; kwargs...)
Operations.ensure_manifest_registries!(ctx)
check_readonly(ctx)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
append_all_pkgs!(pkgs, ctx, PKGMODE_MANIFEST)
append_all_pkgs!(pkgs, ctx, PKGMODE_MANIFEST; workspace)
else
require_not_empty(pkgs, :free)
end
Expand Down
25 changes: 18 additions & 7 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,16 @@ See also [`Pkg.precompile`](@ref).
autoprecompilation_enabled

"""
Pkg.rm(pkg::Union{String, Vector{String}}; mode::PackageMode = PKGMODE_PROJECT)
Pkg.rm(pkg::Union{PackageSpec, Vector{PackageSpec}}; mode::PackageMode = PKGMODE_PROJECT)
Pkg.rm(pkg::Union{String, Vector{String}}; mode::PackageMode = PKGMODE_PROJECT, workspace::Bool = false)
Pkg.rm(pkg::Union{PackageSpec, Vector{PackageSpec}}; mode::PackageMode = PKGMODE_PROJECT, workspace::Bool = false)

Remove a package from the current project. If `mode` is equal to
`PKGMODE_MANIFEST` also remove it from the manifest including all
recursive dependencies of `pkg`.

If `workspace` is `true` and `all_pkgs` is `true`, packages from all projects in the workspace
will be included.

See also [`PackageSpec`](@ref), [`PackageMode`](@ref).
"""
const rm = API.rm
Expand All @@ -335,7 +338,7 @@ If `workspace` is true, this will consider all projects in the workspace and not
const why = API.why

"""
Pkg.update(; level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode = PKGMODE_PROJECT, preserve::PreserveLevel)
Pkg.update(; level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode = PKGMODE_PROJECT, preserve::PreserveLevel, workspace::Bool = false)
Pkg.update(pkg::Union{String, Vector{String}})
Pkg.update(pkg::Union{PackageSpec, Vector{PackageSpec}})

Expand All @@ -347,6 +350,8 @@ If packages are given as positional arguments, the `preserve` argument can be us
- `PRESERVE_DIRECT`: Only allow `pkg` and indirect dependencies that are not a direct dependency in the project to update.
- `PRESERVE_NONE`: Allow `pkg` and all its indirect dependencies to update.

If `workspace` is `true`, packages from all projects in the workspace will be included when no packages are specified.

After any package updates the project will be precompiled. See more at [Environment Precompilation](@ref).

See also [`PackageSpec`](@ref), [`PackageMode`](@ref), [`UpgradeLevel`](@ref).
Expand Down Expand Up @@ -457,14 +462,17 @@ If using the startup file (`~/.julia/config/startup.jl`) is desired, start julia
const build = API.build

"""
Pkg.pin(pkg::Union{String, Vector{String}}; io::IO=stderr, all_pkgs::Bool=false)
Pkg.pin(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr, all_pkgs::Bool=false)
Pkg.pin(pkg::Union{String, Vector{String}}; io::IO=stderr, all_pkgs::Bool=false, workspace::Bool=false)
Pkg.pin(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr, all_pkgs::Bool=false, workspace::Bool=false)

Pin a package to the current version (or the one given in the `PackageSpec`) or to a certain
git revision. A pinned package is never automatically updated: if `pkg` is tracking a path,
or a repository, those remain tracked but will not update.
To get updates from the origin path or remote repository the package must first be freed.

If `workspace` is `true` and `all_pkgs` is `true`, packages from all projects in the workspace
will be included.

!!! compat "Julia 1.7"
The `all_pkgs` kwarg was introduced in julia 1.7.

Expand All @@ -483,13 +491,16 @@ Pkg.pin(all_pkgs = true)
const pin = API.pin

"""
Pkg.free(pkg::Union{String, Vector{String}}; io::IO=stderr, all_pkgs::Bool=false)
Pkg.free(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr, all_pkgs::Bool=false)
Pkg.free(pkg::Union{String, Vector{String}}; io::IO=stderr, all_pkgs::Bool=false, workspace::Bool=false)
Pkg.free(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr, all_pkgs::Bool=false, workspace::Bool=false)

If `pkg` is pinned, remove the pin.
If `pkg` is tracking a path, e.g. after [`Pkg.develop`](@ref), go back to tracking registered versions.
To free all dependencies set `all_pkgs=true`.

If `workspace` is `true` and `all_pkgs` is `true`, packages from all projects in the workspace
will be included.

!!! compat "Julia 1.7"
The `all_pkgs` kwarg was introduced in julia 1.7.

Expand Down
32 changes: 21 additions & 11 deletions src/REPLMode/command_declarations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ compound_declarations = [
PSA[:name => "project", :short_name => "p", :api => :mode => PKGMODE_PROJECT],
PSA[:name => "manifest", :short_name => "m", :api => :mode => PKGMODE_MANIFEST],
PSA[:name => "all", :api => :all_pkgs => true],
PSA[:name => "workspace", :api => :workspace => true],
],
:completions => :complete_installed_packages,
:description => "remove packages from project or manifest",
:help => md"""
[rm|remove] [-p|--project] pkg[=uuid] ...
[rm|remove] [-p|--project] [--all]
[rm|remove] [-p|--project] [--workspace] pkg[=uuid] ...
[rm|remove] [-p|--project] [--workspace] [--all]

Remove package `pkg` from the project file. Since the name `pkg` can only
refer to one package in a project this is unambiguous, but you can specify
Expand All @@ -92,9 +93,11 @@ compound_declarations = [
the project. Project mode operation is the default, so passing `-p` or
`--project` is optional unless it is preceded by the `-m` or `--manifest`
options at some earlier point. All packages can be removed by passing `--all`.
The `--workspace` option includes packages from all projects in the workspace
when used with `--all`.

[rm|remove] [-m|--manifest] pkg[=uuid] ...
[rm|remove] [-m|--manifest] [--all]
[rm|remove] [-m|--manifest] [--workspace] pkg[=uuid] ...
[rm|remove] [-m|--manifest] [--workspace] [--all]

Remove package `pkg` from the manifest file. If the name `pkg` refers to
multiple packages in the manifest, `uuid` disambiguates it. Removing a package
Expand Down Expand Up @@ -224,16 +227,18 @@ compound_declarations = [
:arg_count => 0 => Inf,
:option_spec => [
PSA[:name => "all", :api => :all_pkgs => true],
PSA[:name => "workspace", :api => :workspace => true],
],
:arg_parser => parse_package,
:completions => :complete_fixed_packages,
:description => "undoes a `pin`, `develop`, or stops tracking a repo",
:help => md"""
free pkg[=uuid] ...
free [--all]
free [--workspace] pkg[=uuid] ...
free [--workspace] [--all]

Free pinned packages, which allows it to be upgraded or downgraded again. If the package is checked out (see `help develop`) then this command
makes the package no longer being checked out. Specifying `--all` will free all dependencies (direct and indirect).
The `--workspace` option includes packages from all projects in the workspace when used with `--all`.
""",
],
PSA[
Expand Down Expand Up @@ -266,16 +271,18 @@ compound_declarations = [
:arg_count => 0 => Inf,
:option_spec => [
PSA[:name => "all", :api => :all_pkgs => true],
PSA[:name => "workspace", :api => :workspace => true],
],
:arg_parser => parse_package,
:completions => :complete_installed_packages,
:description => "pins the version of packages",
:help => md"""
pin pkg[=uuid] ...
pin [--all]
pin [--workspace] pkg[=uuid] ...
pin [--workspace] [--all]

Pin packages to given versions, or the current version if no version is specified. A pinned package has its version fixed and will not be upgraded or downgraded.
A pinned package has the symbol `⚲` next to its version in the status list.. Specifying `--all` will pin all dependencies (direct and indirect).
A pinned package has the symbol `⚲` next to its version in the status list. Specifying `--all` will pin all dependencies (direct and indirect).
The `--workspace` option includes packages from all projects in the workspace when used with `--all`.

**Examples**
```
Expand Down Expand Up @@ -368,12 +375,13 @@ compound_declarations = [
PSA[:name => "patch", :api => :level => UPLEVEL_PATCH],
PSA[:name => "fixed", :api => :level => UPLEVEL_FIXED],
PSA[:name => "preserve", :takes_arg => true, :api => :preserve => do_preserve],
PSA[:name => "workspace", :api => :workspace => true],
],
:completions => :complete_installed_packages,
:description => "update packages in manifest",
:help => md"""
[up|update] [-p|--project] [opts] pkg[=uuid] [@version] ...
[up|update] [-m|--manifest] [opts] pkg[=uuid] [@version] ...
[up|update] [-p|--project] [--workspace] [opts] pkg[=uuid] [@version] ...
[up|update] [-m|--manifest] [--workspace] [opts] pkg[=uuid] [@version] ...

opts: --major | --minor | --patch | --fixed
--preserve=<all/direct/none>
Expand All @@ -386,6 +394,8 @@ compound_declarations = [
the following packages to be upgraded only within the current major, minor,
patch version; if the `--fixed` upgrade level is given, then the following
packages will not be upgraded at all.
The `--workspace` option includes packages from all projects in the workspace
when no packages are specified.

After any package updates the project will be precompiled. For more information see `pkg> ?precompile`.
""",
Expand Down