From 24eae8b454767837f365e225f3a09312346f6582 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:58:28 +0200 Subject: [PATCH] support RegistryInstance in `get_all_non_jll_package_names` (#568) * support compressed registry in `get_all_non_jll_package_names` * up * switch approach, don't add dep * fix projects * update docstring * up * don't unpack on docs build * try to fix docs * use pkgserver --- .github/workflows/ci_unit.yml | 7 +++++-- Project.toml | 2 +- docs/Project.toml | 2 ++ docs/src/guidelines.md | 16 +++++++++------- src/AutoMerge/util.jl | 29 ++++++++++++++++++++++------- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci_unit.yml b/.github/workflows/ci_unit.yml index 4f8e3977..ce4d0082 100644 --- a/.github/workflows/ci_unit.yml +++ b/.github/workflows/ci_unit.yml @@ -49,6 +49,8 @@ jobs: env: AUTOMERGE_RUN_INTEGRATION_TESTS: "false" documentation: + env: + JULIA_PKG_UNPACK_REGISTRY: 'false' name: Documentation runs-on: ubuntu-latest steps: @@ -59,10 +61,11 @@ jobs: - run: | julia --project=docs -e ' using Pkg + # install compressed registry + Pkg.Registry.rm("General") + Pkg.Registry.add("General") Pkg.develop(PackageSpec(path=pwd())) Pkg.instantiate()' - env: - JULIA_PKG_SERVER: '' - run: julia --project=docs docs/make.jl env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Project.toml b/Project.toml index aabaf7c0..c751b06d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RegistryCI" uuid = "0c95cc5f-2f7e-43fe-82dd-79dbcba86b32" authors = ["Dilum Aluthge ", "Fredrik Ekre ", "contributors"] -version = "10.5.0" +version = "10.6.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/docs/Project.toml b/docs/Project.toml index 993c115d..67897188 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,6 +1,8 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" RegistryCI = "0c95cc5f-2f7e-43fe-82dd-79dbcba86b32" +RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3" [compat] Documenter = "1" +RegistryInstances = "0.1" diff --git a/docs/src/guidelines.md b/docs/src/guidelines.md index 64086a79..a97dc3ec 100644 --- a/docs/src/guidelines.md +++ b/docs/src/guidelines.md @@ -109,17 +109,19 @@ To test yourself that a tentative package name, say `MyPackage` meets these checks, you can use the following code (after adding the RegistryCI package to your Julia environment): -```julia -using RegistryCI +```@example +using RegistryCI, RegistryInstances using RegistryCI.AutoMerge -all_pkg_names = AutoMerge.get_all_non_jll_package_names(path_to_registry) -AutoMerge.meets_distance_check("MyPackage", all_pkg_names) +path_to_registry = joinpath(DEPOT_PATH[1], "registries", "General.toml") +all_pkg_names = AutoMerge.get_all_non_jll_package_names(RegistryInstance(path_to_registry)) +AutoMerge.meets_distance_check("MyPackage123", all_pkg_names) ``` -where `path_to_registry` is a path to the folder containing the registry of +where `path_to_registry` is a path to the registry of interest. For the General Julia registry, usually `path_to_registry = -joinpath(DEPOT_PATH[1], "registries", "General")` if you haven't changed -your `DEPOT_PATH` and have an extracted version of the Pkg server registry (see JuliaRegistries/RegistryCI.jl#442). This will return a boolean, indicating whether or not +joinpath(DEPOT_PATH[1], "registries", "General.toml")` if you haven't changed +your `DEPOT_PATH` (or `path_to_registry = +joinpath(DEPOT_PATH[1], "registries", "General")` if you have an uncompressed registry at the directory there). This will return a boolean, indicating whether or not your tentative package name passed the check, as well as a string, indicating what the problem is in the event the check did not pass. diff --git a/src/AutoMerge/util.jl b/src/AutoMerge/util.jl index 80a98e34..c0f5a522 100644 --- a/src/AutoMerge/util.jl +++ b/src/AutoMerge/util.jl @@ -288,17 +288,32 @@ end """ get_all_non_jll_package_names(registry_dir::AbstractString) -> Vector{String} + get_all_non_jll_package_names(registry::RegistryInstance) -> Vector{String} -Given a path to the directory holding a registry, returns the names of all the non-JLL packages -defined in that registry, along with the names of Julia's standard libraries. +Given either: + +- a path to a directory holding an uncompressed registry + +or + +- a `RegistryInstance` object (from [RegistryInstances.jl](https://github.com/GunnarFarneback/RegistryInstances.jl)) associated to a registry, + +returns a sorted list of the names of Julia's standard libraries +and all the non-JLL packages defined in that registry. """ function get_all_non_jll_package_names(registry_dir::AbstractString) - packages = [ - x["name"] for - x in values(TOML.parsefile(joinpath(registry_dir, "Registry.toml"))["packages"]) - ] - sort!(packages) + # Mimic the structure of a RegistryInstance + list = TOML.parsefile(joinpath(registry_dir, "Registry.toml"))["packages"] + registry = (; pkgs=Dict(k => (; name=v["name"]) for (k,v) in pairs(list))) + return get_all_non_jll_package_names(registry) +end + +# Generic method intended for RegistryInstance (without taking on the dependency, +# which is only valid on Julia 1.7+) +function get_all_non_jll_package_names(registry) + packages = [entry.name for entry in values(registry.pkgs)] append!(packages, (RegistryTools.get_stdlib_name(x) for x in values(RegistryTools.stdlibs()))) + sort!(packages) filter!(x -> !endswith(x, "_jll"), packages) unique!(packages) return packages