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

Improve PEP-440 support for versions #140

Merged
merged 6 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(

if isinstance(self._constraint, VersionRange) and self._constraint.min:
allows_prereleases = (
allows_prereleases or self._constraint.min.is_prerelease()
allows_prereleases or self._constraint.min.is_unstable()
)

self._allows_prereleases = allows_prereleases
Expand Down Expand Up @@ -551,17 +551,17 @@ def create_from_pep_508(
if parsed_version.precision == 1:
if op == "<=":
op = "<"
version = parsed_version.next_major.text
version = parsed_version.next_major().text
elif op == ">":
op = ">="
version = parsed_version.next_major.text
version = parsed_version.next_major().text
elif parsed_version.precision == 2:
if op == "<=":
op = "<"
version = parsed_version.next_minor.text
version = parsed_version.next_minor().text
elif op == ">":
op = ">="
version = parsed_version.next_minor.text
version = parsed_version.next_minor().text
elif op in ("in", "not in"):
versions = []
for v in re.split("[ ,]+", version):
Expand Down
2 changes: 1 addition & 1 deletion poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def urls(self) -> Dict[str, str]:
return urls

def is_prerelease(self) -> bool:
return self._version.is_prerelease()
return self._version.is_unstable()

def is_root(self) -> bool:
return False
Expand Down
8 changes: 4 additions & 4 deletions poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,17 @@ def get_python_constraint_from_marker(
if parsed_version.precision == 1:
if op == "<=":
op = "<"
version = parsed_version.next_major.text
version = parsed_version.next_major().text
elif op == ">":
op = ">="
version = parsed_version.next_major.text
version = parsed_version.next_major().text
elif parsed_version.precision == 2:
if op == "<=":
op = "<"
version = parsed_version.next_minor.text
version = parsed_version.next_minor().text
elif op == ">":
op = ">="
version = parsed_version.next_minor.text
version = parsed_version.next_minor().text
elif op in ("in", "not in"):
versions = []
for v in re.split("[ ,]+", version):
Expand Down
4 changes: 0 additions & 4 deletions poetry/core/semver/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
class ParseVersionError(ValueError):
pass


class ParseConstraintError(ValueError):
pass
22 changes: 10 additions & 12 deletions poetry/core/semver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
m = TILDE_CONSTRAINT.match(constraint)
if m:
version = Version.parse(m.group(1))

high = version.stable.next_minor
high = version.stable.next_minor()
if len(m.group(1).split(".")) == 1:
high = version.stable.next_major
high = version.stable.next_major()

return VersionRange(version, high, include_min=True)

Expand All @@ -89,9 +88,9 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
version = Version.parse(m.group(1))

if precision == 2:
high = version.stable.next_major
high = version.stable.next_major()
else:
high = version.stable.next_minor
high = version.stable.next_minor()

return VersionRange(version, high, include_min=True)

Expand All @@ -100,7 +99,7 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
if m:
version = Version.parse(m.group(1))

return VersionRange(version, version.next_breaking, include_min=True)
return VersionRange(version, version.next_breaking(), include_min=True)

# X Range
m = X_CONSTRAINT.match(constraint)
Expand All @@ -110,16 +109,15 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
minor = m.group(3)

if minor is not None:
version = Version(major, int(minor), 0)

result = VersionRange(version, version.next_minor, include_min=True)
version = Version.from_parts(major, int(minor), 0)
result = VersionRange(version, version.next_minor(), include_min=True)
else:
if major == 0:
result = VersionRange(max=Version(1, 0, 0))
result = VersionRange(max=Version.from_parts(1, 0, 0))
else:
version = Version(major, 0, 0)
version = Version.from_parts(major, 0, 0)

result = VersionRange(version, version.next_major, include_min=True)
result = VersionRange(version, version.next_major(), include_min=True)

if op == "!=":
result = VersionRange().difference(result)
Expand Down
Loading