From 2dcbe44479b53b32ab0683e4177a37f19c70f20c Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 16 Jul 2025 22:27:14 +0200 Subject: [PATCH 1/2] add ExplicitImports pre-commit code check --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 68066c2cc2..7e9c7c38e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,30 @@ repos: - id: runic additional_dependencies: - 'Runic@1.4' # Keep version in sync with .github/workflows/Check.yml + + explicit-imports: + runs-on: ubuntu-latest + name: "ExplicitImports.jl" + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 'nightly' + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - name: Install dependencies + shell: julia {0} + run: | + # Add ExplicitImports.jl + using Pkg + Pkg.add([ + PackageSpec(name = "ExplicitImports", version = "1.12"), + ]) + - name: ExplicitImports.jl code checks + shell: julia --project {0} + run: | + using Pkg, ExplicitImports + check_no_implicit_imports(Pkg) + # check_no_stale_explicit_imports(Pkg) # artifact_names in PkgArtifacts + check_all_qualified_accesses_via_owners(Pkg) + check_no_self_qualified_accesses(Pkg) From 2d51a8819246ee88c00dc179d001974cad254ded Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 29 Jul 2025 12:13:57 +0200 Subject: [PATCH 2/2] fixups for ExplicitImports.jl --- .github/workflows/check.yml | 27 +++++++++++++++++++++++++++ .pre-commit-config.yaml | 27 --------------------------- ext/REPLExt/REPLExt.jl | 3 ++- ext/REPLExt/precompile.jl | 8 ++++---- src/API.jl | 27 +++++++++++++-------------- src/Apps/Apps.jl | 17 +++++++++-------- src/Artifacts.jl | 17 +++++++++-------- src/BinaryPlatformsCompat.jl | 16 ++++++++-------- src/GitTools.jl | 11 +++++------ src/MiniProgressBars.jl | 2 +- src/Operations.jl | 35 +++++++++++++++++++---------------- src/Pkg.jl | 15 +++++++-------- src/PlatformEngines.jl | 9 +++++++-- src/REPLMode/REPLMode.jl | 4 +++- src/Registry/Registry.jl | 35 ++++++++++++++++++++--------------- src/Resolve/Resolve.jl | 6 +++--- src/Types.jl | 26 ++++++++++++-------------- src/precompile.jl | 14 +++++++++++--- src/utils.jl | 2 +- test/artifacts.jl | 2 +- test/new.jl | 18 +++++++++--------- test/pkg.jl | 6 +++--- test/repl.jl | 2 +- 23 files changed, 175 insertions(+), 154 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 8376d060fb..46af34afcf 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -28,3 +28,30 @@ jobs: - uses: fredrikekre/runic-action@v1 with: version: "1.4" # Keep version in sync with .pre-commit-config.yaml + + explicit-imports: + runs-on: ubuntu-latest + name: "ExplicitImports.jl" + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 'nightly' + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - name: Install dependencies + shell: julia {0} + run: | + # Add ExplicitImports.jl + using Pkg + Pkg.add([ + PackageSpec(name = "ExplicitImports", version = "1.12"), + ]) + - name: ExplicitImports.jl code checks + shell: julia --project {0} + run: | + using Pkg, ExplicitImports + # check_no_implicit_imports(Pkg) # `Pkg.Registry`: `@dateformat_str` bug in ExplicitImports? + # check_no_stale_explicit_imports(Pkg) # artifact_names in PkgArtifacts + check_all_qualified_accesses_via_owners(Pkg) + check_no_self_qualified_accesses(Pkg) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e9c7c38e9..68066c2cc2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,30 +15,3 @@ repos: - id: runic additional_dependencies: - 'Runic@1.4' # Keep version in sync with .github/workflows/Check.yml - - explicit-imports: - runs-on: ubuntu-latest - name: "ExplicitImports.jl" - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: 'nightly' - - uses: julia-actions/cache@v2 - - uses: julia-actions/julia-buildpkg@v1 - - name: Install dependencies - shell: julia {0} - run: | - # Add ExplicitImports.jl - using Pkg - Pkg.add([ - PackageSpec(name = "ExplicitImports", version = "1.12"), - ]) - - name: ExplicitImports.jl code checks - shell: julia --project {0} - run: | - using Pkg, ExplicitImports - check_no_implicit_imports(Pkg) - # check_no_stale_explicit_imports(Pkg) # artifact_names in PkgArtifacts - check_all_qualified_accesses_via_owners(Pkg) - check_no_self_qualified_accesses(Pkg) diff --git a/ext/REPLExt/REPLExt.jl b/ext/REPLExt/REPLExt.jl index 31bbf66970..f27d424a8c 100644 --- a/ext/REPLExt/REPLExt.jl +++ b/ext/REPLExt/REPLExt.jl @@ -4,7 +4,8 @@ if Base.get_bool_env("JULIA_PKG_DISALLOW_PKG_PRECOMPILATION", false) == true error("Precompililing Pkg extension REPLExt is disallowed. JULIA_PKG_DISALLOW_PKG_PRECOMPILATION=$(ENV["JULIA_PKG_DISALLOW_PKG_PRECOMPILATION"])") end -using Markdown, UUIDs, Dates +import Dates +using UUIDs: UUID import REPL import .REPL: LineEdit, REPLCompletions, TerminalMenus diff --git a/ext/REPLExt/precompile.jl b/ext/REPLExt/precompile.jl index fbfdf14baf..85fea417f5 100644 --- a/ext/REPLExt/precompile.jl +++ b/ext/REPLExt/precompile.jl @@ -16,7 +16,7 @@ let Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true Pkg.DEFAULT_IO[] = Pkg.unstableio(devnull) withenv("JULIA_PKG_SERVER" => nothing, "JULIA_PKG_UNPACK_REGISTRY" => nothing) do - tmp = Pkg._run_precompilation_script_setup() + tmp = Pkg.PrecompileHelper._run_precompilation_script_setup() cd(tmp) do try_prompt_pkg_add(Symbol[:notapackage]) promptf() @@ -29,10 +29,10 @@ let copy!(DEPOT_PATH, original_depot_path) copy!(LOAD_PATH, original_load_path) - Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState}) + Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), PkgCompletionProvider, REPL.LineEdit.PromptState}) Base.precompile(Tuple{typeof(REPL.REPLCompletions.completion_text), REPL.REPLCompletions.PackageCompletion}) - Base.precompile(Tuple{typeof(REPLExt.on_done), REPL.LineEdit.MIState, Base.GenericIOBuffer{Memory{UInt8}}, Bool, REPL.LineEditREPL}) - return Base.precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:hint,), Tuple{Bool}}, typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState}) + Base.precompile(Tuple{typeof(on_done), REPL.LineEdit.MIState, Base.GenericIOBuffer{Memory{UInt8}}, Bool, REPL.LineEditREPL}) + return Base.precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:hint,), Tuple{Bool}}, typeof(REPL.LineEdit.complete_line), PkgCompletionProvider, REPL.LineEdit.PromptState}) end if Base.generating_output() diff --git a/src/API.jl b/src/API.jl index f1abc6cb6b..35689e1ac5 100644 --- a/src/API.jl +++ b/src/API.jl @@ -2,26 +2,25 @@ module API -using UUIDs -using Printf -import Random -using Dates +import FileWatching import LibGit2 import Logging -import FileWatching +import Printf +import Random +using Dates: Dates, DateTime, Day, Period, now +using UUIDs: UUIDs, UUID -import Base: StaleCacheKey +using Base.BinaryPlatforms -import ..depots, ..depots1, ..logdir, ..devdir, ..printpkgstyle, .._autoprecompilation_enabled_scoped import ..Operations, ..GitTools, ..Pkg, ..Registry +import ..TOML +import ..depots1, ..logdir, ..devdir, ..printpkgstyle, .._autoprecompilation_enabled_scoped import ..can_fancyprint, ..pathrepr, ..isurl, ..PREV_ENV_PATH, ..atomic_toml_write -using ..Types, ..TOML -using ..Types: VersionTypes -using Base.BinaryPlatforms import ..stderr_f, ..stdout_f +import ..Resolve: ResolverError, ResolverTimeoutError +using ..Types using ..Artifacts: artifact_paths using ..MiniProgressBars -import ..Resolve: ResolverError, ResolverTimeoutError include("generate.jl") @@ -583,7 +582,7 @@ function gc(ctx::Context = Context(); collect_delay::Period = Day(7), verbose = env = ctx.env # Only look at user-depot unless force=true - gc_depots = force ? depots() : [depots1()] + gc_depots = force ? Base.DEPOT_PATH : [depots1()] # First, we load in our `manifest_usage.toml` files which will tell us when our # "index files" (`Manifest.toml`, `Artifacts.toml`) were last used. We will combine @@ -1435,10 +1434,10 @@ function activate(path::AbstractString; shared::Bool = false, temp::Bool = false end end else - # initialize `fullpath` in case of empty `Pkg.depots()` + # initialize `fullpath` in case of empty `Pkg.Base.DEPOT_PATH` fullpath = "" # loop over all depots to check if the shared environment already exists - for depot in Pkg.depots() + for depot in Pkg.Base.DEPOT_PATH fullpath = joinpath(Pkg.envdir(depot), path) isdir(fullpath) && break end diff --git a/src/Apps/Apps.jl b/src/Apps/Apps.jl index e5cfd8b10f..2292f472fe 100644 --- a/src/Apps/Apps.jl +++ b/src/Apps/Apps.jl @@ -1,14 +1,15 @@ module Apps -using Pkg -using Pkg: atomic_toml_write -using Pkg.Versions -using Pkg.Types: AppInfo, PackageSpec, Context, EnvCache, PackageEntry, Manifest, handle_repo_add!, handle_repo_develop!, write_manifest, write_project, +import ..Pkg +using ..Pkg: atomic_toml_write +using ..Pkg.Versions +using ..Pkg.Types: AppInfo, PackageSpec, Context, EnvCache, PackageEntry, Manifest, handle_repo_add!, handle_repo_develop!, write_manifest, pkgerror, projectfile_path, manifestfile_path -using Pkg.Operations: print_single, source_path, update_package_add -using Pkg.API: handle_package_input! -using TOML, UUIDs -import Pkg.Registry +using ..Pkg.Operations: print_single, source_path, update_package_add +using ..Pkg.API: handle_package_input! +import TOML +using UUIDs: UUID +import ..Registry app_env_folder() = joinpath(first(DEPOT_PATH), "environments", "apps") app_manifest_file() = joinpath(app_env_folder(), "AppManifest.toml") diff --git a/src/Artifacts.jl b/src/Artifacts.jl index d6f2c948f4..01d438421b 100644 --- a/src/Artifacts.jl +++ b/src/Artifacts.jl @@ -1,18 +1,19 @@ module PkgArtifacts - using Artifacts, Base.BinaryPlatforms, SHA - using ..MiniProgressBars, ..PlatformEngines + import FileWatching + using Artifacts: @artifact_str, artifact_exists, artifact_hash, artifact_meta, artifact_path, find_artifacts_toml, select_downloadable_artifacts, with_artifacts_directory + using SHA: SHA, SHA256_CTX, sha256 using Tar: can_symlink - using FileWatching: FileWatching - import ..set_readonly, ..GitTools, ..TOML, ..pkg_server, ..can_fancyprint, - ..stderr_f, ..printpkgstyle, ..mv_temp_dir_retries, ..atomic_toml_write + using Base.BinaryPlatforms + import Artifacts: artifact_names, artifact_paths, artifacts_dirs, pack_platform!, unpack_platform, load_artifacts_toml, query_override import Base: get, SHA1 - import Artifacts: artifact_names, ARTIFACTS_DIR_OVERRIDE, ARTIFACT_OVERRIDES, artifact_paths, - artifacts_dirs, pack_platform!, unpack_platform, load_artifacts_toml, - query_override, with_artifacts_directory, load_overrides + + import ..set_readonly, ..GitTools, ..TOML, ..pkg_server, ..can_fancyprint, + ..stderr_f, ..printpkgstyle, ..mv_temp_dir_retries, ..atomic_toml_write import ..Types: write_env_usage, parse_toml + using ..MiniProgressBars, ..PlatformEngines const Artifacts = PkgArtifacts # This is to preserve compatability for folks who depend on the internals of this module export Artifacts, create_artifact, artifact_exists, artifact_path, remove_artifact, verify_artifact, diff --git a/src/BinaryPlatformsCompat.jl b/src/BinaryPlatformsCompat.jl index 93403e05bd..150d862cb9 100644 --- a/src/BinaryPlatformsCompat.jl +++ b/src/BinaryPlatformsCompat.jl @@ -87,16 +87,16 @@ module BinaryPlatformsCompat end # Next, things we don't need to coerce - for f in (:libgfortran_version, :libstdcxx_version, :platform_name, :wordsize, :platform_dlext, :tags, :triplet) - @eval begin - $(f)(p::PlatformUnion) = $(f)(p.p) - end - end + libgfortran_version(p::PlatformUnion) = libgfortran_version(p.p) + libstdcxx_version(p::PlatformUnion) = libstdcxx_version(p.p) + platform_name(p::PlatformUnion) = platform_name(p.p) + wordsize(p::PlatformUnion) = wordsize(p.p) + platform_dlext(p::PlatformUnion) = platform_dlext(p.p) + tags(p::PlatformUnion) = tags(p.p) + triplet(p::PlatformUnion) = triplet(p.p) # Finally, add equality testing between these wrapper types and other AbstractPlatforms - @eval begin - Base.:(==)(a::PlatformUnion, b::AbstractPlatform) = b == a.p - end + Base.:(==)(a::PlatformUnion, b::AbstractPlatform) = b == a.p # Add one-off functions MacOS(; kwargs...) = MacOS(:x86_64; kwargs...) diff --git a/src/GitTools.jl b/src/GitTools.jl index ddce9aac46..0f3b98b65f 100644 --- a/src/GitTools.jl +++ b/src/GitTools.jl @@ -2,13 +2,12 @@ module GitTools +import LibGit2 +using SHA: SHA, SHA1_CTX, update! + +import ..can_fancyprint, ..printpkgstyle, ..stdout_f using ..Pkg using ..MiniProgressBars -import ..can_fancyprint, ..printpkgstyle, ..stdout_f -using SHA -import Base: SHA1 -import LibGit2 -using Printf use_cli_git() = Base.get_bool_env("JULIA_PKG_USE_CLI_GIT", false) const RESOLVING_DELTAS_HEADER = "Resolving Deltas:" @@ -75,7 +74,7 @@ function ensure_clone(io::IO, target_path, url; kwargs...) if ispath(target_path) return LibGit2.GitRepo(target_path) else - return GitTools.clone(io, url, target_path; kwargs...) + return clone(io, url, target_path; kwargs...) end end diff --git a/src/MiniProgressBars.jl b/src/MiniProgressBars.jl index 5682fc04a4..db555a56d3 100644 --- a/src/MiniProgressBars.jl +++ b/src/MiniProgressBars.jl @@ -2,7 +2,7 @@ module MiniProgressBars export MiniProgressBar, start_progress, end_progress, show_progress, print_progress_bottom -using Printf +using Printf: @sprintf # Until Base.format_bytes supports sigdigits function pkg_format_bytes(bytes; binary = true, sigdigits::Integer = 3) diff --git a/src/Operations.jl b/src/Operations.jl index a1fa3fdd99..52c3636400 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -2,20 +2,23 @@ module Operations -using FileWatching: FileWatching -using UUIDs +import Dates +import FileWatching +import LibGit2 +import TOML using Random: randstring -import LibGit2, Dates, TOML +using UUIDs: UUID -using ..Types, ..Resolve, ..PlatformEngines, ..GitTools, ..MiniProgressBars -import ..depots, ..depots1, ..devdir, ..set_readonly, ..Types.PackageEntry -import ..Artifacts: ensure_artifact_installed, artifact_names, extract_all_hashes, - artifact_exists, select_downloadable_artifacts, mv_temp_dir_retries using Base.BinaryPlatforms + import ...Pkg -import ...Pkg: pkg_server, Registry, pathrepr, can_fancyprint, printpkgstyle, stderr_f, OFFLINE_MODE +import ...Pkg: Registry, pathrepr, can_fancyprint, printpkgstyle, stderr_f, OFFLINE_MODE import ...Pkg: UPDATED_REGISTRY_THIS_SESSION, RESPECT_SYSIMAGE_VERSIONS, should_autoprecompile import ...Pkg: usable_io, discover_repo +import ..depots1, ..devdir, ..set_readonly, ..Types.PackageEntry +import ..Artifacts: ensure_artifact_installed, artifact_names, + artifact_exists, select_downloadable_artifacts, mv_temp_dir_retries +using ..Types, ..Resolve, ..PlatformEngines, ..GitTools, ..MiniProgressBars ######### # Utils # @@ -61,7 +64,7 @@ function find_installed(name::String, uuid::UUID, sha1::SHA1) slug_default = Base.version_slug(uuid, sha1) # 4 used to be the default so look there first for slug in (slug_default, Base.version_slug(uuid, sha1, 4)) - for depot in depots() + for depot in Base.DEPOT_PATH path = abspath(depot, "packages", name, slug) ispath(path) && return path end @@ -222,9 +225,9 @@ end function is_instantiated(env::EnvCache, workspace::Bool = false; platform = HostPlatform())::Bool # Load everything if workspace - pkgs = Operations.load_all_deps(env) + pkgs = load_all_deps(env) else - pkgs = Operations.load_all_deps_loadable(env) + pkgs = load_all_deps_loadable(env) end # If the top-level project is a package, ensure it is instantiated as well if env.pkg !== nothing @@ -913,8 +916,8 @@ function install_git( GitTools.checkout_tree_to_path(repo, tree, version_path) return finally - repo !== nothing && LibGit2.close(repo) - tree !== nothing && LibGit2.close(tree) + repo !== nothing && close(repo) + tree !== nothing && close(tree) end end @@ -2704,8 +2707,8 @@ function stat_rep(x::PackageSpec; name = true) rev = occursin(r"\b([a-f0-9]{40})\b", x.repo.rev) ? x.repo.rev[1:7] : x.repo.rev end subdir_str = x.repo.subdir === nothing ? "" : ":$(x.repo.subdir)" - repo = Operations.is_tracking_repo(x) ? "`$(x.repo.source)$(subdir_str)#$(rev)`" : "" - path = Operations.is_tracking_path(x) ? "$(pathrepr(x.path))" : "" + repo = is_tracking_repo(x) ? "`$(x.repo.source)$(subdir_str)#$(rev)`" : "" + path = is_tracking_path(x) ? "$(pathrepr(x.path))" : "" pinned = x.pinned ? "⚲" : "" return join(filter(!isempty, [name, version, repo, path, pinned]), " ") end @@ -2989,7 +2992,7 @@ function print_status( pkg_downloaded = !is_instantiated(new) || is_package_downloaded(env.manifest_file, new) - new_ver_avail = !latest_version && !Operations.is_tracking_repo(new) && !Operations.is_tracking_path(new) + new_ver_avail = !latest_version && !is_tracking_repo(new) && !is_tracking_path(new) pkg_upgradable = new_ver_avail && cinfo !== nothing && isempty(cinfo[1]) pkg_heldback = new_ver_avail && cinfo !== nothing && !isempty(cinfo[1]) diff --git a/src/Pkg.jl b/src/Pkg.jl index d0cdbe760b..96dd1ca969 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -13,7 +13,7 @@ end import Random import TOML -using Dates +using Dates: Dates, Day, Period, Second export @pkg_str export PackageSpec @@ -25,13 +25,12 @@ export Registry, RegistrySpec public activate, add, build, compat, develop, free, gc, generate, instantiate, pin, precompile, redo, rm, resolve, status, test, undo, update, why -depots() = Base.DEPOT_PATH -function depots1(depot_list::Union{String, Vector{String}} = depots()) +function depots1(depot_list::Union{String, Vector{String}} = Base.DEPOT_PATH) # Get the first depot from a list, with proper error handling if depot_list isa String return depot_list else - isempty(depot_list) && Pkg.Types.pkgerror("no depots provided") + isempty(depot_list) && Types.pkgerror("no depots provided") return depot_list[1] end end @@ -109,7 +108,7 @@ include("Apps/Apps.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 import .Types: PKGMODE_MANIFEST, PKGMODE_PROJECT import .Types: PRESERVE_TIERED_INSTALLED, PRESERVE_TIERED, PRESERVE_ALL_INSTALLED, PRESERVE_ALL, PRESERVE_DIRECT, PRESERVE_SEMVER, PRESERVE_NONE @@ -957,7 +956,7 @@ function _auto_gc(ctx::Types.Context; collect_delay::Period = Day(7)) return if curr_time - DEPOT_ORPHANAGE_TIMESTAMPS[depots1()] > delay_secs printpkgstyle(ctx.io, :Info, "We haven't cleaned this depot up for a bit, running Pkg.gc()...", color = Base.info_color()) try - Pkg.gc(ctx; collect_delay) + gc(ctx; collect_delay) DEPOT_ORPHANAGE_TIMESTAMPS[depots1()] = curr_time catch ex @error("GC failed", exception = ex) @@ -972,7 +971,7 @@ end function _auto_precompile(ctx::Types.Context, pkgs::Vector{PackageSpec} = PackageSpec[]; warn_loaded = true, already_instantiated = false) return if should_autoprecompile() - Pkg.precompile(ctx, pkgs; internal_call = true, warn_loaded = warn_loaded, already_instantiated = already_instantiated) + precompile(ctx, pkgs; internal_call = true, warn_loaded = warn_loaded, already_instantiated = already_instantiated) end end @@ -980,7 +979,7 @@ include("precompile.jl") # Reset globals that might have been mutated during precompilation. DEFAULT_IO[] = nothing -Pkg.UPDATED_REGISTRY_THIS_SESSION[] = false +UPDATED_REGISTRY_THIS_SESSION[] = false PREV_ENV_PATH[] = "" Types.STDLIB[] = nothing diff --git a/src/PlatformEngines.jl b/src/PlatformEngines.jl index 22967bdf1a..518821bf9f 100644 --- a/src/PlatformEngines.jl +++ b/src/PlatformEngines.jl @@ -4,10 +4,15 @@ module PlatformEngines -using SHA, Downloads, Tar +import Downloads +import Tar +import p7zip_jll +using SHA: SHA, sha256 + +using Base.BinaryPlatforms + import ...Pkg: Pkg, TOML, pkg_server, depots1, can_fancyprint, stderr_f, atomic_toml_write using ..MiniProgressBars -using Base.BinaryPlatforms, p7zip_jll export verify, unpack, package, download_verify_unpack diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 77e25f7bef..edfa11cd14 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -4,7 +4,9 @@ module REPLMode @eval Base.Experimental.@compiler_options optimize = 1 -using Markdown, UUIDs, Dates +using Markdown: Markdown, @md_str +using UUIDs: UUID +using Dates: Hour import ..OFFLINE_MODE, ..linewrap, ..pathrepr, ..IN_REPL_MODE using ..Types, ..Operations, ..API, ..Registry, ..Resolve, ..Apps diff --git a/src/Registry/Registry.jl b/src/Registry/Registry.jl index b9319d5347..fcd7648f4c 100644 --- a/src/Registry/Registry.jl +++ b/src/Registry/Registry.jl @@ -1,11 +1,16 @@ module Registry +import FileWatching +import LibGit2 +import TOML +import Tar +import UUIDs +using Dates: @dateformat_str, Dates, DateTime, Millisecond, Second, now + import ..Pkg -using ..Pkg: depots, depots1, printpkgstyle, stderr_f, isdir_nothrow, pathrepr, pkg_server, +using ..Pkg: depots1, printpkgstyle, stderr_f, pathrepr, pkg_server, GitTools, atomic_toml_write using ..Pkg.PlatformEngines: download_verify_unpack, download, download_verify, exe7z, verify_archive_tree_hash -using UUIDs, LibGit2, TOML, Dates -import FileWatching public add, rm, status, update @@ -50,9 +55,9 @@ function add(; name = nothing, uuid = nothing, url = nothing, path = nothing, li add([RegistrySpec(; name, uuid, url, path, linked)]; kwargs...) end end -function add(regs::Vector{RegistrySpec}; io::IO = stderr_f(), depots::Union{String, Vector{String}} = depots()) +function add(regs::Vector{RegistrySpec}; io::IO = stderr_f(), depots::Union{String, Vector{String}} = Base.DEPOT_PATH) return if isempty(regs) - download_default_registries(io, only_if_empty = false; depots = depots) + download_default_registries(io, only_if_empty = false; depots) else download_registries(io, regs, depots) end @@ -130,7 +135,7 @@ function is_pkg_in_pkgserver_registry(pkg_uuid::Base.UUID, server_registry_info, return false end -function download_default_registries(io::IO; only_if_empty::Bool = true, depots::Union{String, Vector{String}} = depots()) +function download_default_registries(io::IO; only_if_empty::Bool = true, depots::Union{String, Vector{String}} = Base.DEPOT_PATH) # Check the specified depots for installed registries installed_registries = reachable_registries(; depots) # Only clone if there are no installed registries, unless called @@ -202,7 +207,7 @@ function check_registry_state(reg) return nothing end -function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{String, Vector{String}} = depots()) +function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{String, Vector{String}} = Base.DEPOT_PATH) # Use the first depot as the target target_depot = depots1(depots) populate_known_registries_with_urls!(regs) @@ -251,13 +256,13 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{S else mktempdir() do tmp if reg.path !== nothing && reg.linked == true # symlink to local source - registry = Registry.RegistryInstance(reg.path) + registry = RegistryInstance(reg.path) regpath = joinpath(regdir, registry.name) printpkgstyle(io, :Symlinking, "registry from `$(Base.contractuser(reg.path))`") isdir(dirname(regpath)) || mkpath(dirname(regpath)) symlink(reg.path, regpath) isfile(joinpath(regpath, "Registry.toml")) || Pkg.Types.pkgerror("no `Registry.toml` file in linked registry.") - registry = Registry.RegistryInstance(regpath) + registry = RegistryInstance(regpath) printpkgstyle(io, :Symlinked, "registry `$(Base.contractuser(registry.name))` to `$(Base.contractuser(regpath))`") registry_update_log[string(reg.uuid)] = now() save_registry_update_log(registry_update_log) @@ -282,7 +287,7 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{S elseif reg.path !== nothing # copy from local source printpkgstyle(io, :Copying, "registry from `$(Base.contractuser(reg.path))`") isfile(joinpath(reg.path, "Registry.toml")) || Pkg.Types.pkgerror("no `Registry.toml` file in source directory.") - registry = Registry.RegistryInstance(reg.path) + registry = RegistryInstance(reg.path) regpath = joinpath(regdir, registry.name) cp(reg.path, regpath; force = true) # has to be cp given we're copying printpkgstyle(io, :Copied, "registry `$(Base.contractuser(registry.name))` to `$(Base.contractuser(regpath))`") @@ -292,7 +297,7 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{S elseif reg.url !== nothing # clone from url # retry to help spurious connection issues, particularly on CI repo = retry(GitTools.clone, delays = fill(1.0, 5), check = (s, e) -> isa(e, LibGit2.GitError))(io, reg.url, tmp; header = "registry from $(repr(reg.url))") - LibGit2.close(repo) + close(repo) else Pkg.Types.pkgerror("no path or url specified for registry") end @@ -300,12 +305,12 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{S if !isfile(joinpath(tmp, "Registry.toml")) Pkg.Types.pkgerror("no `Registry.toml` file in cloned registry.") end - registry = Registry.RegistryInstance(tmp) + registry = RegistryInstance(tmp) regpath = joinpath(regdir, registry.name) # copy to `depot` ispath(dirname(regpath)) || mkpath(dirname(regpath)) if isfile(joinpath(regpath, "Registry.toml")) - existing_registry = Registry.RegistryInstance(regpath) + existing_registry = RegistryInstance(regpath) if registry.uuid == existing_registry.uuid println( io, @@ -369,11 +374,11 @@ end # Search for the input registries among installed ones function find_installed_registries( io::IO, - needles::Union{Vector{Registry.RegistryInstance}, Vector{RegistrySpec}}; + needles::Union{Vector{RegistryInstance}, Vector{RegistrySpec}}; depots = Base.DEPOT_PATH ) haystack = reachable_registries(; depots) - output = Registry.RegistryInstance[] + output = RegistryInstance[] for needle in needles if needle.name === nothing && needle.uuid === nothing Pkg.Types.pkgerror("no name or uuid specified for registry.") diff --git a/src/Resolve/Resolve.jl b/src/Resolve/Resolve.jl index 93d0f036bd..f75dea0eab 100644 --- a/src/Resolve/Resolve.jl +++ b/src/Resolve/Resolve.jl @@ -5,9 +5,9 @@ module Resolve using ..Versions import ..stdout_f, ..stderr_f -using Printf -using Random -using UUIDs +using Printf: @sprintf +using Random: Random, shuffle! +using UUIDs: UUID export resolve, sanity_check, Graph, pkgID diff --git a/src/Types.jl b/src/Types.jl index e14fa542a2..48fb909780 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -2,21 +2,19 @@ module Types -using UUIDs -using Random -using Dates +import FileWatching import LibGit2 +import TOML +using Dates: Dates, now +using SHA: SHA, sha1 +using UUIDs: UUID + +import Base: SHA1 import Base.string -using TOML import ..Pkg, ..Registry -import ..Pkg: GitTools, depots, depots1, logdir, set_readonly, safe_realpath, pkg_server, stdlib_dir, stdlib_path, isurl, stderr_f, RESPECT_SYSIMAGE_VERSIONS, atomic_toml_write -import Base.BinaryPlatforms: Platform +import ..Pkg: GitTools, depots1, logdir, set_readonly, safe_realpath, stdlib_dir, stdlib_path, isurl, stderr_f, RESPECT_SYSIMAGE_VERSIONS, atomic_toml_write using ..Pkg.Versions -import FileWatching - -import Base: SHA1 -using SHA export UUID, SHA1, VersionRange, VersionSpec, PackageSpec, PackageEntry, EnvCache, Context, GitRepo, Context!, Manifest, Project, err_rep, @@ -779,7 +777,7 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool) cloned = false package_path = pkg.repo.subdir === nothing ? repo_path : joinpath(repo_path, pkg.repo.subdir) if !has_name(pkg) - LibGit2.close(GitTools.ensure_clone(ctx.io, repo_path, pkg.repo.source)) + close(GitTools.ensure_clone(ctx.io, repo_path, pkg.repo.source)) cloned = true resolve_projectfile!(pkg, package_path) end @@ -802,7 +800,7 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool) else mkpath(dirname(dev_path)) if !cloned - LibGit2.close(GitTools.ensure_clone(ctx.io, dev_path, pkg.repo.source)) + close(GitTools.ensure_clone(ctx.io, dev_path, pkg.repo.source)) else mv(repo_path, dev_path) end @@ -1060,10 +1058,10 @@ end function project_resolve!(env::EnvCache, pkgs::AbstractVector{PackageSpec}) for pkg in pkgs - if has_uuid(pkg) && !has_name(pkg) && Types.is_project_uuid(env, pkg.uuid) + if has_uuid(pkg) && !has_name(pkg) && is_project_uuid(env, pkg.uuid) pkg.name = env.pkg.name end - if has_name(pkg) && !has_uuid(pkg) && Types.is_project_name(env, pkg.name) + if has_name(pkg) && !has_uuid(pkg) && is_project_name(env, pkg.name) pkg.uuid = env.pkg.uuid end end diff --git a/src/precompile.jl b/src/precompile.jl index c95eda5ab8..3772452298 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -1,6 +1,12 @@ -using LibGit2: LibGit2 -using Tar: Tar -using Downloads +module PrecompileHelper + +import Downloads +import LibGit2 +import Tar +import TOML +import Dates +using ..Pkg: Pkg, API, Types, Versions, REPLMode, Registry +using ..Pkg: unstableio, DEFAULT_IO, stdout_f, stderr_f # used by REPLExt too function _run_precompilation_script_setup() @@ -243,3 +249,5 @@ let end end end + +end # module PrecompileHelper diff --git a/src/utils.jl b/src/utils.jl index b4b9054ef2..ac9db9416c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -183,7 +183,7 @@ end function discover_repo(path::AbstractString) dir = abspath(path) stop_dir = homedir() - depot = Pkg.depots1() + depot = depots1() while true dir == depot && return nothing diff --git a/test/artifacts.jl b/test/artifacts.jl index 4c6e213eb7..90e8f3bd1c 100644 --- a/test/artifacts.jl +++ b/test/artifacts.jl @@ -2,7 +2,7 @@ module ArtifactTests import ..Pkg # ensure we are using the correct Pkg using Test, Random, Pkg.Artifacts, Base.BinaryPlatforms, Pkg.PlatformEngines -import Pkg.Artifacts: pack_platform!, unpack_platform, with_artifacts_directory, ensure_all_artifacts_installed, extract_all_hashes +using Pkg.Artifacts: extract_all_hashes, with_artifacts_directory using TOML, Dates import Base: SHA1 diff --git a/test/new.jl b/test/new.jl index de3587ff89..a2ef120a8c 100644 --- a/test/new.jl +++ b/test/new.jl @@ -985,7 +985,7 @@ end touch(joinpath(tempdir, "src", "Foo.jl")) ctx = Pkg.Types.Context() ctx.env.project.name = "Foo" - ctx.env.project.uuid = UUIDs.UUID(0) + ctx.env.project.uuid = UUID(0) Pkg.Types.write_project(ctx.env) Pkg.add(name = "Example", version = "0.3.0") @test Pkg.dependencies()[exuuid].version == v"0.3.0" @@ -2056,11 +2056,11 @@ end isolate(loaded_depot = true) do Pkg.add(name = "Example", version = "0.3.0") @test Pkg.dependencies()[exuuid].version == v"0.3.0" - Pkg.update(; level = Pkg.UPLEVEL_FIXED) + Pkg.update(; level = Pkg.Types.UPLEVEL_FIXED) @test Pkg.dependencies()[exuuid].version == v"0.3.0" - Pkg.update(; level = Pkg.UPLEVEL_PATCH) + Pkg.update(; level = Pkg.Types.UPLEVEL_PATCH) @test Pkg.dependencies()[exuuid].version == v"0.3.3" - Pkg.update(; level = Pkg.UPLEVEL_MINOR) + Pkg.update(; level = Pkg.Types.UPLEVEL_MINOR) @test Pkg.dependencies()[exuuid].version.minor != 3 end # `update` should prune manifest @@ -2158,11 +2158,11 @@ end new_commit = string(LibGit2.commit(repo, "bump version"; author = TEST_SIG, committer = TEST_SIG)) end # update with UPLEVEL != UPLEVEL_MAJOR should not update packages tracking repos - Pkg.update(; level = Pkg.UPLEVEL_MINOR) + Pkg.update(; level = Pkg.Types.UPLEVEL_MINOR) @test simple_package_node == Pkg.dependencies()[simple_package_uuid] - Pkg.update(; level = Pkg.UPLEVEL_PATCH) + Pkg.update(; level = Pkg.Types.UPLEVEL_PATCH) @test simple_package_node == Pkg.dependencies()[simple_package_uuid] - Pkg.update(; level = Pkg.UPLEVEL_FIXED) + Pkg.update(; level = Pkg.Types.UPLEVEL_FIXED) @test simple_package_node == Pkg.dependencies()[simple_package_uuid] # Update should not modify pinned packages which are tracking repos Pkg.pin("SimplePackage") @@ -2598,8 +2598,8 @@ end # rm nonexistent packages warns but does not error isolate(loaded_depot = true) do Pkg.add("Example") - @test_logs (:warn, r"not in project, ignoring") Pkg.rm(name = "FooBar", uuid = UUIDs.UUID(0)) - @test_logs (:warn, r"not in manifest, ignoring") Pkg.rm(name = "FooBar", uuid = UUIDs.UUID(0); mode = Pkg.PKGMODE_MANIFEST) + @test_logs (:warn, r"not in project, ignoring") Pkg.rm(name = "FooBar", uuid = UUID(0)) + @test_logs (:warn, r"not in manifest, ignoring") Pkg.rm(name = "FooBar", uuid = UUID(0); mode = Pkg.PKGMODE_MANIFEST) end end diff --git a/test/pkg.jl b/test/pkg.jl index 7ad0649e3c..d9c29f09fc 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -614,7 +614,7 @@ temp_pkg_dir() do project_path empty!(DEPOT_PATH) pushfirst!(DEPOT_PATH, depo1) Base.append_bundled_depot_path!(DEPOT_PATH) - LibGit2.close(LibGit2.clone(TEST_PKG.url, "Example.jl")) + close(LibGit2.clone(TEST_PKG.url, "Example.jl")) mkdir("machine1") cd("machine1") Pkg.activate(".") @@ -1067,7 +1067,7 @@ end @testset "Pkg.add" begin Pkg.activate(temp = true) mktempdir() do tmp_dir - LibGit2.close(LibGit2.clone(TEST_PKG.url, tmp_dir)) + close(LibGit2.clone(TEST_PKG.url, tmp_dir)) Pkg.develop(path = tmp_dir) Pkg.pin("Example") Pkg.add("Example") @@ -1098,7 +1098,7 @@ end tag = LibGit2.GitObject(repo, "v$ver") hash = string(LibGit2.target(tag)) LibGit2.checkout!(repo, hash) - LibGit2.close(repo) + close(repo) Pkg.develop(path = tmp_dir) Pkg.pin("Example") Pkg.update("Example") # pkg should remain pinned diff --git a/test/repl.jl b/test/repl.jl index 1bf65e1bfb..fcd164fc21 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -38,7 +38,7 @@ end temp_pkg_dir() do project_path with_pkg_env(project_path; change_dir = true) do; pkg"generate HelloWorld" - LibGit2.close((LibGit2.init("."))) + close((LibGit2.init("."))) cd("HelloWorld") @test_throws PkgError pkg"dev Example#blergh"