Skip to content

Commit 1bb7bc4

Browse files
committed
Add validate-pyproject as a vendored dependency
In order to minimise dependencies, `validate-pyproject` has the ability to "dump" only the code necessary to run the validations to a given directory. This special strategy is used instead of the default `pip install -t`. The idea of using JSONSchema for validation was suggested in pypa#2671, and the rationale for that approach is further discussed in https://github.com/abravalheri/validate-pyproject/blob/main/docs/faq.rst Using a library such as `validate-pyproject` has the advantage of incentive sing reuse and collaboration with other projects. Currently `validate-pyproject` ships a JSONSchema for the proposed use of `pyproject.toml` as means of configuration for setuptools. In the future, if there is interest, setuptools could also ship its own schema and just use the shared infrastructure of `validate-pyproject` (by advertising the schemas via entry-points).
1 parent 2f464c6 commit 1bb7bc4

File tree

9 files changed

+1806
-2
lines changed

9 files changed

+1806
-2
lines changed

pavement.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import os
12
import re
23
import sys
4+
import shutil
35
import subprocess
6+
import venv
7+
import string
8+
from tempfile import TemporaryDirectory
49

5-
from paver.easy import task, path as Path
10+
from paver.easy import info, task, path as Path
611

712

813
def remove_all(paths):
@@ -67,4 +72,40 @@ def update_pkg_resources():
6772
def update_setuptools():
6873
vendor = Path('setuptools/_vendor')
6974
install(vendor)
75+
install_validate_pyproject(vendor)
7076
rewrite_packaging(vendor / 'packaging', 'setuptools.extern')
77+
78+
79+
def install_validate_pyproject(vendor):
80+
"""``validate-pyproject`` can be vendorized to remove all dependencies"""
81+
req = next(
82+
(x for x in (vendor / "vendored.txt").lines() if 'validate-pyproject' in x),
83+
"validate-pyproject[all]"
84+
)
85+
86+
pkg, _, _ = req.strip(string.whitespace + "#").partition("#")
87+
pkg = pkg.strip()
88+
89+
opts = {}
90+
if sys.version_info[:2] >= (3, 10):
91+
opts["ignore_cleanup_errors"] = True
92+
93+
with TemporaryDirectory(**opts) as tmp:
94+
venv.create(tmp, with_pip=True)
95+
path = os.pathsep.join(Path(tmp).glob("*"))
96+
venv_python = shutil.which("python", path=path)
97+
info(f"Temporarily installing {pkg!r}...")
98+
subprocess.check_call([venv_python, "-m", "pip", "install", pkg])
99+
cmd = [
100+
venv_python,
101+
"-m",
102+
"validate_pyproject.vendoring",
103+
"--output-dir",
104+
str(vendor / "_validate_pyproject"),
105+
"--enable-plugins",
106+
"setuptools",
107+
"distutils",
108+
"--very-verbose"
109+
]
110+
subprocess.check_output(cmd)
111+
info(f"{pkg!r} vendorized")

0 commit comments

Comments
 (0)