Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
Ran `ruff --format` on the code.
  • Loading branch information
jaraco committed Feb 12, 2024
1 parent 1bd78d0 commit 7f70d7d
Show file tree
Hide file tree
Showing 51 changed files with 181 additions and 164 deletions.
8 changes: 3 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@


if platform.system() != 'Windows':
collect_ignore.extend(
[
'distutils/msvc9compiler.py',
]
)
collect_ignore.extend([
'distutils/msvc9compiler.py',
])


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion distutils/bcppcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# someone should sit down and factor out the common code as
# WindowsCCompiler! --GPW


import os
import warnings

Expand Down
6 changes: 5 additions & 1 deletion distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,11 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''):
return os.path.join(output_dir, basename + (self.exe_extension or ''))

def library_filename(
self, libname, lib_type='static', strip_dir=0, output_dir='' # or 'shared'
self,
libname,
lib_type='static',
strip_dir=0,
output_dir='', # or 'shared'
):
assert output_dir is not None
expected = '"static", "shared", "dylib", "xcode_stub"'
Expand Down
1 change: 0 additions & 1 deletion distutils/command/_framework_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Backward compatibility for homebrew builds on macOS.
"""


import sys
import os
import functools
Expand Down
20 changes: 9 additions & 11 deletions distutils/command/bdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ class bdist(Command):
default_format = {'posix': 'gztar', 'nt': 'zip'}

# Define commands in preferred order for the --help-formats option
format_commands = ListCompat(
{
'rpm': ('bdist_rpm', "RPM distribution"),
'gztar': ('bdist_dumb', "gzip'ed tar file"),
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
'xztar': ('bdist_dumb', "xz'ed tar file"),
'ztar': ('bdist_dumb', "compressed tar file"),
'tar': ('bdist_dumb', "tar file"),
'zip': ('bdist_dumb', "ZIP file"),
}
)
format_commands = ListCompat({
'rpm': ('bdist_rpm', "RPM distribution"),
'gztar': ('bdist_dumb', "gzip'ed tar file"),
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
'xztar': ('bdist_dumb', "xz'ed tar file"),
'ztar': ('bdist_dumb', "compressed tar file"),
'tar': ('bdist_dumb', "tar file"),
'zip': ('bdist_dumb', "ZIP file"),
})

# for compatibility until consumers only reference format_commands
format_command = format_commands
Expand Down
84 changes: 37 additions & 47 deletions distutils/command/bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,11 @@ def run(self): # noqa: C901
if os.path.exists(rpm):
self.move_file(rpm, self.dist_dir)
filename = os.path.join(self.dist_dir, os.path.basename(rpm))
self.distribution.dist_files.append(
('bdist_rpm', pyversion, filename)
)
self.distribution.dist_files.append((
'bdist_rpm',
pyversion,
filename,
))

def _dist_path(self, path):
return os.path.join(self.dist_dir, os.path.basename(path))
Expand All @@ -428,9 +430,9 @@ def _make_spec_file(self): # noqa: C901
# Generate a potential replacement value for __os_install_post (whilst
# normalizing the whitespace to simplify the test for whether the
# invocation of brp-python-bytecompile passes in __python):
vendor_hook = '\n'.join(
[' %s \\' % line.strip() for line in vendor_hook.splitlines()]
)
vendor_hook = '\n'.join([
' %s \\' % line.strip() for line in vendor_hook.splitlines()
])
problem = "brp-python-bytecompile \\\n"
fixed = "brp-python-bytecompile %{__python} \\\n"
fixed_hook = vendor_hook.replace(problem, fixed)
Expand All @@ -445,13 +447,11 @@ def _make_spec_file(self): # noqa: C901
# spec_file.append('Summary(%s): %s' % (locale,
# self.summaries[locale]))

spec_file.extend(
[
'Name: %{name}',
'Version: %{version}',
'Release: %{release}',
]
)
spec_file.extend([
'Name: %{name}',
'Version: %{version}',
'Release: %{release}',
])

# XXX yuck! this filename is available from the "sdist" command,
# but only after it has run: and we create the spec file before
Expand All @@ -461,14 +461,12 @@ def _make_spec_file(self): # noqa: C901
else:
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')

spec_file.extend(
[
'License: ' + (self.distribution.get_license() or "UNKNOWN"),
'Group: ' + self.group,
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
'Prefix: %{_prefix}',
]
)
spec_file.extend([
'License: ' + (self.distribution.get_license() or "UNKNOWN"),
'Group: ' + self.group,
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
'Prefix: %{_prefix}',
])

if not self.force_arch:
# noarch if no extension modules
Expand Down Expand Up @@ -506,13 +504,11 @@ def _make_spec_file(self): # noqa: C901
if self.no_autoreq:
spec_file.append('AutoReq: 0')

spec_file.extend(
[
'',
'%description',
self.distribution.get_long_description() or "",
]
)
spec_file.extend([
'',
'%description',
self.distribution.get_long_description() or "",
])

# put locale descriptions into spec file
# XXX again, suppressed because config file syntax doesn't
Expand Down Expand Up @@ -558,37 +554,31 @@ def _make_spec_file(self): # noqa: C901
# use 'default' as contents of script
val = getattr(self, attr)
if val or default:
spec_file.extend(
[
'',
'%' + rpm_opt,
]
)
spec_file.extend([
'',
'%' + rpm_opt,
])
if val:
with open(val) as f:
spec_file.extend(f.read().split('\n'))
else:
spec_file.append(default)

# files section
spec_file.extend(
[
'',
'%files -f INSTALLED_FILES',
'%defattr(-,root,root)',
]
)
spec_file.extend([
'',
'%files -f INSTALLED_FILES',
'%defattr(-,root,root)',
])

if self.doc_files:
spec_file.append('%doc ' + ' '.join(self.doc_files))

if self.changelog:
spec_file.extend(
[
'',
'%changelog',
]
)
spec_file.extend([
'',
'%changelog',
])
spec_file.extend(self.changelog)

return spec_file
Expand Down
6 changes: 3 additions & 3 deletions distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def find_data_files(self, package, src_dir):
os.path.join(glob.escape(src_dir), convert_path(pattern))
)
# Files that match more than one pattern are only added once
files.extend(
[fn for fn in filelist if fn not in files and os.path.isfile(fn)]
)
files.extend([
fn for fn in filelist if fn not in files and os.path.isfile(fn)
])
return files

def build_package_data(self):
Expand Down
10 changes: 7 additions & 3 deletions distutils/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Implements the Distutils 'check' command.
"""

import contextlib

from ..core import Command
Expand Down Expand Up @@ -144,8 +145,11 @@ def _check_rst_data(self, data):
try:
parser.parse(data, document)
except AttributeError as e:
reporter.messages.append(
(-1, 'Could not finish the parsing: %s.' % e, '', {})
)
reporter.messages.append((
-1,
'Could not finish the parsing: %s.' % e,
'',
{},
))

return reporter.messages
35 changes: 19 additions & 16 deletions distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ class install(Command):
boolean_options = ['compile', 'force', 'skip-build']

if HAS_USER_SITE:
user_options.append(
('user', None, "install in user site-package '%s'" % USER_SITE)
)
user_options.append((
'user',
None,
"install in user site-package '%s'" % USER_SITE,
))
boolean_options.append('user')

negative_opt = {'no-compile': 'compile'}
Expand Down Expand Up @@ -432,9 +434,12 @@ def finalize_options(self): # noqa: C901
local_vars['userbase'] = self.install_userbase
local_vars['usersite'] = self.install_usersite

self.config_vars = _collections.DictStack(
[fw.vars(), compat_vars, sysconfig.get_config_vars(), local_vars]
)
self.config_vars = _collections.DictStack([
fw.vars(),
compat_vars,
sysconfig.get_config_vars(),
local_vars,
])

self.expand_basedirs()

Expand Down Expand Up @@ -620,16 +625,14 @@ def expand_basedirs(self):

def expand_dirs(self):
"""Calls `os.path.expanduser` on install dirs."""
self._expand_attrs(
[
'install_purelib',
'install_platlib',
'install_lib',
'install_headers',
'install_scripts',
'install_data',
]
)
self._expand_attrs([
'install_purelib',
'install_platlib',
'install_lib',
'install_headers',
'install_scripts',
'install_data',
])

def convert_paths(self, *names):
"""Call `convert_path` over `names`."""
Expand Down
16 changes: 8 additions & 8 deletions distutils/command/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def check_metadata(self):
check.run()

def _set_config(self):
'''Reads the configuration file and set attributes.'''
"""Reads the configuration file and set attributes."""
config = self._read_pypirc()
if config != {}:
self.username = config['username']
Expand All @@ -93,19 +93,19 @@ def _set_config(self):
self.has_config = False

def classifiers(self):
'''Fetch the list of classifiers from the server.'''
"""Fetch the list of classifiers from the server."""
url = self.repository + '?:action=list_classifiers'
response = urllib.request.urlopen(url)
log.info(self._read_pypi_response(response))

def verify_metadata(self):
'''Send the metadata to the package index server to be checked.'''
"""Send the metadata to the package index server to be checked."""
# send the info to the server and report the result
(code, result) = self.post_to_server(self.build_post_data('verify'))
log.info('Server response (%s): %s', code, result)

def send_metadata(self): # noqa: C901
'''Send the metadata to the package index server.
"""Send the metadata to the package index server.
Well, do the following:
1. figure who the user is, and then
Expand All @@ -131,7 +131,7 @@ def send_metadata(self): # noqa: C901
2. register as a new user, or
3. set the password to a random string and email the user.
'''
"""
# see if we can short-cut and get the username/password from the
# config
if self.has_config:
Expand All @@ -146,13 +146,13 @@ def send_metadata(self): # noqa: C901
choices = '1 2 3 4'.split()
while choice not in choices:
self.announce(
'''\
"""\
We need to know who you are, so please choose either:
1. use your existing login,
2. register as a new user,
3. have the server generate a new password for you (and email it to you), or
4. quit
Your selection [default 1]: ''',
Your selection [default 1]: """,
logging.INFO,
)
choice = input()
Expand Down Expand Up @@ -262,7 +262,7 @@ def build_post_data(self, action):
return data

def post_to_server(self, data, auth=None): # noqa: C901
'''Post a query to the server, and return a string response.'''
"""Post a query to the server, and return a string response."""
if 'name' in data:
self.announce(
'Registering {} to {}'.format(data['name'], self.repository),
Expand Down
1 change: 1 addition & 0 deletions distutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Provides the PyPIRCCommand class, the base class for the command classes
that uses .pypirc in the distutils.command package.
"""

import os
from configparser import RawConfigParser

Expand Down
2 changes: 1 addition & 1 deletion distutils/cygwinccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def check_config_h():


def is_cygwincc(cc):
'''Try to determine if the compiler that would be used is from cygwin.'''
"""Try to determine if the compiler that would be used is from cygwin."""
out_string = check_output(shlex.split(cc) + ['-dumpmachine'])
return out_string.strip().endswith(b'cygwin')

Expand Down
2 changes: 1 addition & 1 deletion distutils/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
depends=None,
language=None,
optional=None,
**kw # To catch unknown keywords
**kw, # To catch unknown keywords
):
if not isinstance(name, str):
raise AssertionError("'name' must be a string")
Expand Down
Loading

0 comments on commit 7f70d7d

Please sign in to comment.