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

chore: detect available python versions for integration (#1249)

上级 a7879780
......@@ -113,6 +113,7 @@ jobs:
- name: Install Dev Dependencies
run: |
pdm install -v -dGtest
pdm run pip install -U setuptools
pdm info
- name: Run Tests
run: pdm run pytest -n auto --cov=pdm --cov-config=setup.cfg --cov-report=xml tests
......
......@@ -125,9 +125,12 @@ class Project:
@property
def pyproject(self) -> dict | None:
if not self._pyproject and self.pyproject_file.exists():
data = tomlkit.parse(self.pyproject_file.read_text("utf-8"))
self._pyproject = cast(dict, data)
if not self._pyproject:
if self.pyproject_file.exists():
data = tomlkit.parse(self.pyproject_file.read_text("utf-8"))
self._pyproject = cast(dict, data)
else:
self._pyproject = cast(dict, tomlkit.document())
return self._pyproject
@pyproject.setter
......
......@@ -127,8 +127,12 @@ def test_venv_activate_error(invoke, project):
assert result.exit_code != 0
assert "No virtualenv with key" in result.stderr
project.project_config["python.path"] = next(
project.find_interpreters()
).path.as_posix()
result = invoke(["venv", "activate"], obj=project)
assert result.exit_code != 0
print(project.project_config.get("python.path"))
assert result.exit_code != 0, result.output + result.stderr
assert "Can't activate a non-venv Python" in result.stderr
......
......@@ -18,7 +18,7 @@ from packaging.version import parse as parse_version
from unearth.vcs import Git, vcs_support
from pdm._types import CandidateInfo
from pdm.cli.actions import do_init, do_use
from pdm.cli.actions import do_init
from pdm.cli.hooks import HookManager
from pdm.core import Core
from pdm.exceptions import CandidateInfoNotFound
......@@ -290,11 +290,7 @@ def project_no_init(tmp_path, mocker, core, index, monkeypatch):
)
tmp_path.joinpath("caches").mkdir(parents=True)
p.global_config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
do_use(
p,
getattr(sys, "_base_executable", sys.executable),
HookManager(p, ["post_use"]),
)
p.project_config["python.path"] = getattr(sys, "_base_executable", sys.executable)
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
monkeypatch.delenv("CONDA_PREFIX", raising=False)
monkeypatch.delenv("PEP582_PACKAGES", raising=False)
......
import findpython
import pytest
from pdm.utils import cd
PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
PYPROJECT = """\
[project]
name = "test-project"
version = "0.1.0"
requires-python = ">=3.6"
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
"""
def get_python_versions():
finder = findpython.Finder(resolve_symlinks=True)
available_versions = []
for version in PYTHON_VERSIONS:
v = finder.find(version)
if v and v.is_valid():
available_versions.append(version)
return available_versions
@pytest.mark.integration
@pytest.mark.network
@pytest.mark.parametrize("python_version", ["3.6", "3.7", "3.8", "3.9", "3.10"])
@pytest.mark.parametrize("python_version", get_python_versions())
def test_basic_integration(python_version, core, tmp_path, invoke):
"""An e2e test case to ensure PDM works on all supported Python versions"""
project = core.create_project(tmp_path)
project.pyproject_file.write_text(PYPROJECT)
project.root.joinpath("foo.py").write_text("import django\n")
additional_args = ["--no-self"] if python_version == "2.7" else []
project._environment = project.pyproject = None
invoke(["use", "-f", python_version], obj=project, strict=True)
invoke(["init", "-n"], obj=project, strict=True)
project.meta["name"] = "test-project"
project.meta["version"] = "0.1.0"
project.meta[
"requires-python"
] = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*"
project.write_pyproject()
project._environment = None
invoke(["add", "django", "-v"] + additional_args, obj=project, strict=True)
invoke(["add", "django", "-v"], obj=project, strict=True)
with cd(project.root):
invoke(["run", "python", "foo.py"], obj=project, strict=True)
if python_version != "2.7":
invoke(["build", "-v"], obj=project, strict=True)
invoke(["remove", "-v", "django"] + additional_args, obj=project, strict=True)
invoke(["build", "-v"], obj=project, strict=True)
invoke(["remove", "-v", "django"], obj=project, strict=True)
result = invoke(["list"], obj=project, strict=True)
assert not any(
line.strip().lower().startswith("django") for line in result.output.splitlines()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册