diff options
| author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-22 16:30:41 +0200 |
|---|---|---|
| committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-22 16:30:41 +0200 |
| commit | fa4de8bd7dce1611be217ade3aade0bd8c76ca7a (patch) | |
| tree | 621e55e88d3861bea1dc2c42ea0eae87b5930b89 | |
| parent | 45af6b0f420b7a90af417b3846b0bdfe1c6a70d4 (diff) | |
| download | wheel-git-fa4de8bd7dce1611be217ade3aade0bd8c76ca7a.tar.gz | |
Upgraded to py3.7+ syntax
| -rw-r--r-- | src/wheel/bdist_wheel.py | 18 | ||||
| -rw-r--r-- | src/wheel/cli/__init__.py | 2 | ||||
| -rwxr-xr-x | src/wheel/cli/convert.py | 10 | ||||
| -rw-r--r-- | src/wheel/cli/pack.py | 8 | ||||
| -rw-r--r-- | src/wheel/cli/unpack.py | 2 | ||||
| -rw-r--r-- | src/wheel/macosx_libfile.py | 6 | ||||
| -rw-r--r-- | src/wheel/pkginfo.py | 2 | ||||
| -rw-r--r-- | src/wheel/wheelfile.py | 12 | ||||
| -rw-r--r-- | tests/conftest.py | 7 | ||||
| -rw-r--r-- | tests/test_bdist_wheel.py | 4 | ||||
| -rw-r--r-- | tests/test_tagopt.py | 4 | ||||
| -rw-r--r-- | tests/test_wheelfile.py | 12 | ||||
| -rw-r--r-- | tests/testdata/abi3extension.dist/setup.py | 2 | ||||
| -rw-r--r-- | tests/testdata/complex-dist/setup.py | 4 | ||||
| -rw-r--r-- | tests/testdata/extension.dist/setup.py | 2 | ||||
| -rw-r--r-- | tests/testdata/headers.dist/setup.py | 2 | ||||
| -rw-r--r-- | tests/testdata/simple.dist/setup.py | 2 | ||||
| -rw-r--r-- | tests/testdata/unicode.dist/setup.py | 2 |
18 files changed, 49 insertions, 52 deletions
diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index 84a3fcf..ae8da2a 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -38,7 +38,7 @@ PY_LIMITED_API_PATTERN = r'cp3\d' def python_tag(): - return 'py{}'.format(sys.version_info[0]) + return f'py{sys.version_info[0]}' def get_platform(archive_root): @@ -59,7 +59,7 @@ def get_flag(var, fallback, expected=True, warn=True): val = get_config_var(var) if val is None: if warn: - warnings.warn("Config variable '{0}' is unset, Python ABI tag may " + warnings.warn("Config variable '{}' is unset, Python ABI tag may " "be incorrect".format(var), RuntimeWarning, 2) return fallback return val == expected @@ -85,7 +85,7 @@ def get_abi_tag(): and sys.version_info < (3, 8): m = 'm' - abi = '%s%s%s%s%s' % (impl, tags.interpreter_version(), d, m, u) + abi = f'{impl}{tags.interpreter_version()}{d}{m}{u}' elif soabi and soabi.startswith('cpython-'): abi = 'cp' + soabi.split('-')[1] elif soabi and soabi.startswith('pypy-'): @@ -197,7 +197,7 @@ class bdist_wheel(Command): try: self.compression = self.supported_compressions[self.compression] except KeyError: - raise ValueError('Unsupported compression: {}'.format(self.compression)) + raise ValueError(f'Unsupported compression: {self.compression}') need_options = ('dist_dir', 'plat_name', 'skip_build') @@ -276,7 +276,7 @@ class bdist_wheel(Command): # issue gh-374: allow overriding plat_name supported_tags = [(t.interpreter, t.abi, plat_name) for t in tags.sys_tags()] - assert tag in supported_tags, "would build wheel with unsupported tag {}".format(tag) + assert tag in supported_tags, f"would build wheel with unsupported tag {tag}" return tag def run(self): @@ -327,7 +327,7 @@ class bdist_wheel(Command): self.run_command('install') impl_tag, abi_tag, plat_tag = self.get_tag() - archive_basename = "{}-{}-{}-{}".format(self.wheel_dist_name, impl_tag, abi_tag, plat_tag) + archive_basename = f"{self.wheel_dist_name}-{impl_tag}-{abi_tag}-{plat_tag}" if not self.relative: archive_root = self.bdist_dir else: @@ -441,10 +441,10 @@ class bdist_wheel(Command): import glob pat = os.path.join(os.path.dirname(egginfo_path), '*.egg-info') possible = glob.glob(pat) - err = "Egg metadata expected at %s but not found" % (egginfo_path,) + err = f"Egg metadata expected at {egginfo_path} but not found" if possible: alt = os.path.basename(possible[0]) - err += " (%s found - possible misnamed archive file?)" % (alt,) + err += f" ({alt} found - possible misnamed archive file?)" raise ValueError(err) @@ -466,7 +466,7 @@ class bdist_wheel(Command): # delete dependency_links if it is only whitespace dependency_links_path = os.path.join(distinfo_path, 'dependency_links.txt') - with open(dependency_links_path, 'r') as dependency_links_file: + with open(dependency_links_path) as dependency_links_file: dependency_links = dependency_links_file.read().strip() if not dependency_links: adios(dependency_links_path) diff --git a/src/wheel/cli/__init__.py b/src/wheel/cli/__init__.py index d41dcfd..c8a3b35 100644 --- a/src/wheel/cli/__init__.py +++ b/src/wheel/cli/__init__.py @@ -11,7 +11,7 @@ def require_pkgresources(name): try: import pkg_resources # noqa: F401 except ImportError: - raise RuntimeError("'{0}' needs pkg_resources (part of setuptools).".format(name)) + raise RuntimeError(f"'{name}' needs pkg_resources (part of setuptools).") class WheelError(Exception): diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py index b502daf..5c76d5f 100755 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -37,7 +37,7 @@ def egg2wheel(egg_path, dest_dir): filename = os.path.basename(egg_path) match = egg_info_re.match(filename) if not match: - raise WheelError('Invalid egg file name: {}'.format(filename)) + raise WheelError(f'Invalid egg file name: {filename}') egg_info = match.groupdict() dir = tempfile.mkdtemp(suffix="_e2w") @@ -124,13 +124,13 @@ def parse_wininst_info(wininfo_name, egginfo_name): if egginfo_name: egginfo = egg_info_re.search(egginfo_name) if not egginfo: - raise ValueError("Egg info filename %s is not valid" % (egginfo_name,)) + raise ValueError(f"Egg info filename {egginfo_name} is not valid") # Parse the wininst filename # 1. Distribution name (up to the first '-') w_name, sep, rest = wininfo_name.partition('-') if not sep: - raise ValueError("Installer filename %s is not valid" % (wininfo_name,)) + raise ValueError(f"Installer filename {wininfo_name} is not valid") # Strip '.exe' rest = rest[:-4] @@ -149,7 +149,7 @@ def parse_wininst_info(wininfo_name, egginfo_name): # 3. Version and architecture w_ver, sep, w_arch = rest.rpartition('.') if not sep: - raise ValueError("Installer filename %s is not valid" % (wininfo_name,)) + raise ValueError(f"Installer filename {wininfo_name} is not valid") if egginfo: w_name = egginfo.group('name') @@ -260,7 +260,7 @@ def convert(files, dest_dir, verbose): conv = wininst2wheel if verbose: - print("{}... ".format(installer), flush=True) + print(f"{installer}... ", flush=True) conv(installer, dest_dir) if verbose: diff --git a/src/wheel/cli/pack.py b/src/wheel/cli/pack.py index 04d858d..094eb67 100644 --- a/src/wheel/cli/pack.py +++ b/src/wheel/cli/pack.py @@ -21,9 +21,9 @@ def pack(directory, dest_dir, build_number): dist_info_dirs = [fn for fn in os.listdir(directory) if os.path.isdir(os.path.join(directory, fn)) and DIST_INFO_RE.match(fn)] if len(dist_info_dirs) > 1: - raise WheelError('Multiple .dist-info directories found in {}'.format(directory)) + raise WheelError(f'Multiple .dist-info directories found in {directory}') elif not dist_info_dirs: - raise WheelError('No .dist-info directories found in {}'.format(directory)) + raise WheelError(f'No .dist-info directories found in {directory}') # Determine the target wheel filename dist_info_dir = dist_info_dirs[0] @@ -70,9 +70,9 @@ def pack(directory, dest_dir, build_number): tagline = '-'.join(['.'.join(impls), '.'.join(abivers), '.'.join(platforms)]) # Repack the wheel - wheel_path = os.path.join(dest_dir, '{}-{}.whl'.format(name_version, tagline)) + wheel_path = os.path.join(dest_dir, f'{name_version}-{tagline}.whl') with WheelFile(wheel_path, 'w') as wf: - print("Repacking wheel as {}...".format(wheel_path), end='', flush=True) + print(f"Repacking wheel as {wheel_path}...", end='', flush=True) wf.write_files(directory) print('OK') diff --git a/src/wheel/cli/unpack.py b/src/wheel/cli/unpack.py index 8aa8180..3f3963c 100644 --- a/src/wheel/cli/unpack.py +++ b/src/wheel/cli/unpack.py @@ -15,7 +15,7 @@ def unpack(path, dest='.'): with WheelFile(path) as wf: namever = wf.parsed_filename.group('namever') destination = os.path.join(dest, namever) - print("Unpacking to: {}...".format(destination), end='', flush=True) + print(f"Unpacking to: {destination}...", end='', flush=True) wf.extractall(destination) print('OK') diff --git a/src/wheel/macosx_libfile.py b/src/wheel/macosx_libfile.py index 39006fb..29b0395 100644 --- a/src/wheel/macosx_libfile.py +++ b/src/wheel/macosx_libfile.py @@ -363,14 +363,14 @@ def calculate_macosx_platform_tag(archive_root, platform_tag): Example platform tag `macosx-10.14-x86_64` """ prefix, base_version, suffix = platform_tag.split('-') - base_version = tuple([int(x) for x in base_version.split(".")]) + base_version = tuple(int(x) for x in base_version.split(".")) base_version = base_version[:2] if base_version[0] > 10: base_version = (base_version[0], 0) assert len(base_version) == 2 if "MACOSX_DEPLOYMENT_TARGET" in os.environ: - deploy_target = tuple([int(x) for x in os.environ[ - "MACOSX_DEPLOYMENT_TARGET"].split(".")]) + deploy_target = tuple(int(x) for x in os.environ[ + "MACOSX_DEPLOYMENT_TARGET"].split(".")) deploy_target = deploy_target[:2] if deploy_target[0] > 10: deploy_target = (deploy_target[0], 0) diff --git a/src/wheel/pkginfo.py b/src/wheel/pkginfo.py index 0470a1d..bed016c 100644 --- a/src/wheel/pkginfo.py +++ b/src/wheel/pkginfo.py @@ -12,7 +12,7 @@ def read_pkg_info_bytes(bytestr): def read_pkg_info(path): - with open(path, "r", encoding="ascii", errors="surrogateescape") as headers: + with open(path, encoding="ascii", errors="surrogateescape") as headers: message = Parser().parse(headers) return message diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 2295306..83f1611 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -38,7 +38,7 @@ class WheelFile(ZipFile): basename = os.path.basename(file) self.parsed_filename = WHEEL_INFO_RE.match(basename) if not basename.endswith('.whl') or self.parsed_filename is None: - raise WheelError("Bad wheel filename {!r}".format(basename)) + raise WheelError(f"Bad wheel filename {basename!r}") ZipFile.__init__(self, file, mode, compression=compression, allowZip64=True) @@ -56,7 +56,7 @@ class WheelFile(ZipFile): try: record = self.open(self.record_path) except KeyError: - raise WheelError('Missing {} file'.format(self.record_path)) + raise WheelError(f'Missing {self.record_path} file') with record: for line in csv.reader(TextIOWrapper(record, newline='', encoding='utf-8')): @@ -64,11 +64,11 @@ class WheelFile(ZipFile): if not hash_sum: continue - algorithm, hash_sum = hash_sum.split(u'=') + algorithm, hash_sum = hash_sum.split('=') try: hashlib.new(algorithm) except ValueError: - raise WheelError('Unsupported hash algorithm: {}'.format(algorithm)) + raise WheelError(f'Unsupported hash algorithm: {algorithm}') if algorithm.lower() in {'md5', 'sha1'}: raise WheelError( @@ -88,12 +88,12 @@ class WheelFile(ZipFile): running_hash.update(newdata) if eof and running_hash.digest() != expected_hash: - raise WheelError("Hash mismatch for file '{}'".format(native(ef_name))) + raise WheelError(f"Hash mismatch for file '{native(ef_name)}'") ef_name = as_unicode(name_or_info.filename if isinstance(name_or_info, ZipInfo) else name_or_info) if mode == 'r' and not ef_name.endswith('/') and ef_name not in self._file_hashes: - raise WheelError("No hash found for file '{}'".format(native(ef_name))) + raise WheelError(f"No hash found for file '{native(ef_name)}'") ef = ZipFile.open(self, name_or_info, mode, pwd) if mode == 'r' and not ef_name.endswith('/'): diff --git a/tests/conftest.py b/tests/conftest.py index d9821b8..153954c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,11 +12,8 @@ import pytest @pytest.fixture(scope='session') def wheels_and_eggs(tmpdir_factory): """Build wheels and eggs from test distributions.""" - test_distributions = "complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist" - if sys.version_info >= (3, 6): - # Only Python 3.6+ can handle packaging unicode file names reliably - # across different platforms - test_distributions += ("unicode.dist",) + test_distributions = ("complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist", + "unicode.dist") if sys.platform != 'win32': # ABI3 extensions don't really work on Windows diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index a0de591..6c47c47 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -57,7 +57,7 @@ def test_unicode_record(wheel_paths): with ZipFile(path) as zf: record = zf.read('unicode.dist-0.1.dist-info/RECORD') - assert u'åäö_日本語.py'.encode('utf-8') in record + assert 'åäö_日本語.py'.encode() in record def test_licenses_default(dummy_dist, monkeypatch, tmpdir): @@ -138,7 +138,7 @@ def test_build_from_readonly_tree(dummy_dist, monkeypatch, tmpdir): def test_compression(dummy_dist, monkeypatch, tmpdir, option, compress_type): monkeypatch.chdir(dummy_dist) subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel', '-b', str(tmpdir), - '--universal', '--compression={}'.format(option)]) + '--universal', f'--compression={option}']) with WheelFile('dist/dummy_dist-1.0-py2.py3-none-any.whl') as wf: filenames = set(wf.namelist()) assert 'dummy_dist-1.0.dist-info/RECORD' in filenames diff --git a/tests/test_tagopt.py b/tests/test_tagopt.py index d40b078..dd0c7a2 100644 --- a/tests/test_tagopt.py +++ b/tests/test_tagopt.py @@ -56,7 +56,7 @@ def test_default_tag(temp_pkg): assert dist_dir.check(dir=1) wheels = dist_dir.listdir() assert len(wheels) == 1 - assert wheels[0].basename == 'Test-1.0-py%s-none-any.whl' % (sys.version_info[0],) + assert wheels[0].basename == f'Test-1.0-py{sys.version_info[0]}-none-any.whl' assert wheels[0].ext == '.whl' @@ -67,7 +67,7 @@ def test_build_number(temp_pkg): assert dist_dir.check(dir=1) wheels = dist_dir.listdir() assert len(wheels) == 1 - assert (wheels[0].basename == 'Test-1.0-1-py%s-none-any.whl' % (sys.version_info[0],)) + assert (wheels[0].basename == f'Test-1.0-1-py{sys.version_info[0]}-none-any.whl') assert wheels[0].ext == '.whl' diff --git a/tests/test_wheelfile.py b/tests/test_wheelfile.py index 0e060b1..f6e6125 100644 --- a/tests/test_wheelfile.py +++ b/tests/test_wheelfile.py @@ -29,7 +29,7 @@ def test_wheelfile_re(tmpdir): ]) def test_bad_wheel_filename(filename): exc = pytest.raises(WheelError, WheelFile, filename) - exc.match('^Bad wheel filename {!r}$'.format(filename)) + exc.match(f'^Bad wheel filename {filename!r}$') def test_missing_record(wheel_path): @@ -56,14 +56,14 @@ def test_unsupported_hash_algorithm(wheel_path): ('sha1', 'QjCnGu5Qucb6-vir1a6BVptvOA4') ], ids=['md5', 'sha1']) def test_weak_hash_algorithm(wheel_path, algorithm, digest): - hash_string = '{}={}'.format(algorithm, digest) + hash_string = f'{algorithm}={digest}' with ZipFile(wheel_path, 'w') as zf: zf.writestr(native('hello/héllö.py'), as_bytes('print("Héllö, w0rld!")\n')) zf.writestr('test-1.0.dist-info/RECORD', - as_bytes('hello/héllö.py,{},25'.format(hash_string))) + as_bytes(f'hello/héllö.py,{hash_string},25')) exc = pytest.raises(WheelError, WheelFile, wheel_path) - exc.match(r"^Weak hash algorithm \({}\) is not permitted by PEP 427$".format(algorithm)) + exc.match(fr"^Weak hash algorithm \({algorithm}\) is not permitted by PEP 427$") @pytest.mark.parametrize('algorithm, digest', [ @@ -73,11 +73,11 @@ def test_weak_hash_algorithm(wheel_path, algorithm, digest): 'iLNpWVxTwuDWqBQ') ], ids=['sha256', 'sha384', 'sha512']) def test_testzip(wheel_path, algorithm, digest): - hash_string = '{}={}'.format(algorithm, digest) + hash_string = f'{algorithm}={digest}' with ZipFile(wheel_path, 'w') as zf: zf.writestr(native('hello/héllö.py'), as_bytes('print("Héllö, world!")\n')) zf.writestr('test-1.0.dist-info/RECORD', - as_bytes('hello/héllö.py,{},25'.format(hash_string))) + as_bytes(f'hello/héllö.py,{hash_string},25')) with WheelFile(wheel_path) as wf: wf.testzip() diff --git a/tests/testdata/abi3extension.dist/setup.py b/tests/testdata/abi3extension.dist/setup.py index 3ffd839..e9a08df 100644 --- a/tests/testdata/abi3extension.dist/setup.py +++ b/tests/testdata/abi3extension.dist/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, Extension setup(name='extension.dist', version='0.1', - description=u'A testing distribution \N{SNOWMAN}', + description='A testing distribution \N{SNOWMAN}', ext_modules=[ Extension(name='extension', sources=['extension.c'], diff --git a/tests/testdata/complex-dist/setup.py b/tests/testdata/complex-dist/setup.py index 41cfb04..632ae3f 100644 --- a/tests/testdata/complex-dist/setup.py +++ b/tests/testdata/complex-dist/setup.py @@ -2,8 +2,8 @@ from setuptools import setup setup(name='complex-dist', version='0.1', - description=u'Another testing distribution \N{SNOWMAN}', - long_description=u'Another testing distribution \N{SNOWMAN}', + description='Another testing distribution \N{SNOWMAN}', + long_description='Another testing distribution \N{SNOWMAN}', author="Illustrious Author", author_email="illustrious@example.org", url="http://example.org/exemplary", diff --git a/tests/testdata/extension.dist/setup.py b/tests/testdata/extension.dist/setup.py index ae22525..c9bf948 100644 --- a/tests/testdata/extension.dist/setup.py +++ b/tests/testdata/extension.dist/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, Extension setup(name='extension.dist', version='0.1', - description=u'A testing distribution \N{SNOWMAN}', + description='A testing distribution \N{SNOWMAN}', ext_modules=[ Extension(name='extension', sources=['extension.c']) diff --git a/tests/testdata/headers.dist/setup.py b/tests/testdata/headers.dist/setup.py index 67cada3..2c7d7ea 100644 --- a/tests/testdata/headers.dist/setup.py +++ b/tests/testdata/headers.dist/setup.py @@ -2,6 +2,6 @@ from setuptools import setup setup(name='headers.dist', version='0.1', - description=u'A distribution with headers', + description='A distribution with headers', headers=['header.h'] ) diff --git a/tests/testdata/simple.dist/setup.py b/tests/testdata/simple.dist/setup.py index d2aaac9..81b26cd 100644 --- a/tests/testdata/simple.dist/setup.py +++ b/tests/testdata/simple.dist/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup(name='simple.dist', version='0.1', - description=u'A testing distribution \N{SNOWMAN}', + description='A testing distribution \N{SNOWMAN}', packages=['simpledist'], extras_require={'voting': ['beaglevote']}, ) diff --git a/tests/testdata/unicode.dist/setup.py b/tests/testdata/unicode.dist/setup.py index 3382b53..221088e 100644 --- a/tests/testdata/unicode.dist/setup.py +++ b/tests/testdata/unicode.dist/setup.py @@ -2,6 +2,6 @@ from setuptools import setup setup(name='unicode.dist', version='0.1', - description=u'A testing distribution \N{SNOWMAN}', + description='A testing distribution \N{SNOWMAN}', packages=['unicodedist'] ) |
