summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <p.f.moore@gmail.com>2022-10-10 12:20:36 +0100
committerPaul Moore <p.f.moore@gmail.com>2022-10-10 12:22:56 +0100
commit77a0a61722099ab479d29e8e191dea972ac3996f (patch)
tree79640446f8025c2acfd9fe297590a0c63e7e1970
parentc423e4290964ff8d10c29f39c1f46e1ee889bbce (diff)
downloadpip-77a0a61722099ab479d29e8e191dea972ac3996f.tar.gz
Upgrade pep517 to 0.13.0
-rw-r--r--news/pep517.vendor.rst1
-rw-r--r--src/pip/_vendor/pep517/__init__.py2
-rw-r--r--src/pip/_vendor/pep517/_compat.py8
-rw-r--r--src/pip/_vendor/pep517/build.py13
-rw-r--r--src/pip/_vendor/pep517/check.py16
-rw-r--r--src/pip/_vendor/pep517/colorlog.py2
-rw-r--r--src/pip/_vendor/pep517/compat.py51
-rw-r--r--src/pip/_vendor/pep517/dirtools.py27
-rw-r--r--src/pip/_vendor/pep517/envbuild.py15
-rw-r--r--src/pip/_vendor/pep517/in_process/__init__.py17
-rw-r--r--src/pip/_vendor/pep517/in_process/_in_process.py36
-rw-r--r--src/pip/_vendor/pep517/meta.py13
-rw-r--r--src/pip/_vendor/pep517/wrappers.py55
-rw-r--r--src/pip/_vendor/vendor.txt2
14 files changed, 86 insertions, 172 deletions
diff --git a/news/pep517.vendor.rst b/news/pep517.vendor.rst
new file mode 100644
index 000000000..e18c1d87b
--- /dev/null
+++ b/news/pep517.vendor.rst
@@ -0,0 +1 @@
+Upgrade pep517 to 0.13.0
diff --git a/src/pip/_vendor/pep517/__init__.py b/src/pip/_vendor/pep517/__init__.py
index 2b6b88567..38ea0f5f1 100644
--- a/src/pip/_vendor/pep517/__init__.py
+++ b/src/pip/_vendor/pep517/__init__.py
@@ -1,6 +1,6 @@
"""Wrappers to build Python packages using PEP 517 hooks
"""
-__version__ = '0.12.0'
+__version__ = '0.13.0'
from .wrappers import * # noqa: F401, F403
diff --git a/src/pip/_vendor/pep517/_compat.py b/src/pip/_vendor/pep517/_compat.py
new file mode 100644
index 000000000..95e509c01
--- /dev/null
+++ b/src/pip/_vendor/pep517/_compat.py
@@ -0,0 +1,8 @@
+__all__ = ("tomllib",)
+
+import sys
+
+if sys.version_info >= (3, 11):
+ import tomllib
+else:
+ from pip._vendor import tomli as tomllib
diff --git a/src/pip/_vendor/pep517/build.py b/src/pip/_vendor/pep517/build.py
index bc463b2ba..b30909c87 100644
--- a/src/pip/_vendor/pep517/build.py
+++ b/src/pip/_vendor/pep517/build.py
@@ -1,15 +1,14 @@
"""Build a project using PEP 517 hooks.
"""
import argparse
-import io
import logging
import os
import shutil
+import tempfile
+from ._compat import tomllib
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller
-from .dirtools import tempdir, mkdir_p
-from .compat import FileNotFoundError, toml_load
log = logging.getLogger(__name__)
@@ -31,8 +30,8 @@ def load_system(source_dir):
Load the build system from a source dir (pyproject.toml).
"""
pyproject = os.path.join(source_dir, 'pyproject.toml')
- with io.open(pyproject, 'rb') as f:
- pyproject_data = toml_load(f)
+ with open(pyproject, 'rb') as f:
+ pyproject_data = tomllib.load(f)
return pyproject_data['build-system']
@@ -64,7 +63,7 @@ def _do_build(hooks, env, dist, dest):
env.pip_install(reqs)
log.info('Installed dynamic build dependencies')
- with tempdir() as td:
+ with tempfile.TemporaryDirectory() as td:
log.info('Trying to build %s in %s', dist, td)
build_name = 'build_{dist}'.format(**locals())
build = getattr(hooks, build_name)
@@ -76,7 +75,7 @@ def _do_build(hooks, env, dist, dest):
def build(source_dir, dist, dest=None, system=None):
system = system or load_system(source_dir)
dest = os.path.join(source_dir, dest or 'dist')
- mkdir_p(dest)
+ os.makedirs(dest, exist_ok=True)
validate_system(system)
hooks = Pep517HookCaller(
diff --git a/src/pip/_vendor/pep517/check.py b/src/pip/_vendor/pep517/check.py
index bf3c72264..b79f6270b 100644
--- a/src/pip/_vendor/pep517/check.py
+++ b/src/pip/_vendor/pep517/check.py
@@ -1,19 +1,19 @@
"""Check a project and backend by attempting to build using PEP 517 hooks.
"""
import argparse
-import io
import logging
import os
-from os.path import isfile, join as pjoin
import shutil
-from subprocess import CalledProcessError
import sys
import tarfile
-from tempfile import mkdtemp
import zipfile
+from os.path import isfile
+from os.path import join as pjoin
+from subprocess import CalledProcessError
+from tempfile import mkdtemp
+from ._compat import tomllib
from .colorlog import enable_colourful_output
-from .compat import TOMLDecodeError, toml_load
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller
@@ -142,15 +142,15 @@ def check(source_dir):
return False
try:
- with io.open(pyproject, 'rb') as f:
- pyproject_data = toml_load(f)
+ with open(pyproject, 'rb') as f:
+ pyproject_data = tomllib.load(f)
# Ensure the mandatory data can be loaded
buildsys = pyproject_data['build-system']
requires = buildsys['requires']
backend = buildsys['build-backend']
backend_path = buildsys.get('backend-path')
log.info('Loaded pyproject.toml')
- except (TOMLDecodeError, KeyError):
+ except (tomllib.TOMLDecodeError, KeyError):
log.error("Invalid pyproject.toml", exc_info=True)
return False
diff --git a/src/pip/_vendor/pep517/colorlog.py b/src/pip/_vendor/pep517/colorlog.py
index 69c8a59d3..66310a79a 100644
--- a/src/pip/_vendor/pep517/colorlog.py
+++ b/src/pip/_vendor/pep517/colorlog.py
@@ -73,8 +73,6 @@ class LogFormatter(logging.Formatter):
# right conversion in python 3.
fg_color = (curses.tigetstr("setaf") or
curses.tigetstr("setf") or "")
- if (3, 0) < sys.version_info < (3, 2, 3):
- fg_color = str(fg_color, "ascii")
for levelno, code in self.DEFAULT_COLORS.items():
self._colors[levelno] = str(
diff --git a/src/pip/_vendor/pep517/compat.py b/src/pip/_vendor/pep517/compat.py
deleted file mode 100644
index 730ef5ffa..000000000
--- a/src/pip/_vendor/pep517/compat.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""Python 2/3 compatibility"""
-import io
-import json
-import sys
-
-
-# Handle reading and writing JSON in UTF-8, on Python 3 and 2.
-
-if sys.version_info[0] >= 3:
- # Python 3
- def write_json(obj, path, **kwargs):
- with open(path, 'w', encoding='utf-8') as f:
- json.dump(obj, f, **kwargs)
-
- def read_json(path):
- with open(path, 'r', encoding='utf-8') as f:
- return json.load(f)
-
-else:
- # Python 2
- def write_json(obj, path, **kwargs):
- with open(path, 'wb') as f:
- json.dump(obj, f, encoding='utf-8', **kwargs)
-
- def read_json(path):
- with open(path, 'rb') as f:
- return json.load(f)
-
-
-# FileNotFoundError
-
-try:
- FileNotFoundError = FileNotFoundError
-except NameError:
- FileNotFoundError = IOError
-
-
-if sys.version_info < (3, 6):
- from toml import load as _toml_load # noqa: F401
-
- def toml_load(f):
- w = io.TextIOWrapper(f, encoding="utf8", newline="")
- try:
- return _toml_load(w)
- finally:
- w.detach()
-
- from toml import TomlDecodeError as TOMLDecodeError # noqa: F401
-else:
- from pip._vendor.tomli import load as toml_load # noqa: F401
- from pip._vendor.tomli import TOMLDecodeError # noqa: F401
diff --git a/src/pip/_vendor/pep517/dirtools.py b/src/pip/_vendor/pep517/dirtools.py
index 58c6ca0c5..3eff4d801 100644
--- a/src/pip/_vendor/pep517/dirtools.py
+++ b/src/pip/_vendor/pep517/dirtools.py
@@ -1,33 +1,8 @@
-import os
import io
-import contextlib
-import tempfile
-import shutil
-import errno
+import os
import zipfile
-@contextlib.contextmanager
-def tempdir():
- """Create a temporary directory in a context manager."""
- td = tempfile.mkdtemp()
- try:
- yield td
- finally:
- shutil.rmtree(td)
-
-
-def mkdir_p(*args, **kwargs):
- """Like `mkdir`, but does not raise an exception if the
- directory already exists.
- """
- try:
- return os.mkdir(*args, **kwargs)
- except OSError as exc:
- if exc.errno != errno.EEXIST:
- raise
-
-
def dir_to_zipfile(root):
"""Construct an in-memory zip file for a directory."""
buffer = io.BytesIO()
diff --git a/src/pip/_vendor/pep517/envbuild.py b/src/pip/_vendor/pep517/envbuild.py
index fe8873c64..c0415c4d7 100644
--- a/src/pip/_vendor/pep517/envbuild.py
+++ b/src/pip/_vendor/pep517/envbuild.py
@@ -1,27 +1,26 @@
"""Build wheels/sdists by installing build deps to a temporary environment.
"""
-import io
-import os
import logging
+import os
import shutil
-from subprocess import check_call
import sys
+from subprocess import check_call
from sysconfig import get_paths
from tempfile import mkdtemp
-from .compat import toml_load
-from .wrappers import Pep517HookCaller, LoggerWrapper
+from ._compat import tomllib
+from .wrappers import LoggerWrapper, Pep517HookCaller
log = logging.getLogger(__name__)
def _load_pyproject(source_dir):
- with io.open(
+ with open(
os.path.join(source_dir, 'pyproject.toml'),
'rb',
) as f:
- pyproject_data = toml_load(f)
+ pyproject_data = tomllib.load(f)
buildsys = pyproject_data['build-system']
return (
buildsys['requires'],
@@ -30,7 +29,7 @@ def _load_pyproject(source_dir):
)
-class BuildEnvironment(object):
+class BuildEnvironment:
"""Context manager to install build deps in a simple temporary environment
Based on code I wrote for pip, which is MIT licensed.
diff --git a/src/pip/_vendor/pep517/in_process/__init__.py b/src/pip/_vendor/pep517/in_process/__init__.py
index c932313b3..281a356cf 100644
--- a/src/pip/_vendor/pep517/in_process/__init__.py
+++ b/src/pip/_vendor/pep517/in_process/__init__.py
@@ -3,15 +3,24 @@
The subpackage should stay as empty as possible to avoid shadowing modules that
the backend might import.
"""
-from os.path import dirname, abspath, join as pjoin
from contextlib import contextmanager
+from os.path import abspath, dirname
+from os.path import join as pjoin
try:
import importlib.resources as resources
-
- def _in_proc_script_path():
- return resources.path(__package__, '_in_process.py')
+ try:
+ resources.files
+ except AttributeError:
+ # Python 3.8 compatibility
+ def _in_proc_script_path():
+ return resources.path(__package__, '_in_process.py')
+ else:
+ def _in_proc_script_path():
+ return resources.as_file(
+ resources.files(__package__).joinpath('_in_process.py'))
except ImportError:
+ # Python 3.6 compatibility
@contextmanager
def _in_proc_script_path():
yield pjoin(dirname(abspath(__file__)), '_in_process.py')
diff --git a/src/pip/_vendor/pep517/in_process/_in_process.py b/src/pip/_vendor/pep517/in_process/_in_process.py
index 954a4ab05..ae4cf9e9c 100644
--- a/src/pip/_vendor/pep517/in_process/_in_process.py
+++ b/src/pip/_vendor/pep517/in_process/_in_process.py
@@ -12,41 +12,29 @@ Results:
- control_dir/output.json
- {"return_val": ...}
"""
-from glob import glob
-from importlib import import_module
import json
import os
import os.path
-from os.path import join as pjoin
import re
import shutil
import sys
import traceback
+from glob import glob
+from importlib import import_module
+from os.path import join as pjoin
-# This file is run as a script, and `import compat` is not zip-safe, so we
-# include write_json() and read_json() from compat.py.
-#
-# Handle reading and writing JSON in UTF-8, on Python 3 and 2.
+# This file is run as a script, and `import wrappers` is not zip-safe, so we
+# include write_json() and read_json() from wrappers.py.
-if sys.version_info[0] >= 3:
- # Python 3
- def write_json(obj, path, **kwargs):
- with open(path, 'w', encoding='utf-8') as f:
- json.dump(obj, f, **kwargs)
- def read_json(path):
- with open(path, 'r', encoding='utf-8') as f:
- return json.load(f)
+def write_json(obj, path, **kwargs):
+ with open(path, 'w', encoding='utf-8') as f:
+ json.dump(obj, f, **kwargs)
-else:
- # Python 2
- def write_json(obj, path, **kwargs):
- with open(path, 'wb') as f:
- json.dump(obj, f, encoding='utf-8', **kwargs)
- def read_json(path):
- with open(path, 'rb') as f:
- return json.load(f)
+def read_json(path):
+ with open(path, encoding='utf-8') as f:
+ return json.load(f)
class BackendUnavailable(Exception):
@@ -64,7 +52,7 @@ class BackendInvalid(Exception):
class HookMissing(Exception):
"""Raised if a hook is missing and we are not executing the fallback"""
def __init__(self, hook_name=None):
- super(HookMissing, self).__init__(hook_name)
+ super().__init__(hook_name)
self.hook_name = hook_name
diff --git a/src/pip/_vendor/pep517/meta.py b/src/pip/_vendor/pep517/meta.py
index d525de5c6..4afc3c047 100644
--- a/src/pip/_vendor/pep517/meta.py
+++ b/src/pip/_vendor/pep517/meta.py
@@ -1,10 +1,11 @@
"""Build metadata for a project using PEP 517 hooks.
"""
import argparse
+import functools
import logging
import os
import shutil
-import functools
+import tempfile
try:
import importlib.metadata as imp_meta
@@ -16,10 +17,10 @@ try:
except ImportError:
from zipp import Path
+from .build import compat_system, load_system, validate_system
+from .dirtools import dir_to_zipfile
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller, quiet_subprocess_runner
-from .dirtools import tempdir, mkdir_p, dir_to_zipfile
-from .build import validate_system, load_system, compat_system
log = logging.getLogger(__name__)
@@ -31,7 +32,7 @@ def _prep_meta(hooks, env, dest):
env.pip_install(reqs)
log.info('Installed dynamic build dependencies')
- with tempdir() as td:
+ with tempfile.TemporaryDirectory() as td:
log.info('Trying to build metadata in %s', td)
filename = hooks.prepare_metadata_for_build_wheel(td, {})
source = os.path.join(td, filename)
@@ -41,7 +42,7 @@ def _prep_meta(hooks, env, dest):
def build(source_dir='.', dest=None, system=None):
system = system or load_system(source_dir)
dest = os.path.join(source_dir, dest or 'dist')
- mkdir_p(dest)
+ os.makedirs(dest, exist_ok=True)
validate_system(system)
hooks = Pep517HookCaller(
source_dir, system['build-backend'], system.get('backend-path')
@@ -54,7 +55,7 @@ def build(source_dir='.', dest=None, system=None):
def build_as_zip(builder=build):
- with tempdir() as out_dir:
+ with tempfile.TemporaryDirectory() as out_dir:
builder(dest=out_dir)
return dir_to_zipfile(out_dir)
diff --git a/src/pip/_vendor/pep517/wrappers.py b/src/pip/_vendor/pep517/wrappers.py
index e031ed708..987a62aaa 100644
--- a/src/pip/_vendor/pep517/wrappers.py
+++ b/src/pip/_vendor/pep517/wrappers.py
@@ -1,13 +1,13 @@
-import threading
-from contextlib import contextmanager
+import json
import os
-from os.path import abspath, join as pjoin
-import shutil
-from subprocess import check_call, check_output, STDOUT
import sys
-from tempfile import mkdtemp
+import tempfile
+import threading
+from contextlib import contextmanager
+from os.path import abspath
+from os.path import join as pjoin
+from subprocess import STDOUT, check_call, check_output
-from . import compat
from .in_process import _in_proc_script_path
__all__ = [
@@ -21,13 +21,14 @@ __all__ = [
]
-@contextmanager
-def tempdir():
- td = mkdtemp()
- try:
- yield td
- finally:
- shutil.rmtree(td)
+def write_json(obj, path, **kwargs):
+ with open(path, 'w', encoding='utf-8') as f:
+ json.dump(obj, f, **kwargs)
+
+
+def read_json(path):
+ with open(path, encoding='utf-8') as f:
+ return json.load(f)
class BackendUnavailable(Exception):
@@ -47,7 +48,7 @@ class BackendInvalid(Exception):
class HookMissing(Exception):
"""Will be raised on missing hooks."""
def __init__(self, hook_name):
- super(HookMissing, self).__init__(hook_name)
+ super().__init__(hook_name)
self.hook_name = hook_name
@@ -99,7 +100,7 @@ def norm_and_check(source_tree, requested):
return abs_requested
-class Pep517HookCaller(object):
+class Pep517HookCaller:
"""A wrapper around a source directory to be built with a PEP 517 backend.
:param source_dir: The path to the source directory, containing
@@ -292,29 +293,15 @@ class Pep517HookCaller(object):
})
def _call_hook(self, hook_name, kwargs):
- # On Python 2, pytoml returns Unicode values (which is correct) but the
- # environment passed to check_call needs to contain string values. We
- # convert here by encoding using ASCII (the backend can only contain
- # letters, digits and _, . and : characters, and will be used as a
- # Python identifier, so non-ASCII content is wrong on Python 2 in
- # any case).
- # For backend_path, we use sys.getfilesystemencoding.
- if sys.version_info[0] == 2:
- build_backend = self.build_backend.encode('ASCII')
- else:
- build_backend = self.build_backend
- extra_environ = {'PEP517_BUILD_BACKEND': build_backend}
+ extra_environ = {'PEP517_BUILD_BACKEND': self.build_backend}
if self.backend_path:
backend_path = os.pathsep.join(self.backend_path)
- if sys.version_info[0] == 2:
- backend_path = backend_path.encode(sys.getfilesystemencoding())
extra_environ['PEP517_BACKEND_PATH'] = backend_path
- with tempdir() as td:
+ with tempfile.TemporaryDirectory() as td:
hook_input = {'kwargs': kwargs}
- compat.write_json(hook_input, pjoin(td, 'input.json'),
- indent=2)
+ write_json(hook_input, pjoin(td, 'input.json'), indent=2)
# Run the hook in a subprocess
with _in_proc_script_path() as script:
@@ -325,7 +312,7 @@ class Pep517HookCaller(object):
extra_environ=extra_environ
)
- data = compat.read_json(pjoin(td, 'output.json'))
+ data = read_json(pjoin(td, 'output.json'))
if data.get('unsupported'):
raise UnsupportedOperation(data.get('traceback', ''))
if data.get('no_backend'):
diff --git a/src/pip/_vendor/vendor.txt b/src/pip/_vendor/vendor.txt
index 4053e5ab8..f9018960e 100644
--- a/src/pip/_vendor/vendor.txt
+++ b/src/pip/_vendor/vendor.txt
@@ -4,7 +4,7 @@ distlib==0.3.6
distro==1.7.0
msgpack==1.0.4
packaging==21.3
-pep517==0.12.0
+pep517==0.13.0
platformdirs==2.5.2
pyparsing==3.0.9
requests==2.28.1