[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,7 +1,6 @@
"""Wheels support."""
from __future__ import annotations
from distutils.util import get_platform
from distutils import log
import email
import itertools
import os
@ -11,17 +10,20 @@ import zipfile
import pkg_resources
import setuptools
from distutils import log
from distutils.util import get_platform
from pkg_resources import parse_version
from setuptools.command.egg_info import write_requirements
from setuptools.extern.packaging.tags import sys_tags
from setuptools.extern.packaging.utils import canonicalize_name
from setuptools.command.egg_info import write_requirements
WHEEL_NAME = re.compile(
r"""^(?P<project_name>.+?)-(?P<version>\d.*?)
((-(?P<build>\d.*?))?-(?P<py_version>.+?)-(?P<abi>.+?)-(?P<platform>.+?)
)\.whl$""",
re.VERBOSE).match
re.VERBOSE,
).match
NAMESPACE_PACKAGE_INIT = \
"__import__('pkg_resources').declare_namespace(__name__)\n"
@ -69,8 +71,9 @@ class Wheel:
def is_compatible(self):
'''Is the wheel is compatible with the current platform?'''
supported_tags = set(
(t.interpreter, t.abi, t.platform) for t in sys_tags())
supported_tags = {
(t.interpreter, t.abi, t.platform) for t in sys_tags()
}
return next((True for t in self.tags() if t in supported_tags), False)
def egg_name(self):
@ -83,11 +86,14 @@ class Wheel:
# find the correct name of the .dist-info dir in the wheel file
for member in zf.namelist():
dirname = posixpath.dirname(member)
if (dirname.endswith('.dist-info') and
canonicalize_name(dirname).startswith(
canonicalize_name(self.project_name))):
if (
dirname.endswith('.dist-info') and
canonicalize_name(dirname).startswith(
canonicalize_name(self.project_name),
)
):
return dirname
raise ValueError("unsupported wheel format. .dist-info not found")
raise ValueError('unsupported wheel format. .dist-info not found')
def install_as_egg(self, destination_eggdir):
'''Install wheel as an egg directory.'''
@ -95,7 +101,7 @@ class Wheel:
self._install_as_egg(destination_eggdir, zf)
def _install_as_egg(self, destination_eggdir, zf):
dist_basename = '%s-%s' % (self.project_name, self.version)
dist_basename = '{}-{}'.format(self.project_name, self.version)
dist_info = self.get_dist_info(zf)
dist_data = '%s.data' % dist_basename
egg_info = os.path.join(destination_eggdir, 'EGG-INFO')
@ -119,7 +125,8 @@ class Wheel:
)
if not wheel_v1:
raise ValueError(
'unsupported wheel format version: %s' % wheel_version)
'unsupported wheel format version: %s' % wheel_version,
)
# Extract to target directory.
os.mkdir(destination_eggdir)
zf.extractall(destination_eggdir)
@ -175,7 +182,8 @@ class Wheel:
dist_data_scripts = os.path.join(dist_data, 'scripts')
if os.path.exists(dist_data_scripts):
egg_info_scripts = os.path.join(
destination_eggdir, 'EGG-INFO', 'scripts')
destination_eggdir, 'EGG-INFO', 'scripts',
)
os.mkdir(egg_info_scripts)
for entry in os.listdir(dist_data_scripts):
# Remove bytecode, as it's not properly handled
@ -188,10 +196,12 @@ class Wheel:
os.path.join(egg_info_scripts, entry),
)
os.rmdir(dist_data_scripts)
for subdir in filter(os.path.exists, (
os.path.join(dist_data, d)
for d in ('data', 'headers', 'purelib', 'platlib')
)):
for subdir in filter(
os.path.exists, (
os.path.join(dist_data, d)
for d in ('data', 'headers', 'purelib', 'platlib')
),
):
unpack(subdir, destination_eggdir)
if os.path.exists(dist_data):
os.rmdir(dist_data)
@ -199,7 +209,8 @@ class Wheel:
@staticmethod
def _fix_namespace_packages(egg_info, destination_eggdir):
namespace_packages = os.path.join(
egg_info, 'namespace_packages.txt')
egg_info, 'namespace_packages.txt',
)
if os.path.exists(namespace_packages):
with open(namespace_packages) as fp:
namespace_packages = fp.read().split()