From a7a44d18945d1f18687da79ce98acd5d5fac0e21 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Mon, 18 Mar 2024 01:12:16 +0900 Subject: [PATCH 1/2] Add example of checking specification --- docs/src/compatibility.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/src/compatibility.md b/docs/src/compatibility.md index 5ca811aef9..4b411c6dc4 100644 --- a/docs/src/compatibility.md +++ b/docs/src/compatibility.md @@ -163,6 +163,28 @@ PkgA = "0.2 - 0.5" # 0.2.0 - 0.5.* = [0.2.0, 0.6.0) PkgA = "0.2 - 0" # 0.2.0 - 0.*.* = [0.2.0, 1.0.0) ``` +### Checking specification + +Pkg.jl parses a given version specification using `Pkg.Versions.semver_spec`. +You can check if a particular version of a package is contained in a particular +range by using this command. For example: + +```julia +julia> v"0.1.0" in Pkg.Versions.semver_spec("=0.1") +true + +julia> v"0.1.0" in Pkg.Versions.semver_spec("=0.1.1") +false + +julia> v"0.1.0" in Pkg.Versions.semver_spec("0.1 - 0.2") +true + +julia> v"0.3.0" in Pkg.Versions.semver_spec("~0.3.2") +false + +julia> v"0.3.3" in Pkg.Versions.semver_spec("0.1 - 0.2, ~0.3.2") +true +``` ## Fixing conflicts From fdf6bb128fbe14221374b1dd57ee31c405ed8944 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Sun, 17 Mar 2024 16:24:25 +0000 Subject: [PATCH 2/2] Add example with range of versions --- docs/src/compatibility.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/src/compatibility.md b/docs/src/compatibility.md index 4b411c6dc4..df4d5bbc99 100644 --- a/docs/src/compatibility.md +++ b/docs/src/compatibility.md @@ -163,7 +163,7 @@ PkgA = "0.2 - 0.5" # 0.2.0 - 0.5.* = [0.2.0, 0.6.0) PkgA = "0.2 - 0" # 0.2.0 - 0.*.* = [0.2.0, 1.0.0) ``` -### Checking specification +### Checking specifications Pkg.jl parses a given version specification using `Pkg.Versions.semver_spec`. You can check if a particular version of a package is contained in a particular @@ -184,6 +184,19 @@ false julia> v"0.3.3" in Pkg.Versions.semver_spec("0.1 - 0.2, ~0.3.2") true + +julia> # Grid of versions: + versions = [[VersionNumber(major, minor, patch) for patch=0:8, minor=0:3, major=0:1]...]; + +julia> filter(v -> v in Pkg.Versions.semver_spec("0.1.8 - 0.2.2, ^0.3.6"), versions) +7-element Vector{VersionNumber}: + v"0.1.8" + v"0.2.0" + v"0.2.1" + v"0.2.2" + v"0.3.6" + v"0.3.7" + v"0.3.8" ``` ## Fixing conflicts