From c6bc8e76906482b2c13d900520c271a4975b567b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 22 May 2024 14:53:16 +0200 Subject: [PATCH] Manual fixes after `ruff check --fix` runs --- pkg_resources/__init__.py | 11 +++++++---- setuptools/_core_metadata.py | 4 ++-- setuptools/command/bdist_egg.py | 2 +- setuptools/command/easy_install.py | 7 ++++--- setuptools/tests/config/test_setupcfg.py | 8 ++++---- setuptools/tests/test_build_ext.py | 4 ++-- setuptools/tests/test_egg_info.py | 7 ++++--- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index c9a58419425..b6212f96a51 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -213,7 +213,9 @@ def get_supported_platform(): m = macosVersionString.match(plat) if m is not None and sys.platform == "darwin": try: - plat = 'macosx-{}-{}'.format('.'.join(_macos_vers()[:2]), m.group(3)) + major_minor = '.'.join(_macos_vers()[:2]) + build = m.group(3) + plat = f'macosx-{major_minor}-{build}' except ValueError: # not macOS pass @@ -2723,7 +2725,8 @@ def __str__(self): if self.attrs: s += ':' + '.'.join(self.attrs) if self.extras: - s += ' [{}]'.format(','.join(self.extras)) + extras = ','.join(self.extras) + s += f' [{extras}]' return s def __repr__(self): @@ -3309,8 +3312,8 @@ def check_version_conflict(self): ): continue issue_warning( - f"Module {modname} was already imported from {fn}, but {self.location} is being added" - " to sys.path", + f"Module {modname} was already imported from {fn}, " + f"but {self.location} is being added to sys.path", ) def has_version(self): diff --git a/setuptools/_core_metadata.py b/setuptools/_core_metadata.py index a5e18a40064..642b80df317 100644 --- a/setuptools/_core_metadata.py +++ b/setuptools/_core_metadata.py @@ -178,8 +178,8 @@ def write_field(key, value): if license: write_field('License', rfc822_escape(license)) - for project_url in self.project_urls.items(): - write_field('Project-URL', '{}, {}'.format(*project_url)) + for label, url in self.project_urls.items(): + write_field('Project-URL', f'{label}, {url}') keywords = ','.join(self.get_keywords()) if keywords: diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 94eff236f89..cc5ed59a75f 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -60,7 +60,7 @@ def __bootstrap__(): class bdist_egg(Command): - description = "create an \"egg\" distribution" + description = 'create an "egg" distribution' user_options = [ ('bdist-dir=', 'b', "temporary directory for creating the distribution"), diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 3a6f3872de0..ed5d34129ee 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -131,8 +131,8 @@ class easy_install(Command): ( 'optimize=', 'O', - "also compile with optimization: -O1 for \"python -O\", " - "-O2 for \"python -OO\", and -O0 to disable [default: -O0]", + 'also compile with optimization: -O1 for "python -O", ' + '-O2 for "python -OO", and -O0 to disable [default: -O0]', ), ('record=', None, "filename in which to record list of installed files"), ('always-unzip', 'Z', "don't install as a zipfile, no matter what"), @@ -1021,7 +1021,8 @@ def install_exe(self, dist_filename, tmpdir): f.write('Metadata-Version: 1.0\n') for k, v in cfg.items('metadata'): if k != 'target_version': - f.write('{}: {}\n'.format(k.replace('_', '-').title(), v)) + k = k.replace('_', '-').title() + f.write(f'{k}: {v}\n') script_dir = os.path.join(_egg_info, 'scripts') # delete entry-point scripts to avoid duping self.delete_blockers([ diff --git a/setuptools/tests/config/test_setupcfg.py b/setuptools/tests/config/test_setupcfg.py index 68522caa415..8ba19c98201 100644 --- a/setuptools/tests/config/test_setupcfg.py +++ b/setuptools/tests/config/test_setupcfg.py @@ -87,14 +87,14 @@ def test_basic(self, tmpdir): '[options]\n' 'scripts = bin/a.py, bin/b.py\n', ) - config_dict = read_configuration(f'{config}') + config_dict = read_configuration(str(config)) assert config_dict['metadata']['version'] == '10.1.1' assert config_dict['metadata']['keywords'] == ['one', 'two'] assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py'] def test_no_config(self, tmpdir): with pytest.raises(DistutilsFileError): - read_configuration('{}'.format(tmpdir.join('setup.cfg'))) + read_configuration(str(tmpdir.join('setup.cfg'))) def test_ignore_errors(self, tmpdir): _, config = fake_env( @@ -102,9 +102,9 @@ def test_ignore_errors(self, tmpdir): '[metadata]\nversion = attr: none.VERSION\nkeywords = one, two\n', ) with pytest.raises(ImportError): - read_configuration(f'{config}') + read_configuration(str(config)) - config_dict = read_configuration(f'{config}', ignore_option_errors=True) + config_dict = read_configuration(str(config), ignore_option_errors=True) assert config_dict['metadata']['keywords'] == ['one', 'two'] assert 'version' not in config_dict['metadata'] diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py index cc28344d683..225d978f911 100644 --- a/setuptools/tests/test_build_ext.py +++ b/setuptools/tests/test_build_ext.py @@ -285,8 +285,8 @@ def test_build_ext_config_handling(tmpdir_cwd): ), } path.build(files) - code, output = environment.run_setup_py( + code, (stdout, stderr) = environment.run_setup_py( cmd=['build'], data_stream=(0, 2), ) - assert code == 0, '\nSTDOUT:\n{}\nSTDERR:\n{}'.format(*output) + assert code == 0, f'\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}' diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 16f2bf18505..926119c42d3 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -33,13 +33,14 @@ def env(): subs = 'home', 'lib', 'scripts', 'data', 'egg-base' env.paths = dict((dirname, os.path.join(env_dir, dirname)) for dirname in subs) list(map(os.mkdir, env.paths.values())) + egg_base = env.paths["egg-base"] path.build({ env.paths['home']: { '.pydistutils.cfg': DALS( - """ + f""" [egg_info] - egg-base = {egg-base} - """.format(**env.paths) + egg-base = {egg_base} + """ ) } })