diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2021-12-03 10:04:00 +0000 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-05 09:58:49 +0000 |
| commit | 771488dabe71374a735b266c38e6b8c1fd94a02d (patch) | |
| tree | efd0e3cfb2da58c3f78becfd601cd69fe4e72bda /tools | |
| parent | 099ac60fba6f63d9658733f10c5525ecfb390eee (diff) | |
| download | python-setuptools-git-771488dabe71374a735b266c38e6b8c1fd94a02d.tar.gz | |
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 #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).
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/vendored.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/vendored.py b/tools/vendored.py index 8a122ad7..53185437 100644 --- a/tools/vendored.py +++ b/tools/vendored.py @@ -1,6 +1,11 @@ +import os import re import sys +import shutil +import string import subprocess +import venv +from tempfile import TemporaryDirectory from path import Path @@ -127,6 +132,7 @@ def update_pkg_resources(): def update_setuptools(): vendor = Path('setuptools/_vendor') install(vendor) + install_validate_pyproject(vendor) rewrite_packaging(vendor / 'packaging', 'setuptools.extern') rewrite_jaraco_text(vendor / 'jaraco/text', 'setuptools.extern') rewrite_jaraco(vendor / 'jaraco', 'setuptools.extern') @@ -135,4 +141,37 @@ def update_setuptools(): rewrite_more_itertools(vendor / "more_itertools") +def install_validate_pyproject(vendor): + """``validate-pyproject`` can be vendorized to remove all dependencies""" + req = next( + (x for x in (vendor / "vendored.txt").lines() if 'validate-pyproject' in x), + "validate-pyproject[all]" + ) + + pkg, _, _ = req.strip(string.whitespace + "#").partition("#") + pkg = pkg.strip() + + opts = {} + if sys.version_info[:2] >= (3, 10): + opts["ignore_cleanup_errors"] = True + + with TemporaryDirectory(**opts) as tmp: + venv.create(tmp, with_pip=True) + path = os.pathsep.join(Path(tmp).glob("*")) + venv_python = shutil.which("python", path=path) + subprocess.check_call([venv_python, "-m", "pip", "install", pkg]) + cmd = [ + venv_python, + "-m", + "validate_pyproject.vendoring", + "--output-dir", + str(vendor / "_validate_pyproject"), + "--enable-plugins", + "setuptools", + "distutils", + "--very-verbose" + ] + subprocess.check_call(cmd) + + __name__ == '__main__' and update_vendored() |
