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 Dec 11, 2021
1 parent f90db0a commit b3132b8
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import re
import sys
import shutil
import subprocess
import venv
import string
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 @@ -67,4 +72,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")
Loading

0 comments on commit b3132b8

Please sign in to comment.