diff --git a/docs/conf.py b/docs/conf.py index d38fad28a0..0685f7650b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,86 +11,86 @@ # Link dates and other references in the changelog extensions += ['rst.linker'] link_files = { - '../NEWS.rst': dict( - using=dict( - BB='https://bitbucket.org', - GH='https://github.com', - ), - replace=[ - dict( - pattern=r'(Issue #|\B#)(?P\d+)', - url='{package_url}/issues/{issue}', - ), - dict( - pattern=r'(?m:^((?Pv?\d+(\.\d+){1,2}))\n[-=]+\n)', - with_scm='{text}\n{rev[timestamp]:%d %b %Y}\n', - ), - dict( - pattern=r'PEP[- ](?P\d+)', - url='https://peps.python.org/pep-{pep_number:0>4}/', - ), - dict( - pattern=r'(?\d+)', - url='{package_url}/pull/{pull}', - ), - dict( - pattern=r'BB Pull Request ?#(?P\d+)', - url='{BB}/pypa/setuptools/pull-request/{bb_pull_request}', - ), - dict( - pattern=r'Distribute #(?P\d+)', - url='{BB}/tarek/distribute/issue/{distribute}', - ), - dict( - pattern=r'Buildout #(?P\d+)', - url='{GH}/buildout/buildout/issues/{buildout}', - ), - dict( - pattern=r'Old Setuptools #(?P\d+)', - url='https://bugs.python.org/setuptools/issue{old_setuptools}', - ), - dict( - pattern=r'Jython #(?P\d+)', - url='https://bugs.jython.org/issue{jython}', - ), - dict( - pattern=r'(Python #|bpo-)(?P\d+)', - url='https://bugs.python.org/issue{python}', - ), - dict( - pattern=r'\bpython/cpython#(?P\d+)', - url='{GH}/python/cpython/issues/{cpython}', - ), - dict( - pattern=r'Interop #(?P\d+)', - url='{GH}/pypa/interoperability-peps/issues/{interop}', - ), - dict( - pattern=r'Pip #(?P\d+)', - url='{GH}/pypa/pip/issues/{pip}', - ), - dict( - pattern=r'Packaging #(?P\d+)', - url='{GH}/pypa/packaging/issues/{packaging}', - ), - dict( - pattern=r'[Pp]ackaging (?P\d+(\.\d+)+)', - url='{GH}/pypa/packaging/blob/{packaging_ver}/CHANGELOG.rst', - ), - dict( - pattern=r'setuptools_svn #(?P\d+)', - url='{GH}/jaraco/setuptools_svn/issues/{setuptools_svn}', - ), - dict( - pattern=r'pypa/(?P[\-\.\w]+)#(?P\d+)', - url='{GH}/pypa/{issue_repo}/issues/{issue_number}', - ), - dict( - pattern=r'pypa/(?P[\-\.\w]+)@(?P[\da-f]+)', - url='{GH}/pypa/{commit_repo}/commit/{commit_number}', - ), + '../NEWS.rst': { + 'using': { + 'BB': 'https://bitbucket.org', + 'GH': 'https://github.com', + }, + 'replace': [ + { + 'pattern': r'(Issue #|\B#)(?P\d+)', + 'url': '{package_url}/issues/{issue}', + }, + { + 'pattern': r'(?m:^((?Pv?\d+(\.\d+){1,2}))\n[-=]+\n)', + 'with_scm': '{text}\n{rev[timestamp]:%d %b %Y}\n', + }, + { + 'pattern': r'PEP[- ](?P\d+)', + 'url': 'https://peps.python.org/pep-{pep_number:0>4}/', + }, + { + 'pattern': r'(?\d+)', + 'url': '{package_url}/pull/{pull}', + }, + { + 'pattern': r'BB Pull Request ?#(?P\d+)', + 'url': '{BB}/pypa/setuptools/pull-request/{bb_pull_request}', + }, + { + 'pattern': r'Distribute #(?P\d+)', + 'url': '{BB}/tarek/distribute/issue/{distribute}', + }, + { + 'pattern': r'Buildout #(?P\d+)', + 'url': '{GH}/buildout/buildout/issues/{buildout}', + }, + { + 'pattern': r'Old Setuptools #(?P\d+)', + 'url': 'https://bugs.python.org/setuptools/issue{old_setuptools}', + }, + { + 'pattern': r'Jython #(?P\d+)', + 'url': 'https://bugs.jython.org/issue{jython}', + }, + { + 'pattern': r'(Python #|bpo-)(?P\d+)', + 'url': 'https://bugs.python.org/issue{python}', + }, + { + 'pattern': r'\bpython/cpython#(?P\d+)', + 'url': '{GH}/python/cpython/issues/{cpython}', + }, + { + 'pattern': r'Interop #(?P\d+)', + 'url': '{GH}/pypa/interoperability-peps/issues/{interop}', + }, + { + 'pattern': r'Pip #(?P\d+)', + 'url': '{GH}/pypa/pip/issues/{pip}', + }, + { + 'pattern': r'Packaging #(?P\d+)', + 'url': '{GH}/pypa/packaging/issues/{packaging}', + }, + { + 'pattern': r'[Pp]ackaging (?P\d+(\.\d+)+)', + 'url': '{GH}/pypa/packaging/blob/{packaging_ver}/CHANGELOG.rst', + }, + { + 'pattern': r'setuptools_svn #(?P\d+)', + 'url': '{GH}/jaraco/setuptools_svn/issues/{setuptools_svn}', + }, + { + 'pattern': r'pypa/(?P[\-\.\w]+)#(?P\d+)', + 'url': '{GH}/pypa/{issue_repo}/issues/{issue_number}', + }, + { + 'pattern': r'pypa/(?P[\-\.\w]+)@(?P[\da-f]+)', + 'url': '{GH}/pypa/{commit_repo}/commit/{commit_number}', + }, ], - ), + }, } # Be strict about any broken references diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 8a2fbfa412..74c7258e91 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -128,7 +128,9 @@ class _ZipLoaderModule(Protocol): __loader__: zipimport.zipimporter -_PEP440_FALLBACK = re.compile(r"^v?(?P(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I) +_PEP440_FALLBACK = re.compile( + r"^v?(?P(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.IGNORECASE +) class PEP440Warning(RuntimeWarning): @@ -3177,7 +3179,7 @@ def __getattr__(self, attr: str): def __dir__(self): return list( set(super().__dir__()) - | set(attr for attr in self._provider.__dir__() if not attr.startswith('_')) + | {attr for attr in self._provider.__dir__() if not attr.startswith('_')} ) @classmethod diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index cfc9b16c0f..18b19bfcd8 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -348,7 +348,7 @@ class Environment(str): env = Environment(tmpdir) tmpdir.chmod(stat.S_IRWXU) subs = 'home', 'lib', 'scripts', 'data', 'egg-base' - env.paths = dict((dirname, str(tmpdir / dirname)) for dirname in subs) + env.paths = {dirname: str(tmpdir / dirname) for dirname in subs} list(map(os.mkdir, env.paths.values())) return env @@ -358,7 +358,7 @@ def create_foo_pkg(self, env, version): as version. """ ld = "This package has unicode metadata! ❄" - attrs = dict(name='foo', version=version, long_description=ld) + attrs = {"name": 'foo', "version": version, "long_description": ld} dist = distutils.dist.Distribution(attrs) iei_cmd = distutils.command.install_egg_info.install_egg_info(dist) iei_cmd.initialize_options() diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 70436c0881..05c9ea86ed 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -405,7 +405,7 @@ def test_resolve_conflicts_with_prior(self): ws.resolve(parse_requirements("Foo\nBar\n")) msg = "Baz 1.0 is installed but Baz==2.0 is required by " - msg += repr(set(['Bar'])) + msg += repr({'Bar'}) assert vc.value.report() == msg @@ -481,13 +481,13 @@ def checkSubMap(self, m): assert sorted(m.get(key).attrs) == sorted(ep.attrs) assert sorted(m.get(key).extras) == sorted(ep.extras) - submap_expect = dict( - feature1=EntryPoint('feature1', 'somemodule', ['somefunction']), - feature2=EntryPoint( + submap_expect = { + "feature1": EntryPoint('feature1', 'somemodule', ['somefunction']), + "feature2": EntryPoint( 'feature2', 'another.module', ['SomeClass'], ['extra1', 'extra2'] ), - feature3=EntryPoint('feature3', 'this.module', extras=['something']), - ) + "feature3": EntryPoint('feature3', 'this.module', extras=['something']), + } submap_str = """ # define features for blah blah feature1 = somemodule:somefunction @@ -561,8 +561,8 @@ def testOptionsAndHashing(self): r1 = Requirement.parse("Twisted[foo,bar]>=1.2") r2 = Requirement.parse("Twisted[bar,FOO]>=1.2") assert r1 == r2 - assert set(r1.extras) == set(("foo", "bar")) - assert set(r2.extras) == set(("foo", "bar")) + assert set(r1.extras) == {"foo", "bar"} + assert set(r2.extras) == {"foo", "bar"} assert hash(r1) == hash(r2) assert hash(r1) == hash(( "twisted", diff --git a/ruff.toml b/ruff.toml index ce0b99e1dc..8031827ca5 100644 --- a/ruff.toml +++ b/ruff.toml @@ -30,6 +30,7 @@ extend-select = [ # local "ANN2", # missing-return-type-* + "C4", # flake8-comprehensions "PERF", # Perflint "PGH", # pygrep-hooks (blanket-* rules) "PT", # flake8-pytest-style diff --git a/setup.py b/setup.py index c28a14e722..e790c9a219 100755 --- a/setup.py +++ b/setup.py @@ -82,10 +82,10 @@ def _restore_install_lib(self): self.install_lib = self.install_libbase -setup_params = dict( - cmdclass={'install': install_with_pth}, - package_data=package_data, -) +setup_params = { + "cmdclass": {'install': install_with_pth}, + "package_data": package_data, +} if __name__ == '__main__': # allow setup.py to run from another directory diff --git a/setuptools/_normalization.py b/setuptools/_normalization.py index 0937a4faf8..7c23b4d970 100644 --- a/setuptools/_normalization.py +++ b/setuptools/_normalization.py @@ -9,10 +9,12 @@ import packaging # https://packaging.python.org/en/latest/specifications/core-metadata/#name -_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I) -_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.I) -_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.I) -_PEP440_FALLBACK = re.compile(r"^v?(?P(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I) +_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.IGNORECASE) +_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.IGNORECASE) +_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.IGNORECASE) +_PEP440_FALLBACK = re.compile( + r"^v?(?P(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.IGNORECASE +) def safe_identifier(name: str) -> str: diff --git a/setuptools/command/_requirestxt.py b/setuptools/command/_requirestxt.py index 9029b12514..9e3619099b 100644 --- a/setuptools/command/_requirestxt.py +++ b/setuptools/command/_requirestxt.py @@ -77,11 +77,11 @@ def _move_install_requirements_markers( for r in complex_reqs: extras_require[':' + str(r.marker)].setdefault(r) - expanded_extras = dict( + expanded_extras = { # list(dict.fromkeys(...)) ensures a list of unique strings - (k, list(dict.fromkeys(str(r) for r in map(_clean_req, v)))) + k: list(dict.fromkeys(str(r) for r in map(_clean_req, v))) for k, v in extras_require.items() - ) + } return simple_install_requires, expanded_extras diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7f66c3ba6a..40680cac48 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -35,8 +35,7 @@ def _get_purelib(): def strip_module(filename): if '.' in filename: filename = os.path.splitext(filename)[0] - if filename.endswith('module'): - filename = filename[:-6] + filename = filename.removesuffix('module') return filename diff --git a/setuptools/command/build_clib.py b/setuptools/command/build_clib.py index f376f4ce4d..92a58f7828 100644 --- a/setuptools/command/build_clib.py +++ b/setuptools/command/build_clib.py @@ -33,14 +33,14 @@ def build_libraries(self, libraries) -> None: "'sources' must be present and must be " "a list of source filenames" ) - sources = sorted(list(sources)) + sources = sorted(sources) log.info("building '%s' library", lib_name) # Make sure everything is the correct type. # obj_deps should be a dictionary of keys as sources # and a list/tuple of files that are its dependencies. - obj_deps = build_info.get('obj_deps', dict()) + obj_deps = build_info.get('obj_deps', {}) if not isinstance(obj_deps, dict): raise DistutilsSetupError( f"in 'libraries' option (library '{lib_name}'), " @@ -51,7 +51,7 @@ def build_libraries(self, libraries) -> None: # Get the global dependencies that are specified by the '' key. # These will go into every source's dependency list. - global_deps = obj_deps.get('', list()) + global_deps = obj_deps.get('', []) if not isinstance(global_deps, (list, tuple)): raise DistutilsSetupError( f"in 'libraries' option (library '{lib_name}'), " @@ -64,7 +64,7 @@ def build_libraries(self, libraries) -> None: for source in sources: src_deps = [source] src_deps.extend(global_deps) - extra_deps = obj_deps.get(source, list()) + extra_deps = obj_deps.get(source, []) if not isinstance(extra_deps, (list, tuple)): raise DistutilsSetupError( f"in 'libraries' option (library '{lib_name}'), " diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index be833a379c..0d0ab1ff7b 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -1,6 +1,7 @@ from __future__ import annotations import itertools +import operator import os import sys from collections.abc import Iterator @@ -326,7 +327,7 @@ def get_outputs(self) -> list[str]: def get_output_mapping(self) -> dict[str, str]: """See :class:`setuptools.commands.build.SubCommand`""" mapping = self._get_output_mapping() - return dict(sorted(mapping, key=lambda x: x[0])) + return dict(sorted(mapping, key=operator.itemgetter(0))) def __get_stubs_outputs(self): # assemble the base name for each extension that needs a stub @@ -337,7 +338,7 @@ def __get_stubs_outputs(self): ) # pair each base with the extension pairs = itertools.product(ns_ext_bases, self.__get_output_extensions()) - return list(base + fnext for base, fnext in pairs) + return [base + fnext for base, fnext in pairs] def __get_output_extensions(self): yield '.py' diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 2f6fcb7cdc..e4d35305e1 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -2,6 +2,7 @@ import fnmatch import itertools +import operator import os import stat import textwrap @@ -147,7 +148,7 @@ def get_output_mapping(self) -> dict[str, str]: self._get_package_data_output_mapping(), self._get_module_mapping(), ) - return dict(sorted(mapping, key=lambda x: x[0])) + return dict(sorted(mapping, key=operator.itemgetter(0))) def _get_module_mapping(self) -> Iterator[tuple[str, str]]: """Iterate over all modules producing (dest, src) pairs.""" diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index eb1b4c1fcc..325507120d 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1240,7 +1240,7 @@ def _set_fetcher_options(self, base): continue fetch_options[key] = val[1] # create a settings dictionary suitable for `edit_config` - settings = dict(easy_install=fetch_options) + settings = {"easy_install": fetch_options} cfg_filename = os.path.join(base, 'setup.cfg') setopt.edit_config(cfg_filename, settings) @@ -1377,17 +1377,17 @@ def create_home_path(self) -> None: self.debug_print(f"os.makedirs('{path}', 0o700)") os.makedirs(path, 0o700) - INSTALL_SCHEMES = dict( - posix=dict( - install_dir='$base/lib/python$py_version_short/site-packages', - script_dir='$base/bin', - ), - ) + INSTALL_SCHEMES = { + "posix": { + "install_dir": '$base/lib/python$py_version_short/site-packages', + "script_dir": '$base/bin', + }, + } - DEFAULT_SCHEME = dict( - install_dir='$base/Lib/site-packages', - script_dir='$base/Scripts', - ) + DEFAULT_SCHEME = { + "install_dir": '$base/Lib/site-packages', + "script_dir": '$base/Scripts', + } def _expand(self, *attrs): config_vars = self.get_finalized_command('install').config_vars @@ -2214,10 +2214,10 @@ def best(cls): """ Select the best ScriptWriter suitable for Windows """ - writer_lookup = dict( - executable=WindowsExecutableLauncherWriter, - natural=cls, - ) + writer_lookup = { + "executable": WindowsExecutableLauncherWriter, + "natural": cls, + } # for compatibility, use the executable launcher by default launcher = os.environ.get('SETUPTOOLS_LAUNCHER', 'executable') return writer_lookup[launcher] @@ -2225,7 +2225,7 @@ def best(cls): @classmethod def _get_script_args(cls, type_, name, header, script_text): "For Windows, add a .py extension" - ext = dict(console='.pya', gui='.pyw')[type_] + ext = {"console": '.pya', "gui": '.pyw'}[type_] if ext not in os.environ['PATHEXT'].lower().split(';'): msg = ( "{ext} not listed in PATHEXT; scripts will not be " diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 1a544ec258..c95753842d 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -14,6 +14,7 @@ import io import logging +import operator import os import shutil import traceback @@ -650,7 +651,7 @@ def _parent_path(pkg, pkg_path): >>> _parent_path("b", "src/c") 'src/c' """ - parent = pkg_path[: -len(pkg)] if pkg_path.endswith(pkg) else pkg_path + parent = pkg_path.removesuffix(pkg) return parent.rstrip("/" + os.sep) @@ -891,7 +892,7 @@ def _finder_template( """Create a string containing the code for the``MetaPathFinder`` and ``PathEntryFinder``. """ - mapping = dict(sorted(mapping.items(), key=lambda p: p[0])) + mapping = dict(sorted(mapping.items(), key=operator.itemgetter(0))) return _FINDER_TEMPLATE.format(name=name, mapping=mapping, namespaces=namespaces) diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index f77631168f..fa7fb5e5ca 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -213,8 +213,8 @@ def save_version_info(self, filename) -> None: """ # follow the order these keys would have been added # when PYTHONHASHSEED=0 - egg_info = dict(tag_build=self.tags(), tag_date=0) - edit_config(filename, dict(egg_info=egg_info)) + egg_info = {'tag_build': self.tags(), 'tag_date': 0} + edit_config(filename, {'egg_info': egg_info}) def finalize_options(self) -> None: # Note: we need to capture the current value returned @@ -475,8 +475,7 @@ def global_exclude(self, pattern): return self._remove_files(match.match) def append(self, item) -> None: - if item.endswith('\r'): # Fix older sdists built on Windows - item = item[:-1] + item = item.removesuffix('\r') path = convert_path(item) if self._safe_path(path): diff --git a/setuptools/dist.py b/setuptools/dist.py index 8d972cc49b..6feeca33df 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -781,7 +781,7 @@ def by_order(hook): defined = metadata.entry_points(group=group) filtered = itertools.filterfalse(self._removed, defined) - loaded = map(lambda e: e.load(), filtered) + loaded = (e.load() for e in filtered) for ep in sorted(loaded, key=by_order): ep(self) @@ -1064,8 +1064,7 @@ def iter_distribution_names(self): name, _buildinfo = ext else: name = ext.name - if name.endswith('module'): - name = name[:-6] + name = name.removesuffix('module') yield name def handle_display_options(self, option_order): diff --git a/setuptools/launch.py b/setuptools/launch.py index 0d162647d5..8a54814010 100644 --- a/setuptools/launch.py +++ b/setuptools/launch.py @@ -17,11 +17,11 @@ def run() -> None: """ __builtins__ script_name = sys.argv[1] - namespace = dict( - __file__=script_name, - __name__='__main__', - __doc__=None, - ) + namespace = { + '__file__': script_name, + '__name__': '__main__', + '__doc__': None, + } sys.argv[:] = sys.argv[1:] open_ = getattr(tokenize, 'open', open) diff --git a/setuptools/msvc.py b/setuptools/msvc.py index 313a781ae0..3128c3a714 100644 --- a/setuptools/msvc.py +++ b/setuptools/msvc.py @@ -35,7 +35,7 @@ class winreg: HKEY_LOCAL_MACHINE = None HKEY_CLASSES_ROOT = None - environ: dict[str, str] = dict() + environ: dict[str, str] = {} class PlatformInfo: @@ -393,7 +393,7 @@ def _find_latest_available_vs_ver(self): vc_vers = set(reg_vc_vers) vc_vers.update(self.known_vs_paths) - return sorted(vc_vers)[-1] + return max(vc_vers) def find_reg_vs_vers(self): """ diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1a6abebcda..e02f403f78 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -49,12 +49,12 @@ from distutils.errors import DistutilsError EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.+!]+)$') -HREF = re.compile(r"""href\s*=\s*['"]?([^'"> ]+)""", re.I) +HREF = re.compile(r"""href\s*=\s*['"]?([^'"> ]+)""", re.IGNORECASE) PYPI_MD5 = re.compile( r'([^<]+)\n\s+\(md5\)' ) -URL_SCHEME = re.compile('([-+.a-z0-9]{2,}):', re.I).match +URL_SCHEME = re.compile('([-+.a-z0-9]{2,}):', re.IGNORECASE).match EXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz".split() __all__ = [ @@ -214,7 +214,9 @@ def wrapper(*args, **kwargs): return wrapper -REL = re.compile(r"""<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>""", re.I) +REL = re.compile( + r"""<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>""", re.IGNORECASE +) """ Regex for an HTML tag with 'rel="val"' attributes. """ @@ -858,10 +860,10 @@ def _download_vcs(self, url, spec_filename): self.info(f"Doing {vcs} clone from {url} to {filename}") subprocess.check_call([vcs, 'clone', '--quiet', url, filename]) - co_commands = dict( - git=[vcs, '-C', filename, 'checkout', '--quiet', rev], - hg=[vcs, '--cwd', filename, 'up', '-C', '-r', rev, '-q'], - ) + co_commands = { + 'git': [vcs, '-C', filename, 'checkout', '--quiet', rev], + 'hg': [vcs, '--cwd', filename, 'up', '-C', '-r', rev, '-q'], + } if rev is not None: self.info(f"Checking out {rev}") subprocess.check_call(co_commands[vcs]) diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 2d84242d66..85f688fa23 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -266,7 +266,7 @@ def run_setup(setup_script, args): working_set.callbacks.append(lambda dist: dist.activate()) with DirectorySandbox(setup_dir): - ns = dict(__file__=setup_script, __name__='__main__') + ns = {'__file__': setup_script, '__name__': '__main__'} _execfile(setup_script, ns) except SystemExit as v: if v.args and v.args[0]: diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py index 489fd98e26..e87b85f94a 100644 --- a/setuptools/tests/config/test_apply_pyprojecttoml.py +++ b/setuptools/tests/config/test_apply_pyprojecttoml.py @@ -600,7 +600,7 @@ def test_not_listed_in_dynamic(self, tmp_path, attr, field, value): """Setuptools cannot set a field if not listed in ``dynamic``""" pyproject = self.pyproject(tmp_path, []) dist = makedist(tmp_path, **{attr: value}) - msg = re.compile(f"defined outside of `pyproject.toml`:.*{field}", re.S) + msg = re.compile(f"defined outside of `pyproject.toml`:.*{field}", re.DOTALL) with pytest.warns(_MissingDynamic, match=msg): dist = pyprojecttoml.apply_configuration(dist, pyproject) diff --git a/setuptools/tests/config/test_expand.py b/setuptools/tests/config/test_expand.py index c5710ec63d..71046d1c1f 100644 --- a/setuptools/tests/config/test_expand.py +++ b/setuptools/tests/config/test_expand.py @@ -29,7 +29,7 @@ def test_glob_relative(tmp_path, monkeypatch): "dir1/dir2/a.ini", } - write_files({k: "" for k in files}, tmp_path) + write_files(dict.fromkeys(files, ""), tmp_path) patterns = ["**/*.txt", "[ab].*", "**/[ac].ini"] monkeypatch.chdir(tmp_path) assert set(expand.glob_relative(patterns)) == files @@ -198,7 +198,7 @@ def test_find_packages(tmp_path, args, pkgs): "other/__init__.py", "dir1/dir2/__init__.py", } - write_files({k: "" for k in files}, tmp_path) + write_files(dict.fromkeys(files, ""), tmp_path) package_dir = {} kwargs = {"root_dir": tmp_path, "fill_package_dir": package_dir, **args} @@ -237,7 +237,7 @@ def test_find_packages(tmp_path, args, pkgs): ], ) def test_fill_package_dir(tmp_path, files, where, expected_package_dir): - write_files({k: "" for k in files}, tmp_path) + write_files(dict.fromkeys(files, ""), tmp_path) pkg_dir = {} kwargs = {"root_dir": tmp_path, "fill_package_dir": pkg_dir, "namespaces": False} pkgs = expand.find_packages(where=where, **kwargs) diff --git a/setuptools/tests/config/test_pyprojecttoml.py b/setuptools/tests/config/test_pyprojecttoml.py index db40fcd23d..6d995d23af 100644 --- a/setuptools/tests/config/test_pyprojecttoml.py +++ b/setuptools/tests/config/test_pyprojecttoml.py @@ -207,7 +207,7 @@ def test_scripts_not_listed_in_dynamic(self, tmp_path, missing_dynamic): dynamic = {"scripts", "gui-scripts", "entry-points"} - {missing_dynamic} msg = f"defined outside of `pyproject.toml`:.*{missing_dynamic}" - with pytest.raises(OptionError, match=re.compile(msg, re.S)): + with pytest.raises(OptionError, match=re.compile(msg, re.DOTALL)): expand_configuration(self.pyproject(dynamic), tmp_path) @@ -325,7 +325,9 @@ def test_invalid_example(tmp_path, example, error_msg): pyproject = tmp_path / "pyproject.toml" pyproject.write_text(cleandoc(example), encoding="utf-8") - pattern = re.compile(f"invalid pyproject.toml.*{error_msg}.*", re.M | re.S) + pattern = re.compile( + f"invalid pyproject.toml.*{error_msg}.*", re.MULTILINE | re.DOTALL + ) with pytest.raises(ValueError, match=pattern): read_configuration(pyproject) diff --git a/setuptools/tests/config/test_setupcfg.py b/setuptools/tests/config/test_setupcfg.py index 61af990447..13b065f844 100644 --- a/setuptools/tests/config/test_setupcfg.py +++ b/setuptools/tests/config/test_setupcfg.py @@ -354,11 +354,11 @@ def test_usupported_section(self, tmpdir): dist.parse_config_files() def test_classifiers(self, tmpdir): - expected = set([ + expected = { 'Framework :: Django', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', - ]) + } # From file. _, config = fake_env(tmpdir, '[metadata]\nclassifiers = file: classifiers\n') @@ -602,11 +602,11 @@ def test_find_directive(self, tmpdir): make_package_dir('sub_two', dir_package) with get_dist(tmpdir) as dist: - assert set(dist.packages) == set([ + assert set(dist.packages) == { 'fake_package', 'fake_package.sub_two', 'fake_package.sub_one', - ]) + } config.write( '[options]\n' @@ -630,7 +630,7 @@ def test_find_directive(self, tmpdir): ' fake_package.sub_one\n' ) with get_dist(tmpdir) as dist: - assert set(dist.packages) == set(['fake_package', 'fake_package.sub_two']) + assert set(dist.packages) == {'fake_package', 'fake_package.sub_two'} def test_find_namespace_directive(self, tmpdir): dir_package, config = fake_env( diff --git a/setuptools/tests/contexts.py b/setuptools/tests/contexts.py index 97cceea0e7..9002f1f395 100644 --- a/setuptools/tests/contexts.py +++ b/setuptools/tests/contexts.py @@ -27,7 +27,7 @@ def environment(**replacements): In a context, patch the environment with replacements. Pass None values to clear the values. """ - saved = dict((key, os.environ[key]) for key in replacements if key in os.environ) + saved = {key: os.environ[key] for key in replacements if key in os.environ} # remove values that are null remove = (key for (key, value) in replacements.items() if value is None) diff --git a/setuptools/tests/environment.py b/setuptools/tests/environment.py index ed5499ef7d..17e1e37a3f 100644 --- a/setuptools/tests/environment.py +++ b/setuptools/tests/environment.py @@ -49,7 +49,7 @@ def run_setup_py(cmd, pypath=None, path=None, data_stream=0, env=None): code directly to prevent accidental behavior issues """ if env is None: - env = dict() + env = {} for envname in os.environ: env[envname] = os.environ[envname] diff --git a/setuptools/tests/test_bdist_deprecations.py b/setuptools/tests/test_bdist_deprecations.py index d9d67b0616..fa975323a7 100644 --- a/setuptools/tests/test_bdist_deprecations.py +++ b/setuptools/tests/test_bdist_deprecations.py @@ -13,14 +13,12 @@ @pytest.mark.xfail(reason="bdist_rpm is long deprecated, should we remove it? #1988") @mock.patch('distutils.command.bdist_rpm.bdist_rpm') def test_bdist_rpm_warning(distutils_cmd, tmpdir_cwd): - dist = Distribution( - dict( - script_name='setup.py', - script_args=['bdist_rpm'], - name='foo', - py_modules=['hi'], - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['bdist_rpm'], + 'name': 'foo', + 'py_modules': ['hi'], + }) dist.parse_command_line() with pytest.warns(SetuptoolsDeprecationWarning): dist.run_commands() diff --git a/setuptools/tests/test_bdist_egg.py b/setuptools/tests/test_bdist_egg.py index 036167dd95..d054533243 100644 --- a/setuptools/tests/test_bdist_egg.py +++ b/setuptools/tests/test_bdist_egg.py @@ -31,14 +31,12 @@ class Test: @pytest.mark.usefixtures("user_override") @pytest.mark.usefixtures("setup_context") def test_bdist_egg(self): - dist = Distribution( - dict( - script_name='setup.py', - script_args=['bdist_egg'], - name='foo', - py_modules=['hi'], - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['bdist_egg'], + 'name': 'foo', + 'py_modules': ['hi'], + }) os.makedirs(os.path.join('build', 'src')) with contexts.quiet(): dist.parse_command_line() @@ -55,19 +53,17 @@ def test_bdist_egg(self): @pytest.mark.usefixtures("user_override") @pytest.mark.usefixtures("setup_context") def test_exclude_source_files(self): - dist = Distribution( - dict( - script_name='setup.py', - script_args=['bdist_egg', '--exclude-source-files'], - py_modules=['hi'], - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['bdist_egg', '--exclude-source-files'], + 'py_modules': ['hi'], + }) with contexts.quiet(): dist.parse_command_line() dist.run_commands() [dist_name] = os.listdir('dist') dist_filename = os.path.join('dist', dist_name) zip = zipfile.ZipFile(dist_filename) - names = list(zi.filename for zi in zip.filelist) + names = [zi.filename for zi in zip.filelist] assert 'hi.pyc' in names assert 'hi.py' not in names diff --git a/setuptools/tests/test_build.py b/setuptools/tests/test_build.py index f0f1d9dcf2..56ad825913 100644 --- a/setuptools/tests/test_build.py +++ b/setuptools/tests/test_build.py @@ -9,14 +9,12 @@ def test_distribution_gives_setuptools_build_obj(tmpdir_cwd): setuptools specific build object. """ - dist = Distribution( - dict( - script_name='setup.py', - script_args=['build'], - packages=[], - package_data={'': ['path/*']}, - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['build'], + 'packages': [], + 'package_data': {'': ['path/*']}, + }) assert isinstance(dist.get_command_obj("build"), build) diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py index c7b60ac32f..aaa6cf5d6f 100644 --- a/setuptools/tests/test_build_ext.py +++ b/setuptools/tests/test_build_ext.py @@ -43,7 +43,7 @@ def test_abi3_filename(self): print(get_abi3_suffix()) extension = Extension('spam.eggs', ['eggs.c'], py_limited_api=True) - dist = Distribution(dict(ext_modules=[extension])) + dist = Distribution({'ext_modules': [extension]}) cmd = build_ext(dist) cmd.finalize_options() assert 'spam.eggs' in cmd.ext_map @@ -187,7 +187,7 @@ def get_build_ext_cmd(self, optional: bool, **opts) -> build_ext: } path.build(files) extension = Extension('spam.eggs', ['eggs.c'], optional=optional) - dist = Distribution(dict(ext_modules=[extension])) + dist = Distribution({'ext_modules': [extension]}) dist.script_name = 'setup.py' cmd = build_ext(dist) vars(cmd).update(build_lib=".build/lib", build_temp=".build/tmp", **opts) diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py index 1e3a660833..90fcf49089 100644 --- a/setuptools/tests/test_build_py.py +++ b/setuptools/tests/test_build_py.py @@ -21,14 +21,12 @@ def test_directories_in_package_data_glob(tmpdir_cwd): Regression test for #261. """ - dist = Distribution( - dict( - script_name='setup.py', - script_args=['build_py'], - packages=[''], - package_data={'': ['path/*']}, - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['build_py'], + 'packages': [''], + 'package_data': {'': ['path/*']}, + }) os.makedirs('path/subpath') dist.parse_command_line() dist.run_commands() @@ -41,14 +39,12 @@ def test_recursive_in_package_data_glob(tmpdir_cwd): #1806 """ - dist = Distribution( - dict( - script_name='setup.py', - script_args=['build_py'], - packages=[''], - package_data={'': ['path/**/data']}, - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['build_py'], + 'packages': [''], + 'package_data': {'': ['path/**/data']}, + }) os.makedirs('path/subpath/subsubpath') open('path/subpath/subsubpath/data', 'wb').close() @@ -69,14 +65,12 @@ def test_read_only(tmpdir_cwd): #1451 """ - dist = Distribution( - dict( - script_name='setup.py', - script_args=['build_py'], - packages=['pkg'], - package_data={'pkg': ['data.dat']}, - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['build_py'], + 'packages': ['pkg'], + 'package_data': {'pkg': ['data.dat']}, + }) os.makedirs('pkg') open('pkg/__init__.py', 'wb').close() open('pkg/data.dat', 'wb').close() @@ -100,14 +94,12 @@ def test_executable_data(tmpdir_cwd): #2041 """ - dist = Distribution( - dict( - script_name='setup.py', - script_args=['build_py'], - packages=['pkg'], - package_data={'pkg': ['run-me']}, - ) - ) + dist = Distribution({ + 'script_name': 'setup.py', + 'script_args': ['build_py'], + 'packages': ['pkg'], + 'package_data': {'pkg': ['run-me']}, + }) os.makedirs('pkg') open('pkg/__init__.py', 'wb').close() open('pkg/run-me', 'wb').close() @@ -252,7 +244,7 @@ def test_existing_egg_info(tmpdir_cwd, monkeypatch): assert build_py.data_files # Make sure the list of outputs is actually OK - outputs = map(lambda x: x.replace(os.sep, "/"), build_py.get_outputs()) + outputs = (x.replace(os.sep, "/") for x in build_py.get_outputs()) assert outputs example = str(Path(build_py.build_lib, "mypkg/__init__.py")).replace(os.sep, "/") assert example in outputs diff --git a/setuptools/tests/test_core_metadata.py b/setuptools/tests/test_core_metadata.py index 0d925111fa..0e5ee48047 100644 --- a/setuptools/tests/test_core_metadata.py +++ b/setuptools/tests/test_core_metadata.py @@ -25,15 +25,15 @@ from .config.downloads import retrieve_file, urls_from_file -EXAMPLE_BASE_INFO = dict( - name="package", - version="0.0.1", - author="Foo Bar", - author_email="foo@bar.net", - long_description="Long\ndescription", - description="Short description", - keywords=["one", "two"], -) +EXAMPLE_BASE_INFO = { + "name": "package", + "version": "0.0.1", + "author": "Foo Bar", + "author_email": "foo@bar.net", + "long_description": "Long\ndescription", + "description": "Short description", + "keywords": ["one", "two"], +} @pytest.mark.parametrize( @@ -107,7 +107,7 @@ def __read_test_cases(): ), pytest.param( 'Metadata Version 1.2: Project-Url', - params(project_urls=dict(Foo='https://example.bar')), + params(project_urls={"Foo": 'https://example.bar'}), marks=pytest.mark.xfail( reason="Issue #1578: project_urls not read", ), @@ -137,33 +137,33 @@ def __read_test_cases(): ), ( 'Missing author', - dict( - name='foo', - version='1.0.0', - author_email='snorri@sturluson.name', - ), + { + "name": 'foo', + "version": '1.0.0', + "author_email": 'snorri@sturluson.name', + }, ), ( 'Missing author e-mail', - dict( - name='foo', - version='1.0.0', - author='Snorri Sturluson', - ), + { + "name": 'foo', + "version": '1.0.0', + "author": 'Snorri Sturluson', + }, ), ( 'Missing author and e-mail', - dict( - name='foo', - version='1.0.0', - ), + { + "name": 'foo', + "version": '1.0.0', + }, ), ( 'Bypass normalized version', - dict( - name='foo', - version=sic('1.0.0a'), - ), + { + "name": 'foo', + "version": sic('1.0.0a'), + }, ), ] diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 929fa9c285..51f206737d 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -64,16 +64,16 @@ def test_console_scripts(self, tmpdir): "TODO: needs a fixture to cause 'develop' " "to be invoked without mutating environment." ) - settings = dict( - name='foo', - packages=['foo'], - version='0.0', - entry_points={ + settings = { + 'name': 'foo', + 'packages': ['foo'], + 'version': '0.0', + 'entry_points': { 'console_scripts': [ 'foocmd = foo:foo', ], }, - ) + } dist = Distribution(settings) dist.script_name = 'setup.py' cmd = develop(dist) @@ -84,9 +84,9 @@ def test_console_scripts(self, tmpdir): @pytest.mark.xfail(reason="legacy behavior retained for compatibility #4167") def test_egg_link_filename(self): - settings = dict( - name='Foo $$$ Bar_baz-bing', - ) + settings = { + 'name': 'Foo $$$ Bar_baz-bing', + } dist = Distribution(settings) cmd = develop(dist) cmd.ensure_finalized() diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index e65ab310e7..56418ee6d5 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -59,19 +59,19 @@ def sdist_with_index(distname, version): assert [dist.key for dist in resolved_dists if dist] == reqs -EXAMPLE_BASE_INFO = dict( - name="package", - version="0.0.1", - author="Foo Bar", - author_email="foo@bar.net", - long_description="Long\ndescription", - description="Short description", - keywords=["one", "two"], -) +EXAMPLE_BASE_INFO = { + 'name': "package", + 'version': "0.0.1", + 'author': "Foo Bar", + 'author_email': "foo@bar.net", + 'long_description': "Long\ndescription", + 'description': "Short description", + 'keywords': ["one", "two"], +} def test_provides_extras_deterministic_order(): - attrs = dict(extras_require=dict(a=['foo'], b=['bar'])) + attrs = {'extras_require': {'a': ['foo'], 'b': ['bar']}} dist = Distribution(attrs) assert list(dist.metadata.provides_extras) == ['a', 'b'] attrs['extras_require'] = dict(reversed(attrs['extras_require'].items())) diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py index 426694e019..06beced4f4 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -56,9 +56,7 @@ def metadata(self, tmpdir): return str(tmpdir) def test_distinfo(self, metadata): - dists = dict( - (d.project_name, d) for d in pkg_resources.find_distributions(metadata) - ) + dists = {d.project_name: d for d in pkg_resources.find_distributions(metadata)} assert len(dists) == 2, dists @@ -86,7 +84,7 @@ def test_invalid_version(self, tmp_path): """ config = "[metadata]\nname=proj\nversion=42\n[egg_info]\ntag_build=invalid!!!\n" (tmp_path / "setup.cfg").write_text(config, encoding="utf-8") - msg = re.compile("invalid version", re.M | re.I) + msg = re.compile("invalid version", re.MULTILINE | re.IGNORECASE) proc = run_command_inner("dist_info", cwd=tmp_path, check=False) assert proc.returncode assert msg.search(proc.stdout) diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py index f99a588499..a69483f4e8 100644 --- a/setuptools/tests/test_distutils_adoption.py +++ b/setuptools/tests/test_distutils_adoption.py @@ -51,7 +51,7 @@ def test_distutils_stdlib(venv): """ Ensure stdlib distutils is used when appropriate. """ - env = dict(SETUPTOOLS_USE_DISTUTILS='stdlib') + env = {'SETUPTOOLS_USE_DISTUTILS': 'stdlib'} assert venv.name not in find_distutils(venv, env=env).split(os.sep) assert count_meta_path(venv, env=env) == 0 @@ -60,7 +60,7 @@ def test_distutils_local_with_setuptools(venv): """ Ensure local distutils is used when appropriate. """ - env = dict(SETUPTOOLS_USE_DISTUTILS='local') + env = {'SETUPTOOLS_USE_DISTUTILS': 'local'} loc = find_distutils(venv, imports='setuptools, distutils', env=env) assert venv.name in loc.split(os.sep) assert count_meta_path(venv, env=env) <= 1 @@ -72,7 +72,7 @@ def test_distutils_local(venv): Even without importing, the setuptools-local copy of distutils is preferred. """ - env = dict(SETUPTOOLS_USE_DISTUTILS='local') + env = {'SETUPTOOLS_USE_DISTUTILS': 'local'} assert venv.name in find_distutils(venv, env=env).split(os.sep) assert count_meta_path(venv, env=env) <= 1 @@ -127,7 +127,7 @@ def test_distutils_has_origin(): ], ) def test_modules_are_not_duplicated_on_import(distutils_version, imported_module, venv): - env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version) + env = {'SETUPTOOLS_USE_DISTUTILS': distutils_version} script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED.format(imported_module=imported_module) cmd = ['python', '-c', script] output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip() @@ -153,7 +153,7 @@ def test_modules_are_not_duplicated_on_import(distutils_version, imported_module ], ) def test_log_module_is_not_duplicated_on_import(distutils_version, venv): - env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version) + env = {'SETUPTOOLS_USE_DISTUTILS': distutils_version} cmd = ['python', '-c', ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED] output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip() assert output == "success" @@ -186,7 +186,7 @@ def test_log_module_is_not_duplicated_on_import(distutils_version, venv): ], ) def test_consistent_error_from_modified_py(distutils_version, imported_module, venv): - env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version) + env = {'SETUPTOOLS_USE_DISTUTILS': distutils_version} cmd = [ 'python', '-c', diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index b58b0b6666..db9eea3c59 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -761,7 +761,7 @@ def make_dependency_sdist(dist_path, distname, version): with contexts.tempdir() as temp_dir: test_pkg = create_setup_requires_package( temp_dir, - setup_attrs=dict(version='attr: foobar.version'), + setup_attrs={'version': 'attr: foobar.version'}, make_package=make_dependency_sdist, use_setup_cfg=use_setup_cfg + ('version',), ) @@ -783,7 +783,7 @@ def test_setup_requires_honors_pip_env(self, mock_index, monkeypatch): temp_dir, 'python-xlib', '0.19', - setup_attrs=dict(dependency_links=[]), + setup_attrs={'dependency_links': []}, ) test_setup_cfg = os.path.join(test_pkg, 'setup.cfg') with open(test_setup_cfg, 'w', encoding="utf-8") as fp: @@ -815,7 +815,7 @@ def test_setup_requires_with_pep508_url(self, mock_index, monkeypatch): # Ignored (overridden by setup_attrs) 'python-xlib', '0.19', - setup_attrs=dict(setup_requires=f'dependency @ {dep_url}'), + setup_attrs={'setup_requires': f'dependency @ {dep_url}'}, ) test_setup_py = os.path.join(test_pkg, 'setup.py') run_setup(test_setup_py, ['--version']) @@ -898,7 +898,7 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir): str(tmpdir), 'python-xlib', '0.19', # Ignored (overridden by setup_attrs). - setup_attrs=dict(setup_requires='dep', dependency_links=[index_url]), + setup_attrs={'setup_requires': 'dep', 'dependency_links': [index_url]}, ) test_setup_py = os.path.join(test_pkg, 'setup.py') run_setup(test_setup_py, ['--version']) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 528e2c13d8..4b567b3cf0 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -31,7 +31,7 @@ def env(): env = Environment(env_dir) os.chmod(env_dir, stat.S_IRWXU) subs = 'home', 'lib', 'scripts', 'data', 'egg-base' - env.paths = dict((dirname, os.path.join(env_dir, dirname)) for dirname in subs) + env.paths = {dirname: os.path.join(env_dir, dirname) for dirname in subs} list(map(os.mkdir, env.paths.values())) path.build({ env.paths['home']: { diff --git a/setuptools/tests/test_glob.py b/setuptools/tests/test_glob.py index 8d225a4461..8805e2f663 100644 --- a/setuptools/tests/test_glob.py +++ b/setuptools/tests/test_glob.py @@ -41,5 +41,5 @@ ) def test_glob(monkeypatch, tmpdir, tree, pattern, matches): monkeypatch.chdir(tmpdir) - path.build({name: '' for name in tree.split()}) - assert list(sorted(glob(pattern))) == list(sorted(matches)) + path.build(dict.fromkeys(tree.split(), '')) + assert sorted(glob(pattern)) == sorted(matches) diff --git a/setuptools/tests/test_install_scripts.py b/setuptools/tests/test_install_scripts.py index e62a6b7f31..a1e3fe2d55 100644 --- a/setuptools/tests/test_install_scripts.py +++ b/setuptools/tests/test_install_scripts.py @@ -11,11 +11,11 @@ class TestInstallScripts: - settings = dict( - name='foo', - entry_points={'console_scripts': ['foo=foo:foo']}, - version='0.0', - ) + settings = { + 'name': 'foo', + 'entry_points': {'console_scripts': ['foo=foo:foo']}, + 'version': '0.0', + } unix_exe = '/usr/dummy-test-path/local/bin/python' unix_spaces_exe = '/usr/bin/env dummy-test-python' win32_exe = 'C:\\Dummy Test Path\\Program Files\\Python 3.6\\python.exe' diff --git a/setuptools/tests/test_manifest.py b/setuptools/tests/test_manifest.py index 903a528db0..1fd8efda35 100644 --- a/setuptools/tests/test_manifest.py +++ b/setuptools/tests/test_manifest.py @@ -227,7 +227,7 @@ def get_files(self): def test_no_manifest(self): """Check a missing MANIFEST.in includes only the standard files.""" - assert (default_files - set(['MANIFEST.in'])) == self.get_files() + assert (default_files - {'MANIFEST.in'}) == self.get_files() def test_empty_files(self): """Check an empty MANIFEST.in includes only the standard files.""" @@ -237,7 +237,7 @@ def test_empty_files(self): def test_include(self): """Include extra rst files in the project root.""" self.make_manifest("include *.rst") - files = default_files | set(['testing.rst', '.hidden.rst']) + files = default_files | {'testing.rst', '.hidden.rst'} assert files == self.get_files() def test_exclude(self): @@ -249,45 +249,45 @@ def test_exclude(self): exclude app/*.txt """ ) - files = default_files | set([ml('app/c.rst')]) + files = default_files | {ml('app/c.rst')} assert files == self.get_files() def test_include_multiple(self): """Include with multiple patterns.""" ml = make_local_path self.make_manifest("include app/*.txt app/static/*") - files = default_files | set([ + files = default_files | { ml('app/a.txt'), ml('app/b.txt'), ml('app/static/app.js'), ml('app/static/app.js.map'), ml('app/static/app.css'), ml('app/static/app.css.map'), - ]) + } assert files == self.get_files() def test_graft(self): """Include the whole app/static/ directory.""" ml = make_local_path self.make_manifest("graft app/static") - files = default_files | set([ + files = default_files | { ml('app/static/app.js'), ml('app/static/app.js.map'), ml('app/static/app.css'), ml('app/static/app.css.map'), - ]) + } assert files == self.get_files() def test_graft_glob_syntax(self): """Include the whole app/static/ directory.""" ml = make_local_path self.make_manifest("graft */static") - files = default_files | set([ + files = default_files | { ml('app/static/app.js'), ml('app/static/app.js.map'), ml('app/static/app.css'), ml('app/static/app.css.map'), - ]) + } assert files == self.get_files() def test_graft_global_exclude(self): @@ -299,7 +299,7 @@ def test_graft_global_exclude(self): global-exclude *.map """ ) - files = default_files | set([ml('app/static/app.js'), ml('app/static/app.css')]) + files = default_files | {ml('app/static/app.js'), ml('app/static/app.css')} assert files == self.get_files() def test_global_include(self): @@ -310,13 +310,13 @@ def test_global_include(self): global-include *.rst *.js *.css """ ) - files = default_files | set([ + files = default_files | { '.hidden.rst', 'testing.rst', ml('app/c.rst'), ml('app/static/app.js'), ml('app/static/app.css'), - ]) + } assert files == self.get_files() def test_graft_prune(self): @@ -328,7 +328,7 @@ def test_graft_prune(self): prune app/static """ ) - files = default_files | set([ml('app/a.txt'), ml('app/b.txt'), ml('app/c.rst')]) + files = default_files | {ml('app/a.txt'), ml('app/b.txt'), ml('app/c.rst')} assert files == self.get_files() diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 19d8ddf6da..cc99992f83 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -419,7 +419,7 @@ def test_defaults_case_sensitivity(self, source_dir): # lowercase all names so we can test in a # case-insensitive way to make sure the files # are not included. - manifest = map(lambda x: x.lower(), cmd.filelist.files) + manifest = (x.lower() for x in cmd.filelist.files) assert 'readme.rst' not in manifest, manifest assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index ccf25618a5..f715dcbbd3 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -23,7 +23,7 @@ def test_utf8_encoding_retained(self, tmpdir): """ config = tmpdir.join('setup.cfg') self.write_text(str(config), '[names]\njaraco=джарако') - setopt.edit_config(str(config), dict(names=dict(other='yes'))) + setopt.edit_config(str(config), {'names': {'other': 'yes'}}) parser = self.parse_config(str(config)) assert parser.get('names', 'jaraco') == 'джарако' assert parser.get('names', 'other') == 'yes' @@ -34,7 +34,7 @@ def test_case_retained(self, tmpdir): """ config = tmpdir.join('setup.cfg') self.write_text(str(config), '[names]\nFoO=bAr') - setopt.edit_config(str(config), dict(names=dict(oTher='yes'))) + setopt.edit_config(str(config), {'names': {'oTher': 'yes'}}) actual = config.read_text(encoding='ascii') assert 'FoO' in actual assert 'oTher' in actual diff --git a/setuptools/tests/test_warnings.py b/setuptools/tests/test_warnings.py index 41193d4f71..8daf602a3b 100644 --- a/setuptools/tests/test_warnings.py +++ b/setuptools/tests/test_warnings.py @@ -5,10 +5,10 @@ from setuptools.warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning _EXAMPLES = { - "default": dict( - args=("Hello {x}", "\n\t{target} {v:.1f}"), - kwargs={"x": 5, "v": 3, "target": "World"}, - expected=""" + "default": { + "args": ("Hello {x}", "\n\t{target} {v:.1f}"), + "kwargs": {"x": 5, "v": 3, "target": "World"}, + "expected": """ Hello 5 !! @@ -18,11 +18,11 @@ !! """, - ), - "futue_due_date": dict( - args=("Summary", "Lorem ipsum"), - kwargs={"due_date": (9999, 11, 22)}, - expected=""" + }, + "futue_due_date": { + "args": ("Summary", "Lorem ipsum"), + "kwargs": {"due_date": (9999, 11, 22)}, + "expected": """ Summary !! @@ -35,11 +35,11 @@ !! """, - ), - "past_due_date_with_docs": dict( - args=("Summary", "Lorem ipsum"), - kwargs={"due_date": (2000, 11, 22), "see_docs": "some_page.html"}, - expected=""" + }, + "past_due_date_with_docs": { + "args": ("Summary", "Lorem ipsum"), + "kwargs": {"due_date": (2000, 11, 22), "see_docs": "some_page.html"}, + "expected": """ Summary !! @@ -54,7 +54,7 @@ !! """, - ), + }, } diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py index 70165c608b..b6b7feb17d 100644 --- a/setuptools/tests/test_wheel.py +++ b/setuptools/tests/test_wheel.py @@ -115,11 +115,11 @@ def build_wheel(extra_file_defs=None, **kwargs): def tree_set(root): - contents = set() - for dirpath, dirnames, filenames in os.walk(root): - for filename in filenames: - contents.add(os.path.join(os.path.relpath(dirpath, root), filename)) - return contents + return { + os.path.join(os.path.relpath(dirpath, root), filename) + for dirpath, dirnames, filenames in os.walk(root) + for filename in filenames + } def flatten_tree(tree): @@ -183,47 +183,47 @@ def __repr__(self) -> str: # making a TypedDict is not worth in a test and anonymous/inline TypedDict are experimental # https://github.com/python/mypy/issues/9884 WHEEL_INSTALL_TESTS: tuple[dict[str, Any], ...] = ( - dict( - id='basic', - file_defs={'foo': {'__init__.py': ''}}, - setup_kwargs=dict( - packages=['foo'], - ), - install_tree=flatten_tree({ + { + 'id': 'basic', + 'file_defs': {'foo': {'__init__.py': ''}}, + 'setup_kwargs': { + 'packages': ['foo'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': ['PKG-INFO', 'RECORD', 'WHEEL', 'top_level.txt'], 'foo': ['__init__.py'], } }), - ), - dict( - id='utf-8', - setup_kwargs=dict( - description='Description accentuée', - ), - ), - dict( - id='data', - file_defs={ + }, + { + 'id': 'utf-8', + 'setup_kwargs': { + 'description': 'Description accentuée', + }, + }, + { + 'id': 'data', + 'file_defs': { 'data.txt': DALS( """ Some data... """ ), }, - setup_kwargs=dict( - data_files=[('data_dir', ['data.txt'])], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'data_files': [('data_dir', ['data.txt'])], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': ['PKG-INFO', 'RECORD', 'WHEEL', 'top_level.txt'], 'data_dir': ['data.txt'], } }), - ), - dict( - id='extension', - file_defs={ + }, + { + 'id': 'extension', + 'file_defs': { 'extension.c': DALS( """ #include "Python.h" @@ -268,14 +268,14 @@ def __repr__(self) -> str: """ ), }, - setup_kwargs=dict( - ext_modules=[ + 'setup_kwargs': { + 'ext_modules': [ Record( 'setuptools.Extension', name='extension', sources=['extension.c'] ) ], - ), - install_tree=flatten_tree({ + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}-{platform}.egg': [ 'extension{shlib_ext}', { @@ -288,19 +288,19 @@ def __repr__(self) -> str: }, ] }), - ), - dict( - id='header', - file_defs={ + }, + { + 'id': 'header', + 'file_defs': { 'header.h': DALS( """ """ ), }, - setup_kwargs=dict( - headers=['header.h'], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'headers': ['header.h'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': [ 'header.h', { @@ -313,10 +313,10 @@ def __repr__(self) -> str: }, ] }), - ), - dict( - id='script', - file_defs={ + }, + { + 'id': 'script', + 'file_defs': { 'script.py': DALS( """ #/usr/bin/python @@ -330,10 +330,10 @@ def __repr__(self) -> str: """ ), }, - setup_kwargs=dict( - scripts=['script.py', 'script.sh'], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'scripts': ['script.py', 'script.sh'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': [ 'PKG-INFO', @@ -344,11 +344,11 @@ def __repr__(self) -> str: ] } }), - ), - dict( - id='requires1', - install_requires='foobar==2.0', - install_tree=flatten_tree({ + }, + { + 'id': 'requires1', + 'install_requires': 'foobar==2.0', + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': [ 'PKG-INFO', @@ -359,40 +359,40 @@ def __repr__(self) -> str: ] } }), - requires_txt=DALS( + 'requires_txt': DALS( """ foobar==2.0 """ ), - ), - dict( - id='requires2', - install_requires=f""" + }, + { + 'id': 'requires2', + 'install_requires': f""" bar foo<=2.0; {sys.platform!r} in sys_platform """, - requires_txt=DALS( + 'requires_txt': DALS( """ bar foo<=2.0 """ ), - ), - dict( - id='requires3', - install_requires=f""" + }, + { + 'id': 'requires3', + 'install_requires': f""" bar; {sys.platform!r} != sys_platform """, - ), - dict( - id='requires4', - install_requires=""" + }, + { + 'id': 'requires4', + 'install_requires': """ foo """, - extras_require={ + 'extras_require': { 'extra': 'foobar>3', }, - requires_txt=DALS( + 'requires_txt': DALS( """ foo @@ -400,27 +400,27 @@ def __repr__(self) -> str: foobar>3 """ ), - ), - dict( - id='requires5', - extras_require={ + }, + { + 'id': 'requires5', + 'extras_require': { 'extra': f'foobar; {sys.platform!r} != sys_platform', }, - requires_txt=DALS( + 'requires_txt': DALS( """ [extra] """ ), - ), - dict( - id='requires_ensure_order', - install_requires=""" + }, + { + 'id': 'requires_ensure_order', + 'install_requires': """ foo bar baz qux """, - extras_require={ + 'extras_require': { 'extra': """ foobar>3 barbaz>4 @@ -428,7 +428,7 @@ def __repr__(self) -> str: quxzap>6 """, }, - requires_txt=DALS( + 'requires_txt': DALS( """ foo bar @@ -442,19 +442,19 @@ def __repr__(self) -> str: quxzap>6 """ ), - ), - dict( - id='namespace_package', - file_defs={ + }, + { + 'id': 'namespace_package', + 'file_defs': { 'foo': { 'bar': {'__init__.py': ''}, }, }, - setup_kwargs=dict( - namespace_packages=['foo'], - packages=['foo.bar'], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'namespace_packages': ['foo'], + 'packages': ['foo.bar'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': [ 'foo-1.0-py{py_version}-nspkg.pth', { @@ -474,21 +474,21 @@ def __repr__(self) -> str: }, ] }), - ), - dict( - id='empty_namespace_package', - file_defs={ + }, + { + 'id': 'empty_namespace_package', + 'file_defs': { 'foobar': { '__init__.py': ( "__import__('pkg_resources').declare_namespace(__name__)" ) }, }, - setup_kwargs=dict( - namespace_packages=['foobar'], - packages=['foobar'], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'namespace_packages': ['foobar'], + 'packages': ['foobar'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': [ 'foo-1.0-py{py_version}-nspkg.pth', { @@ -507,10 +507,10 @@ def __repr__(self) -> str: }, ] }), - ), - dict( - id='data_in_package', - file_defs={ + }, + { + 'id': 'data_in_package', + 'file_defs': { 'foo': { '__init__.py': '', 'data_dir': { @@ -522,11 +522,11 @@ def __repr__(self) -> str: }, } }, - setup_kwargs=dict( - packages=['foo'], - data_files=[('foo/data_dir', ['foo/data_dir/data.txt'])], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'packages': ['foo'], + 'data_files': [('foo/data_dir', ['foo/data_dir/data.txt'])], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': [ 'PKG-INFO', @@ -544,7 +544,7 @@ def __repr__(self) -> str: ], } }), - ), + }, ) @@ -653,9 +653,9 @@ def build_wheel(extra_file_defs=None, **kwargs): ) yield glob.glob(os.path.join(source_dir, 'dist', '*.whl'))[0] - params = dict( - id='script', - file_defs={ + params = { + 'id': 'script', + 'file_defs': { 'script.py': DALS( """ #/usr/bin/python @@ -669,10 +669,10 @@ def build_wheel(extra_file_defs=None, **kwargs): """ ), }, - setup_kwargs=dict( - scripts=['script.py', 'script.sh'], - ), - install_tree=flatten_tree({ + 'setup_kwargs': { + 'scripts': ['script.py', 'script.sh'], + }, + 'install_tree': flatten_tree({ 'foo-1.0-py{py_version}.egg': { 'EGG-INFO': [ 'PKG-INFO', @@ -683,7 +683,7 @@ def build_wheel(extra_file_defs=None, **kwargs): ] } }), - ) + } project_name = params.get('name', 'foo') version = params.get('version', '1.0') diff --git a/setuptools/wheel.py b/setuptools/wheel.py index c7ca43b5cf..3ca9c109cf 100644 --- a/setuptools/wheel.py +++ b/setuptools/wheel.py @@ -178,10 +178,10 @@ def raw_req(req): os.path.join(egg_info, 'PKG-INFO'), ) setup_dist = setuptools.Distribution( - attrs=dict( - install_requires=install_requires, - extras_require=extras_require, - ), + attrs={ + "install_requires": install_requires, + "extras_require": extras_require, + }, ) with disable_info_traces(): write_requirements( diff --git a/tools/finalize.py b/tools/finalize.py index d646e67cd0..27471c7e25 100644 --- a/tools/finalize.py +++ b/tools/finalize.py @@ -37,7 +37,7 @@ def _repair_changelog(): """ changelog_fn = pathlib.Path('NEWS.rst') changelog = changelog_fn.read_text(encoding='utf-8') - fixed = re.sub(r'^(v[0-9.]+)v[0-9.]+$', r'\1', changelog, flags=re.M) + fixed = re.sub(r'^(v[0-9.]+)v[0-9.]+$', r'\1', changelog, flags=re.MULTILINE) changelog_fn.write_text(fixed, encoding='utf-8') subprocess.check_output(['git', 'add', changelog_fn])