Skip to content

Commit

Permalink
preview: poetry-core update with lark pep440
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Mar 27, 2021
1 parent 3738ae7 commit cc0db46
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 56 deletions.
21 changes: 17 additions & 4 deletions poetry.lock

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

27 changes: 9 additions & 18 deletions poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,22 @@ def increment_version(self, version: str, rule: str) -> "Version":
raise ValueError("The project's version doesn't seem to follow semver")

if rule in {"major", "premajor"}:
new = version.next_major
new = version.next_major()
if rule == "premajor":
new = new.first_prerelease
new = new.first_prerelease()
elif rule in {"minor", "preminor"}:
new = version.next_minor
new = version.next_minor()
if rule == "preminor":
new = new.first_prerelease
new = new.first_prerelease()
elif rule in {"patch", "prepatch"}:
new = version.next_patch
new = version.next_patch()
if rule == "prepatch":
new = new.first_prerelease
new = new.first_prerelease()
elif rule == "prerelease":
if version.is_prerelease():
pre = version.prerelease
new_prerelease = int(pre[1]) + 1
new = Version.parse(
"{}.{}.{}-{}".format(
version.major,
version.minor,
version.patch,
".".join([pre[0], str(new_prerelease)]),
)
)
if version.is_unstable():
new = Version(version.epoch, version.release, version.pre.next())
else:
new = version.next_patch.first_prerelease
new = version.next_patch().first_prerelease()
else:
new = Version.parse(rule)

Expand Down
5 changes: 3 additions & 2 deletions poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ def _install_directory(self, operation: Union[Install, Update]) -> int:
# some versions of pip (< 19.0.0) don't understand it
# so we need to check the version of pip to know
# if we can rely on the build system
legacy_pip = self._env.pip_version < self._env.pip_version.__class__(
19, 0, 0
legacy_pip = (
self._env.pip_version
< self._env.pip_version.__class__.from_parts(19, 0, 0)
)
package_poetry = Factory().create_poetry(pyproject.file.path.parent)

Expand Down
2 changes: 1 addition & 1 deletion poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _setup_build(self) -> None:
f.write(decode(builder.build_setup()))

try:
if self._env.pip_version < Version(19, 0):
if self._env.pip_version < Version.from_parts(19, 0):
pip_editable_install(self._path, self._env)
else:
# Temporarily rename pyproject.toml
Expand Down
2 changes: 1 addition & 1 deletion poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _get_min(dependency: Dependency) -> int:
if locked and (
dependency.constraint.allows(locked.version)
or locked.is_prerelease()
and dependency.constraint.allows(locked.version.next_patch)
and dependency.constraint.allows(locked.version.next_patch())
):
return 1

Expand Down
2 changes: 1 addition & 1 deletion poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _get_lock_data(self) -> "TOMLDocument":
# We expect the locker to be able to read lock files
# from the same semantic versioning range
accepted_versions = parse_constraint(
"^{}".format(Version(current_version.major, 0))
"^{}".format(Version.from_parts(current_version.major, 0))
)
lock_version_allowed = accepted_versions.allows(lock_version)
if lock_version_allowed and current_version < lock_version:
Expand Down
2 changes: 1 addition & 1 deletion poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from poetry.core.masonry.metadata import Metadata
from poetry.core.masonry.utils.helpers import escape_name
from poetry.core.masonry.utils.helpers import escape_version
from poetry.utils.helpers import normalize_version
from poetry.core.utils.helpers import normalize_version
from poetry.utils.patterns import wheel_file_re


Expand Down
2 changes: 1 addition & 1 deletion poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def reachable(self) -> List["PackageNode"]:
if pkg.complete_name == dependency.complete_name and (
dependency.constraint.allows(pkg.version)
or dependency.allows_prereleases()
and pkg.version.is_prerelease()
and pkg.version.is_unstable()
and dependency.constraint.allows(pkg.version.stable)
):
# If there is already a child with this name
Expand Down
6 changes: 3 additions & 3 deletions poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def find_packages(self, dependency: "Dependency") -> List[Package]:
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
and constraint.max.is_unstable()
or constraint.min is not None
and constraint.min.is_prerelease()
and constraint.min.is_unstable()
):
allow_prereleases = True

Expand All @@ -275,7 +275,7 @@ def find_packages(self, dependency: "Dependency") -> List[Package]:

versions = []
for version in page.versions:
if version.is_prerelease() and not allow_prereleases:
if version.is_unstable() and not allow_prereleases:
if constraint.is_any():
# we need this when all versions of the package are pre-releases
ignored_pre_release_versions.append(version)
Expand Down
10 changes: 5 additions & 5 deletions poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.utils.link import Link
from poetry.core.semver.exceptions import ParseVersionError
from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version_constraint import VersionConstraint
from poetry.core.semver.version_range import VersionRange
from poetry.core.version.exceptions import InvalidVersion
from poetry.core.version.markers import parse_marker
from poetry.locations import REPOSITORY_CACHE_DIR
from poetry.utils._compat import to_str
Expand Down Expand Up @@ -98,9 +98,9 @@ def find_packages(self, dependency: Dependency) -> List[Package]:
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
and constraint.max.is_unstable()
or constraint.min is not None
and constraint.min.is_prerelease()
and constraint.min.is_unstable()
):
allow_prereleases = True

Expand Down Expand Up @@ -129,7 +129,7 @@ def find_packages(self, dependency: Dependency) -> List[Package]:

try:
package = Package(info["info"]["name"], version)
except ParseVersionError:
except InvalidVersion:
self._log(
'Unable to parse version "{}" for the {} package, skipping'.format(
version, dependency.name
Expand Down Expand Up @@ -186,7 +186,7 @@ def search(self, query: str) -> List[Package]:
result = Package(name, version, description)
result.description = to_str(description.strip())
results.append(result)
except ParseVersionError:
except InvalidVersion:
self._log(
'Unable to parse version "{}" for the {} package, skipping'.format(
version, name
Expand Down
6 changes: 3 additions & 3 deletions poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def find_packages(self, dependency: "Dependency") -> List["Package"]:
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
and constraint.max.is_unstable()
or constraint.min is not None
and constraint.min.is_prerelease()
and constraint.min.is_unstable()
):
allow_prereleases = True

Expand All @@ -77,7 +77,7 @@ def find_packages(self, dependency: "Dependency") -> List["Package"]:

if constraint.allows(package.version) or (
package.is_prerelease()
and constraint.allows(package.version.next_patch)
and constraint.allows(package.version.next_patch())
):
packages.append(package)

Expand Down
5 changes: 0 additions & 5 deletions poetry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from poetry.config.config import Config
from poetry.core.packages.package import Package
from poetry.core.version import Version


try:
Expand All @@ -37,10 +36,6 @@ def module_name(name: str) -> str:
return canonicalize_name(name).replace(".", "_").replace("-", "_")


def normalize_version(version: str) -> str:
return str(Version(version))


def _del_ro(action: Callable, name: str, exc: Exception) -> None:
os.chmod(name, stat.S_IWRITE)
os.remove(name)
Expand Down
6 changes: 3 additions & 3 deletions poetry/version/version_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def find_best_candidate(
},
)
candidates = self._pool.find_packages(dependency)
only_prereleases = all([c.version.is_prerelease() for c in candidates])
only_prereleases = all([c.version.is_unstable() for c in candidates])

if not candidates:
return False
Expand Down Expand Up @@ -77,7 +77,7 @@ def _transform_version(self, version: str, pretty_version: str) -> str:
version = pretty_version
else:
version = ".".join(str(p) for p in parts)
if parsed.is_prerelease():
version += "-{}".format(".".join(str(p) for p in parsed.prerelease))
if parsed.is_unstable():
version += "-{}".format(parsed.pre.to_string())

return "^{}".format(version)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ generate-setup-file = false
[tool.poetry.dependencies]
python = "^3.6"

poetry-core = { git = "https://github.com/python-poetry/poetry-core", branch = "master"}
poetry-core = { git = "https://github.com/abn/poetry-core.git", branch = "semver/lark"}
cleo = "^1.0.0a1"
crashtest = "^0.3.0"
requests = "^2.18"
Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/env/test_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup(mocker):
def mock_subprocess_calls(setup, current_python, mocker):
mocker.patch(
"subprocess.check_output",
side_effect=check_output_wrapper(Version(*current_python)),
side_effect=check_output_wrapper(Version.from_parts(*current_python)),
)
mocker.patch(
"subprocess.Popen.communicate",
Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/self/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_self_update_should_install_all_necessary_elements(

command = tester.command

version = Version.parse(__version__).next_minor.text
version = Version.parse(__version__).next_minor().text
mocker.patch(
"poetry.repositories.pypi_repository.PyPiRepository.find_packages",
return_value=[Package("poetry", version)],
Expand Down
2 changes: 1 addition & 1 deletion tests/mixology/version_solver/test_backtracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_backjump_to_nearer_unsatisfied_package(root, provider, repo):
root.add_dependency(Factory.create_dependency("b", "*"))

add_to_repo(repo, "a", "1.0.0", deps={"c": "1.0.0"})
add_to_repo(repo, "a", "2.0.0", deps={"c": "2.0.0-nonexistent"})
add_to_repo(repo, "a", "2.0.0", deps={"c": "2.0.0-1"})
add_to_repo(repo, "b", "1.0.0")
add_to_repo(repo, "b", "2.0.0")
add_to_repo(repo, "b", "3.0.0")
Expand Down
4 changes: 3 additions & 1 deletion tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ def test_locker_should_emit_warnings_if_lock_version_is_newer_but_allowed(
[metadata.files]
""".format(
version=".".join(Version.parse(Locker._VERSION).next_minor.text.split(".")[:2])
version=".".join(
Version.parse(Locker._VERSION).next_minor().text.split(".")[:2]
)
)
caplog.set_level(logging.WARNING, logger="poetry.packages.locker")

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def test_deactivate_activated(tmp_dir, manager, poetry, config, mocker):

venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
other_version = Version.parse("3.4") if version.major == 2 else version.next_minor
other_version = Version.parse("3.4") if version.major == 2 else version.next_minor()
(
Path(tmp_dir) / "{}-py{}.{}".format(venv_name, version.major, version.minor)
).mkdir()
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from poetry.core.semver.exceptions import ParseVersionError
from poetry.core.version.exceptions import InvalidVersion
from poetry.utils.setup_reader import SetupReader


Expand Down Expand Up @@ -115,7 +115,7 @@ def test_setup_reader_read_setup_cfg(setup):


def test_setup_reader_read_setup_cfg_with_attr(setup):
with pytest.raises(ParseVersionError):
with pytest.raises(InvalidVersion):
SetupReader.read_from_directory(setup("with-setup-cfg-attr"))


Expand Down

0 comments on commit cc0db46

Please sign in to comment.