Skip to content

Commit

Permalink
PEP-660 support
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <gaborjbernat@gmail.com>
  • Loading branch information
gaborbernat committed Sep 17, 2022
1 parent 0ee8853 commit 74aecc8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v2.38.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
Expand Down Expand Up @@ -52,7 +52,7 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==22.8.23
- flake8-bugbear==22.9.11
- flake8-comprehensions==3.10
- flake8-pytest-style==1.6
- flake8-spellcheck==0.28
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=1.8.1", "hatch-vcs>=0.2"]
requires = ["hatchling>=1.9", "hatch-vcs>=0.2"]

[project]
name = "tox"
Expand All @@ -27,14 +27,14 @@ dependencies = [
"packaging>=21.3",
"platformdirs>=2.5.2",
"pluggy>=1",
"pyproject-api>=0.1.1",
'tomli>=2.0.1;python_version<"3.11"',
"pyproject-api>=1.1.1",
'tomli>=2.0.1; python_version < "3.11"',
"virtualenv>=20.16.5",
'importlib-metadata>=4.12; python_version < "3.8"',
'typing-extensions>=4.3; python_version < "3.8"',
]
optional-dependencies.docs = [
"furo>=2022.6.21",
"furo>=2022.9.15",
"sphinx>=5.1.1",
"sphinx-argparse-cli>=1.10",
"sphinx-autodoc-typehints>=1.19.2",
Expand All @@ -46,12 +46,12 @@ optional-dependencies.docs = [
optional-dependencies.testing = [
"covdefaults>=2.2",
"devpi-client>=6.0.1",
"devpi-server>=6.6",
"devpi-server>=6.6.1",
"distlib>=0.3.6",
"filelock>=3.8",
"flaky>=3.7",
"hatch-vcs>=0.2",
"hatchling>=1.8.1",
"hatchling>=1.9",
"psutil>=5.9.2",
"pytest>=7.1.3",
"pytest-cov>=3",
Expand Down
10 changes: 9 additions & 1 deletion src/tox/tox_env/python/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class DevLegacyPackage(PythonPathPackageWithDeps):
"""legacy dev package"""


class DevPackage(PythonPathPackageWithDeps):
"""PEP-660 dev package"""


class PythonPackageToxEnv(Python, PackageToxEnv, ABC):
def __init__(self, create_args: ToxEnvCreateArgs) -> None:
self._wheel_build_envs: dict[str, PythonPackageToxEnv] = {}
Expand All @@ -59,7 +63,11 @@ def requires(self) -> tuple[Requirement, ...] | PythonDeps:

def register_run_env(self, run_env: RunToxEnv) -> Generator[tuple[str, str], PackageToxEnv, None]:
yield from super().register_run_env(run_env)
if not isinstance(run_env, Python) or run_env.conf["package"] != "wheel" or "wheel_build_env" in run_env.conf:
if (
not isinstance(run_env, Python)
or run_env.conf["package"] not in {"wheel", "dev"}
or "wheel_build_env" in run_env.conf
):
return

def default_wheel_tag(conf: Config, env_name: str | None) -> str: # noqa: U100
Expand Down
2 changes: 1 addition & 1 deletion src/tox/tox_env/python/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def register_config(self) -> None:

@property
def _package_types(self) -> tuple[str, ...]:
return "wheel", "sdist", "dev-legacy", "skip", "external"
return "wheel", "sdist", "dev", "dev-legacy", "skip", "external"

def _register_package_conf(self) -> bool:
# provision package type
Expand Down
9 changes: 6 additions & 3 deletions src/tox/tox_env/python/virtual_env/package/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def register_run_env(self, run_env: RunToxEnv) -> Generator[tuple[str, str], Pac

def _setup_env(self) -> None:
super()._setup_env()
if "dev" in self.builds:
build_requires = self._frontend.get_requires_for_build_editable().requires
self.installer.install(build_requires, PythonPackageToxEnv.__name__, "requires_for_build_editable")
if "wheel" in self.builds:
build_requires = self._frontend.get_requires_for_build_wheel().requires
self.installer.install(build_requires, PythonPackageToxEnv.__name__, "requires_for_build_wheel")
Expand All @@ -153,21 +156,21 @@ def perform_packaging(self, for_env: EnvConfigSet) -> list[Package]:
of_type: str = for_env["package"]
if of_type == "dev-legacy":
self.setup()
deps = [*self.requires(), *self._frontend.get_requires_for_build_sdist().requires] + deps
package: Package = DevLegacyPackage(self.core["tox_root"], deps) # the folder itself is the package
elif of_type == "sdist":
self.setup()
with self._pkg_lock:
package = SdistPackage(self._frontend.build_sdist(sdist_directory=self.pkg_dir).sdist, deps)
elif of_type == "wheel":
elif of_type in {"wheel", "dev"}:
w_env = self._wheel_build_envs.get(for_env["wheel_build_env"])
if w_env is not None and w_env is not self:
with w_env.display_context(self._has_display_suspended):
return w_env.perform_packaging(for_env)
else:
self.setup()
with self._pkg_lock:
path = self._frontend.build_wheel(
method = "build_editable" if of_type == "dev" else "build_wheel"
path = getattr(self._frontend, method)(
wheel_directory=self.pkg_dir,
metadata_directory=self.meta_folder,
config_settings=self._wheel_config_settings,
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ envlist =
pkg_meta
isolated_build = true
skip_missing_interpreters = true
minversion = 4.0.0b2

[testenv]
description = run the tests with pytest under {envname}
Expand Down

0 comments on commit 74aecc8

Please sign in to comment.