未验证 提交 c9ce9f5a 编写于 作者: F Frost Ming

Fix python version subset check

上级 9a562840
Regard `4.0` as infinite upper bound when checking subsetting.
Display all availible Python interpreters if users don't give on in `pdm init`.
......@@ -447,7 +447,7 @@ def do_use(project: Project, python: str, first: bool = False) -> None:
"""Use the specified python version and save in project config.
The python can be a version string or interpreter path.
"""
if not all(c.isdigit() for c in python.split(".")):
if python and not all(c.isdigit() for c in python.split(".")):
if Path(python).exists():
python_path = Path(python).absolute().as_posix()
else:
......@@ -458,7 +458,7 @@ def do_use(project: Project, python: str, first: bool = False) -> None:
else:
finder = pythonfinder.Finder()
pythons = []
args = [int(v) for v in python.split(".")]
args = [int(v) for v in python.split(".") if v != ""]
for i, entry in enumerate(finder.find_all_python_versions(*args)):
python_version = get_python_version(entry.path.as_posix(), True)
pythons.append((entry.path.as_posix(), python_version))
......
......@@ -289,7 +289,9 @@ def build(project, sdist, wheel, dest, clean):
@pass_project
def init(project):
"""Initialize a pyproject.toml for PDM."""
python = click.prompt("Please enter the Python interpreter to use")
python = click.prompt(
"Please enter the Python interpreter to use", default="", show_default=False
)
actions.do_use(project, python)
if project.pyproject_file.exists():
......
......@@ -86,6 +86,7 @@ class PySpecSet(SpecifierSet):
(3, 6): 10,
(3, 7): 6,
}
MAX_MAJOR_VERSION = 4
MIN_VERSION = (-1, -1, -1)
MAX_VERSION = (99, 99, 99)
......@@ -381,6 +382,10 @@ class PySpecSet(SpecifierSet):
if self.is_allow_all:
return True
other = type(self)(str(other))
if other._upper_bound[0] >= self.MAX_MAJOR_VERSION:
# XXX: narrow down the upper bound to ``MAX_MAJOR_VERSION``
# So that `>=3.6,<4.0` is considered a superset of `>=3.7`, see issues/66
other._upper_bound = (self.MAX_MAJOR_VERSION, 0, 0)
if (
self._lower_bound > other._lower_bound
or self._upper_bound < other._upper_bound
......@@ -398,6 +403,8 @@ class PySpecSet(SpecifierSet):
if self.is_impossible:
return False
other = type(self)(str(other))
if other._upper_bound[0] >= self.MAX_MAJOR_VERSION:
other._upper_bound = self.MAX_VERSION
if other.is_allow_all:
return True
if (
......
......@@ -200,3 +200,9 @@ def test_resolve_two_extras_from_the_same_package(project, repository):
result = resolve_requirements(repository, [line])
assert "pysocks" in result
assert "pyopenssl" in result
def test_resolve_package_with_dummy_upbound(project, repository):
repository.add_candidate("foo", "0.1.0", ">=3.6,<4.0")
result = resolve_requirements(repository, ["foo"], ">=3.5")
assert "foo" in result
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册