Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick proof of concept of down #3802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 12 additions & 4 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function require_not_empty(pkgs, f::Symbol)
end

# Provide some convenience calls
for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status, :why, :precompile)
for f in (:develop, :add, :rm, :up, :down, :pin, :free, :test, :build, :status, :why, :precompile)
@eval begin
$f(pkg::Union{AbstractString, PackageSpec}; kwargs...) = $f([pkg]; kwargs...)
$f(pkgs::Vector{<:AbstractString}; kwargs...) = $f([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
Expand All @@ -156,8 +156,8 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status, :why, :
pkgs = deepcopy(pkgs) # don't mutate input
foreach(handle_package_input!, pkgs)
ret = $f(ctx, pkgs; kwargs...)
$(f in (:up, :pin, :free, :build)) && Pkg._auto_precompile(ctx)
$(f in (:up, :pin, :free, :rm)) && Pkg._auto_gc(ctx)
$(f in (:up, :pin, :free, :build, :down)) && Pkg._auto_precompile(ctx)
$(f in (:up, :pin, :free, :rm, :down)) && Pkg._auto_gc(ctx)
return ret
end
$f(ctx::Context; kwargs...) = $f(ctx, PackageSpec[]; kwargs...)
Expand Down Expand Up @@ -333,7 +333,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
printpkgstyle(ctx.io, :Update, "All dependencies are pinned - nothing to update.", color = Base.info_color())
return
end
if update_registry
if false # update_registry
Registry.download_default_registries(ctx.io)
Operations.update_registries(ctx; force=true)
end
Expand All @@ -351,6 +351,14 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
return
end

function down(ctx::Context, pkgs::Vector{PackageSpec};
kwargs...)
if !isempty(pkgs)
pkgerror("`down` can only be called without specifying packages")
end
return up(ctx, pkgs; level=UPLEVEL_DOWN)
end

resolve(; io::IO=stderr_f(), kwargs...) = resolve(Context(;io); kwargs...)
function resolve(ctx::Context; skip_writing_project::Bool=false, kwargs...)
up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, skip_writing_project, kwargs...)
Expand Down
30 changes: 29 additions & 1 deletion src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,40 @@ function up_load_versions!(ctx::Context, pkg::PackageSpec, entry::PackageEntry,
r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) :
level == UPLEVEL_MINOR ? VersionRange(ver.major) :
level == UPLEVEL_MAJOR ? VersionRange() :
error("unexpected upgrade level: $level")
level == UPLEVEL_DOWN ? begin
if !is_tracking_registry(pkg) || is_stdlib(pkg.uuid)
VersionRange()
else
compat = get(ctx.env.project.compat, pkg.name, nothing)
vr = compat === nothing ? VersionRange() : compat.val
lowest_version(pkg, ctx.registries, vr)
end
end :
error("unexpected upgrade level: $level")
pkg.version = VersionSpec(r)
end
return false
end

function lowest_version(pkg, registries, vr::VersionSpec)
minv = nothing
for reg in registries
rpkg = get(reg, pkg.uuid, nothing)
rpkg === nothing && continue
pkginfo = Registry.registry_info(rpkg)
matching_versions = filter(in(vr), keys(pkginfo.version_info))
if !isempty(matching_versions)
min_match = minimum(matching_versions)
minv = minv === nothing ? min_match : minv < min_match ? minv : min_match
end
end
if minv === nothing
pkgerror("Did not find any version matching $vr in registries")
end
@info "Fixing $(pkg.name) to version $minv"
return minv
end

up_load_manifest_info!(pkg::PackageSpec, ::Nothing) = nothing
function up_load_manifest_info!(pkg::PackageSpec, entry::PackageEntry)
pkg.name = entry.name # TODO check name is same
Expand Down
5 changes: 3 additions & 2 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using Dates
export @pkg_str
export PackageSpec
export PackageMode, PKGMODE_MANIFEST, PKGMODE_PROJECT
export UpgradeLevel, UPLEVEL_MAJOR, UPLEVEL_MINOR, UPLEVEL_PATCH
export UpgradeLevel, UPLEVEL_MAJOR, UPLEVEL_MINOR, UPLEVEL_PATCH, UPLEVEL_DOWN
export PreserveLevel, PRESERVE_TIERED_INSTALLED, PRESERVE_TIERED, PRESERVE_ALL_INSTALLED, PRESERVE_ALL, PRESERVE_DIRECT, PRESERVE_SEMVER, PRESERVE_NONE
export Registry, RegistrySpec

Expand Down Expand Up @@ -68,7 +68,7 @@ include("API.jl")
include("REPLMode/REPLMode.jl")

import .REPLMode: @pkg_str
import .Types: UPLEVEL_MAJOR, UPLEVEL_MINOR, UPLEVEL_PATCH, UPLEVEL_FIXED
import .Types: UPLEVEL_MAJOR, UPLEVEL_MINOR, UPLEVEL_PATCH, UPLEVEL_FIXED, UPLEVEL_DOWN
import .Types: PKGMODE_MANIFEST, PKGMODE_PROJECT
import .Types: PRESERVE_TIERED_INSTALLED, PRESERVE_TIERED, PRESERVE_ALL_INSTALLED, PRESERVE_ALL, PRESERVE_DIRECT, PRESERVE_SEMVER, PRESERVE_NONE

Expand Down Expand Up @@ -99,6 +99,7 @@ An enum with the instances
* `UPLEVEL_PATCH`
* `UPLEVEL_MINOR`
* `UPLEVEL_MAJOR`
* `UPLEVEL_DOWN`

Determines how much a package is allowed to be updated.
Used as an argument to [`PackageSpec`](@ref) or as an argument to [`Pkg.update`](@ref).
Expand Down
6 changes: 3 additions & 3 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FileWatching
import Base: SHA1
using SHA

export UUID, SHA1, VersionRange, VersionSpec,
export UUID, SHA1, VersionRange, VersionSpec, Compat,
PackageSpec, PackageEntry, EnvCache, Context, GitRepo, Context!, Manifest, Project, err_rep,
PkgError, pkgerror, PkgPrecompileError,
has_name, has_uuid, is_stdlib, is_or_was_stdlib, stdlib_version, is_unregistered_stdlib, stdlibs, write_env, write_env_usage, parse_toml,
Expand All @@ -27,7 +27,7 @@ export UUID, SHA1, VersionRange, VersionSpec,
manifest_info,
read_project, read_package, read_manifest,
PackageMode, PKGMODE_MANIFEST, PKGMODE_PROJECT, PKGMODE_COMBINED,
UpgradeLevel, UPLEVEL_FIXED, UPLEVEL_PATCH, UPLEVEL_MINOR, UPLEVEL_MAJOR,
UpgradeLevel, UPLEVEL_FIXED, UPLEVEL_PATCH, UPLEVEL_MINOR, UPLEVEL_MAJOR, UPLEVEL_DOWN,
PreserveLevel, PRESERVE_ALL_INSTALLED, PRESERVE_ALL, PRESERVE_DIRECT, PRESERVE_SEMVER, PRESERVE_TIERED,
PRESERVE_TIERED_INSTALLED, PRESERVE_NONE,
projectfile_path, manifestfile_path
Expand Down Expand Up @@ -82,7 +82,7 @@ Base.show(io::IO, err::PkgPrecompileError) = print(io, "PkgPrecompileError: ", e
###############
# PackageSpec #
###############
@enum(UpgradeLevel, UPLEVEL_FIXED, UPLEVEL_PATCH, UPLEVEL_MINOR, UPLEVEL_MAJOR)
@enum(UpgradeLevel, UPLEVEL_FIXED, UPLEVEL_PATCH, UPLEVEL_MINOR, UPLEVEL_MAJOR, UPLEVEL_DOWN)
@enum(PreserveLevel, PRESERVE_ALL_INSTALLED, PRESERVE_ALL, PRESERVE_DIRECT, PRESERVE_SEMVER, PRESERVE_TIERED, PRESERVE_TIERED_INSTALLED, PRESERVE_NONE)
@enum(PackageMode, PKGMODE_PROJECT, PKGMODE_MANIFEST, PKGMODE_COMBINED)

Expand Down
Loading