mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 04:17:37 +00:00
Copy over pep440-rs crate (#30)
This PR copies over the `pep440-rs` crate at commit `a8303b01ffef6fccfdce562a887f6b110d482ef3` with no modifications. It won't pass CI, but modifications will intentionally be confined to later PRs.
This commit is contained in:
parent
1e6a217503
commit
f03398bee3
15 changed files with 3480 additions and 0 deletions
42
crates/pep440-rs/python/Readme.md
Normal file
42
crates/pep440-rs/python/Readme.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# PEP440 in rust
|
||||
|
||||
A library for python version numbers and specifiers, implementing
|
||||
[PEP 440](https://peps.python.org/pep-0440)
|
||||
|
||||
```shell
|
||||
pip install pep440_rs
|
||||
```
|
||||
|
||||
```python
|
||||
from pep440_rs import Version, VersionSpecifier
|
||||
|
||||
assert Version("1.1a1").any_prerelease()
|
||||
assert Version("1.1.dev2").any_prerelease()
|
||||
assert not Version("1.1").any_prerelease()
|
||||
assert VersionSpecifier(">=1.0").contains(Version("1.1a1"))
|
||||
assert not VersionSpecifier(">=1.1").contains(Version("1.1a1"))
|
||||
assert Version("2.0") in VersionSpecifier("==2")
|
||||
```
|
||||
|
||||
Unlike [pypa/packaging](https://github.com/pypa/packaging), this library always matches preleases. To only match final releases, filter with `.any_prelease()` beforehand.
|
||||
|
||||
PEP 440 has a lot of unintuitive features, including:
|
||||
|
||||
* An epoch that you can prefix the version which, e.g. `1!1.2.3`. Lower epoch always means lower
|
||||
version (`1.0 <=2!0.1`)
|
||||
* post versions, which can be attached to both stable releases and prereleases
|
||||
* dev versions, which can be attached to sbpth table releases and prereleases. When attached to a
|
||||
prerelease the dev version is ordered just below the normal prerelease, however when attached
|
||||
to a stable version, the dev version is sorted before a prereleases
|
||||
* prerelease handling is a mess: "Pre-releases of any kind, including developmental releases,
|
||||
are implicitly excluded from all version specifiers, unless they are already present on the
|
||||
system, explicitly requested by the user, or if the only available version that satisfies
|
||||
the version specifier is a pre-release.". This means that we can't say whether a specifier
|
||||
matches without also looking at the environment
|
||||
* prelease vs. prerelease incl. dev is fuzzy
|
||||
* local versions on top of all the others, which are added with a + and have implicitly typed
|
||||
string and number segments
|
||||
* no semver-caret (`^`), but a pseudo-semver tilde (`~=`)
|
||||
* ordering contradicts matching: We have e.g. `1.0+local > 1.0` when sorting,
|
||||
but `==1.0` matches `1.0+local`. While the ordering of versions itself is a total order
|
||||
the version matching needs to catch all sorts of special cases
|
||||
22
crates/pep440-rs/python/pep440_rs/__init__.py
Normal file
22
crates/pep440-rs/python/pep440_rs/__init__.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
A PEP440 reimplementation in rust
|
||||
|
||||
```python
|
||||
from pep440_rs import Version, VersionSpecifier
|
||||
|
||||
|
||||
assert Version("1.1a1").any_prerelease()
|
||||
assert Version("1.1.dev2").any_prerelease()
|
||||
assert not Version("1.1").any_prerelease()
|
||||
assert VersionSpecifier(">=1.0").contains(Version("1.1a1"))
|
||||
assert not VersionSpecifier(">=1.1").contains(Version("1.1a1"))
|
||||
assert Version("2.0") in VersionSpecifier("==2")
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
from ._pep440_rs import *
|
||||
|
||||
__doc__ = _pep440_rs.__doc__
|
||||
if hasattr(_pep440_rs, "__all__"):
|
||||
__all__ = _pep440_rs.__all__
|
||||
40
crates/pep440-rs/python/pep440_rs/__init__.pyi
Normal file
40
crates/pep440-rs/python/pep440_rs/__init__.pyi
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Generated by `stubgen -p pep440_rs`
|
||||
from typing import Any, ClassVar
|
||||
|
||||
|
||||
class Version:
|
||||
dev: Any
|
||||
epoch: Any
|
||||
post: Any
|
||||
pre: Any
|
||||
release: Any
|
||||
major: Any
|
||||
minor: Any
|
||||
micro: Any
|
||||
|
||||
@classmethod
|
||||
def __init__(cls, *args, **kwargs) -> None: ...
|
||||
def any_prerelease(self, *args, **kwargs) -> Any: ...
|
||||
def parse_star(self, *args, **kwargs) -> Any: ...
|
||||
def __eq__(self, other) -> Any: ...
|
||||
def __ge__(self, other) -> Any: ...
|
||||
def __gt__(self, other) -> Any: ...
|
||||
def __hash__(self) -> Any: ...
|
||||
def __le__(self, other) -> Any: ...
|
||||
def __lt__(self, other) -> Any: ...
|
||||
def __ne__(self, other) -> Any: ...
|
||||
|
||||
|
||||
class VersionSpecifier:
|
||||
__hash__: ClassVar[None] = ...
|
||||
|
||||
@classmethod
|
||||
def __init__(cls, *args, **kwargs) -> None: ...
|
||||
def contains(self, *args, **kwargs) -> Any: ...
|
||||
def __contains__(self, other) -> Any: ...
|
||||
def __eq__(self, other) -> Any: ...
|
||||
def __ge__(self, other) -> Any: ...
|
||||
def __gt__(self, other) -> Any: ...
|
||||
def __le__(self, other) -> Any: ...
|
||||
def __lt__(self, other) -> Any: ...
|
||||
def __ne__(self, other) -> Any: ...
|
||||
Loading…
Add table
Add a link
Reference in a new issue