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

Add example of manually checking specifications #3847

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Sponsor Member

@MilesCranmer MilesCranmer commented Mar 17, 2024

The Compatibility guide is very helpful, but I still find the exact syntax easy to forget, and find myself repeatedly checking this guide whenever I'm creating a complex version specification.

I recently found the Pkg.Versions.semver_spec as a way to manually parse the version string. I have found this useful for my own work and I thought it would be helpful to give an example of how to use this to explicitly check versions, and make sure you aren't too constrained or too flexible in a given version spec.

I add the following subsection to the docs:


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
range by using this command. For example:

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

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"

@KristofferC
Copy link
Sponsor Member

KristofferC commented Mar 17, 2024

I think this is a good idea and we should imo also:

  • Give it a docstring.
  • Make it public.
  • Give it a better name.

@MilesCranmer
Copy link
Sponsor Member Author

That all sounds good to me.

For naming, maybe just something like parse_compat?

@DilumAluthge
Copy link
Member

Does this mean that we have to make Pkg.Versions.VersionSpec part of the public API? Because semver_spec returns a VersionSpec?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants