Skip to content

Commit

Permalink
Add validate-pyproject as a vendored dependency
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
abravalheri committed Jan 7, 2022
1 parent 622c185 commit dd6e88b
Show file tree
Hide file tree
Showing 9 changed files with 1,806 additions and 2 deletions.
43 changes: 42 additions & 1 deletion pavement.py
@@ -1,9 +1,14 @@
import os
import re
import sys
import shutil
import string
import subprocess
import venv
from fnmatch import fnmatch
from tempfile import TemporaryDirectory

from paver.easy import task, path as Path
from paver.easy import info, task, path as Path


def remove_all(paths):
Expand Down Expand Up @@ -99,4 +104,40 @@ def update_pkg_resources():
def update_setuptools():
vendor = Path('setuptools/_vendor')
install(vendor)
install_validate_pyproject(vendor)
rewrite_packaging(vendor / 'packaging', 'setuptools.extern')


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)
info(f"Temporarily installing {pkg!r}...")
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_output(cmd)
info(f"{pkg!r} vendorized")

0 comments on commit dd6e88b

Please sign in to comment.