version

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-pep440-version

Test Go Report Card GitHub

A golang library for parsing PEP 440 compliant Python versions

go-pep440-version is a library for parsing versions of Python software distributions and version specifiers, and verifying versions against a set of specifiers.

Versions used with go-pep440-version must follow PEP 440.

For more details, see pypa/packaging

Usage

Version Parsing and Comparison

See example

v1, _ := version.Parse("1.2.a")
v2, _ := version.Parse("1.2")

// Comparison example. There is also GreaterThan, Equal, and just
// a simple Compare that returns an int allowing easy >=, <=, etc.
if v1.LessThan(v2) {
	fmt.Printf("%s is less than %s", v1, v2)
}
Version Constraints

See example

v, _ := version.Parse("2.1")
c, _ := version.NewSpecifiers(">= 1.0, < 1.4 || > 2.0")

if c.Check(v) {
	fmt.Printf("%s satisfies specifiers '%s'", v, c)
}

Status

  • >
  • >=
  • <
  • <=
  • ==
  • !=
  • ~=
  • ===

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SortedVersions

type SortedVersions []Version

func (SortedVersions) Len

func (s SortedVersions) Len() int

func (SortedVersions) Less

func (s SortedVersions) Less(i, j int) bool

func (SortedVersions) Swap

func (s SortedVersions) Swap(i, j int)

type SpecifierOption

type SpecifierOption interface {
	// contains filtered or unexported methods
}

type Specifiers

type Specifiers struct {
	// contains filtered or unexported fields
}

func NewRSpecifiers

func NewRSpecifiers(v string, sanitizer func(string) string, opts ...SpecifierOption) (Specifiers, error)

NewRSpecifiers parses a given specifier and returns a new instance of Specifiers intended for working with R package versions.

func NewSpecifiers

func NewSpecifiers(v string, opts ...SpecifierOption) (Specifiers, error)

NewSpecifiers parses a given specifier and returns a new instance of Specifiers

func NewSpecifiersWithSanitizer

func NewSpecifiersWithSanitizer(v string, sanitizer func(string) string, opts ...SpecifierOption) (Specifiers, error)

NewSpecifiersWithSanitizer parses a given specifier and returns a new instance of Specifiers it sanitizes the version string before parsing it with the given function.

func (Specifiers) Check

func (ss Specifiers) Check(v Version) bool

Check tests if a version satisfies all the specifiers.

func (Specifiers) String

func (ss Specifiers) String() string

String returns the string format of the specifiers

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a single version.

func MustParse

func MustParse(v string) Version

MustParse is like Parse but panics if the version cannot be parsed.

func Parse

func Parse(v string) (Version, error)

Parse parses the given version and returns a new Version.

func (Version) BaseVersion

func (v Version) BaseVersion() string

BaseVersion returns the base version

func (Version) Compare

func (v Version) Compare(other Version) int

Compare compares this version to another version. This returns -1, 0, or 1 if this version is smaller, equal, or larger than the other version, respectively.

func (Version) Equal

func (v Version) Equal(o Version) bool

Equal tests if two versions are equal.

func (Version) GreaterThan

func (v Version) GreaterThan(o Version) bool

GreaterThan tests if this version is greater than another version.

func (Version) GreaterThanOrEqual

func (v Version) GreaterThanOrEqual(o Version) bool

GreaterThanOrEqual tests if this version is greater than or equal to another version.

func (Version) IsPostRelease

func (v Version) IsPostRelease() bool

IsPostRelease returns if it is a post-release

func (Version) IsPreRelease

func (v Version) IsPreRelease() bool

IsPreRelease returns if it is a pre-release

func (Version) LessThan

func (v Version) LessThan(o Version) bool

LessThan tests if this version is less than another version.

func (Version) LessThanOrEqual

func (v Version) LessThanOrEqual(o Version) bool

LessThanOrEqual tests if this version is less than or equal to another version.

func (Version) Local

func (v Version) Local() string

Local returns the local version

func (Version) Original

func (v Version) Original() string

Original returns the original parsed version as-is, including any potential whitespace, `v` prefix, etc.

func (Version) Public

func (v Version) Public() string

Public returns the public version

func (Version) String

func (v Version) String() string

String returns the full version string included pre-release and metadata information.

type WithPreRelease

type WithPreRelease bool

Directories

Path Synopsis
examples
comparison command
specifier command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL