Commit 728fb6f4 by Sébastien Eustace

Fix prereleases being selected with the add command

parent 58dbca46
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
- Fixed a possible error when building distributions with the `exclude` option. - Fixed a possible error when building distributions with the `exclude` option.
- Fixed the `run` command for namespaced packages. - Fixed the `run` command for namespaced packages.
- Fixed errors for virtualenvs with spaces in their path. - Fixed errors for virtualenvs with spaces in their path.
- Fixed prerelease versions being selected with the `add` command.
## [0.12.8] - 2018-11-13 ## [0.12.8] - 2018-11-13
......
...@@ -37,6 +37,7 @@ from poetry.packages.utils.link import Link ...@@ -37,6 +37,7 @@ from poetry.packages.utils.link import Link
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
from poetry.semver import Version from poetry.semver import Version
from poetry.semver import VersionConstraint from poetry.semver import VersionConstraint
from poetry.semver import VersionRange
from poetry.utils._compat import Path from poetry.utils._compat import Path
from poetry.utils.helpers import canonicalize_name, get_http_basic_auth from poetry.utils.helpers import canonicalize_name, get_http_basic_auth
from poetry.version.markers import InvalidMarker from poetry.version.markers import InvalidMarker
...@@ -187,11 +188,23 @@ class LegacyRepository(PyPiRepository): ...@@ -187,11 +188,23 @@ class LegacyRepository(PyPiRepository):
): ):
packages = [] packages = []
if constraint is not None and not isinstance(constraint, VersionConstraint): if constraint is None:
constraint = "*"
if not isinstance(constraint, VersionConstraint):
constraint = parse_constraint(constraint) constraint = parse_constraint(constraint)
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
or constraint.min is not None
and constraint.min.is_prerelease()
):
allow_prereleases = True
key = name key = name
if constraint: if not constraint.is_any():
key = "{}:{}".format(key, str(constraint)) key = "{}:{}".format(key, str(constraint))
if self._cache.store("matches").has(key): if self._cache.store("matches").has(key):
...@@ -203,7 +216,10 @@ class LegacyRepository(PyPiRepository): ...@@ -203,7 +216,10 @@ class LegacyRepository(PyPiRepository):
versions = [] versions = []
for version in page.versions: for version in page.versions:
if not constraint or (constraint and constraint.allows(version)): if version.is_prerelease() and not allow_prereleases:
continue
if constraint.allows(version):
versions.append(version) versions.append(version)
self._cache.store("matches").put(key, versions, 5) self._cache.store("matches").put(key, versions, 5)
......
...@@ -28,17 +28,16 @@ from cachy import CacheManager ...@@ -28,17 +28,16 @@ from cachy import CacheManager
from requests import get from requests import get
from requests import session from requests import session
from poetry.io import NullIO
from poetry.locations import CACHE_DIR from poetry.locations import CACHE_DIR
from poetry.packages import dependency_from_pep_508 from poetry.packages import dependency_from_pep_508
from poetry.packages import Package from poetry.packages import Package
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
from poetry.semver import VersionConstraint from poetry.semver import VersionConstraint
from poetry.semver import VersionRange
from poetry.utils._compat import Path from poetry.utils._compat import Path
from poetry.utils._compat import to_str from poetry.utils._compat import to_str
from poetry.utils.helpers import parse_requires from poetry.utils.helpers import parse_requires
from poetry.utils.helpers import temporary_directory from poetry.utils.helpers import temporary_directory
from poetry.utils.env import Env
from poetry.utils.setup_reader import SetupReader from poetry.utils.setup_reader import SetupReader
from poetry.version.markers import InvalidMarker from poetry.version.markers import InvalidMarker
...@@ -93,6 +92,15 @@ class PyPiRepository(Repository): ...@@ -93,6 +92,15 @@ class PyPiRepository(Repository):
if not isinstance(constraint, VersionConstraint): if not isinstance(constraint, VersionConstraint):
constraint = parse_constraint(constraint) constraint = parse_constraint(constraint)
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
or constraint.min is not None
and constraint.min.is_prerelease()
):
allow_prereleases = True
info = self.get_package_info(name) info = self.get_package_info(name)
packages = [] packages = []
...@@ -110,11 +118,7 @@ class PyPiRepository(Repository): ...@@ -110,11 +118,7 @@ class PyPiRepository(Repository):
package = Package(name, version) package = Package(name, version)
if ( if package.is_prerelease() and not allow_prereleases:
package.is_prerelease()
and not allow_prereleases
and not constraint.allows(package.version)
):
continue continue
if not constraint or (constraint and constraint.allows(package.version)): if not constraint or (constraint and constraint.allows(package.version)):
......
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
from poetry.semver import VersionConstraint from poetry.semver import VersionConstraint
from poetry.semver import VersionRange
from .base_repository import BaseRepository from .base_repository import BaseRepository
...@@ -46,16 +47,21 @@ class Repository(BaseRepository): ...@@ -46,16 +47,21 @@ class Repository(BaseRepository):
if not isinstance(constraint, VersionConstraint): if not isinstance(constraint, VersionConstraint):
constraint = parse_constraint(constraint) constraint = parse_constraint(constraint)
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
and constraint.max.is_prerelease()
or constraint.min is not None
and constraint.min.is_prerelease()
):
allow_prereleases = True
for package in self.packages: for package in self.packages:
if name == package.name: if name == package.name:
if ( if package.is_prerelease() and not allow_prereleases:
package.is_prerelease()
and not allow_prereleases
and not constraint.allows(package.version)
):
continue continue
if constraint is None or constraint.allows(package.version): if constraint.allows(package.version):
for dep in package.requires: for dep in package.requires:
for extra in extras: for extra in extras:
if extra not in package.extras: if extra not in package.extras:
......
...@@ -418,3 +418,36 @@ Writing lock file ...@@ -418,3 +418,36 @@ Writing lock file
assert "cachy" in content["dev-dependencies"] assert "cachy" in content["dev-dependencies"]
assert content["dev-dependencies"]["cachy"] == "^0.2.0" assert content["dev-dependencies"]["cachy"] == "^0.2.0"
def test_add_should_not_select_prereleases(app, repo, installer):
command = app.find("add")
tester = CommandTester(command)
repo.add_package(get_package("pyyaml", "3.13"))
repo.add_package(get_package("pyyaml", "4.2b2"))
tester.execute([("command", command.get_name()), ("name", ["pyyaml"])])
expected = """\
Using version ^3.13 for pyyaml
Updating dependencies
Resolving dependencies...
Package operations: 1 install, 0 updates, 0 removals
Writing lock file
- Installing pyyaml (3.13)
"""
assert tester.get_display(True) == expected
assert len(installer.installs) == 1
content = app.poetry.file.read()["tool"]["poetry"]
assert "pyyaml" in content["dependencies"]
assert content["dependencies"]["pyyaml"] == "^3.13"
<!DOCTYPE html>
<html>
<head>
<title>Links for python-language-server</title>
</head>
<body>
<h1>Links for python-language-server</h1>
<a href="https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz#sha256=3ef3092145e9b70e3ddd2c7ad59bdd0252a94dfe3949721633e41344de00a6bf">PyYAML-3.13.tar.gz</a><br/>
<a href="https://files.pythonhosted.org/packages/0f/9d/f98ed0a460dc540f720bbe5c6e076f025595cdfa3e318fad27165db13cf9/PyYAML-4.2b2.tar.gz#sha256=406b717f739e2d00c49873068b71f5454c2420157db51b082d4d2beb17ffffb6">PyYAML-4.2b2.tar.gz</a><br/>
</body>
</html>
<!--SERIAL 4245719-->
...@@ -128,3 +128,11 @@ def test_get_package_information_skips_dependencies_with_invalid_constraints(): ...@@ -128,3 +128,11 @@ def test_get_package_information_skips_dependencies_with_invalid_constraints():
Dependency("pyflakes", ">=1.6.0"), Dependency("pyflakes", ">=1.6.0"),
Dependency("yapf", "*"), Dependency("yapf", "*"),
] ]
def test_find_packages_no_prereleases():
repo = MockRepository()
packages = repo.find_packages("pyyaml")
assert len(packages) == 1
...@@ -58,6 +58,13 @@ def test_find_packages_with_prereleases(): ...@@ -58,6 +58,13 @@ def test_find_packages_with_prereleases():
assert len(packages) == 7 assert len(packages) == 7
def test_find_packages_does_not_select_prereleases_if_not_allowed():
repo = MockRepository()
packages = repo.find_packages("pyyaml")
assert len(packages) == 1
def test_package(): def test_package():
repo = MockRepository() repo = MockRepository()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment