Skip to content

Commit 9a5d83a

Browse files
Apply a few ruff/refurb rules (FURB)
I have fixed the few cases which I think result in more readable code.
1 parent ae8c3fb commit 9a5d83a

File tree

8 files changed

+12
-18
lines changed

8 files changed

+12
-18
lines changed

backend/src/hatchling/builders/binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def build_bootstrap(
157157

158158
if self.config.scripts:
159159
for script in self.config.scripts:
160-
env = dict(base_env)
160+
env = base_env.copy()
161161
env['PYAPP_EXEC_SPEC'] = self.metadata.core.scripts[script]
162162

163163
self.cargo_build(install_command, cwd=context_dir, env=env)

backend/src/hatchling/builders/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def safe_walk(path: str) -> Iterable[tuple[str, list[str], list[str]]]:
2424
stat = os.stat(root)
2525
identifier = stat.st_dev, stat.st_ino
2626
if identifier in seen:
27-
del dirs[:]
27+
dirs.clear()
2828
continue
2929

3030
seen.add(identifier)

backend/src/hatchling/dep/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def dependency_in_sync(
7070
if extra not in available_extras:
7171
return False
7272

73-
extra_environment = dict(environment)
73+
extra_environment = environment.copy()
7474
extra_environment['extra'] = extra
7575
if not dependency_in_sync(transitive_requirement, extra_environment, installed_distributions):
7676
return False

src/hatch/cli/new/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ def new(app, name, location, interactive, feature_cli, initialize, setuptools_op
100100

101101
template_classes = app.plugins.template.collect()
102102

103-
templates = []
104-
for template_name, template_class in sorted(template_classes.items(), key=lambda item: -item[1].PRIORITY):
105-
if template_name in plugin_config:
106-
templates.append(
107-
template_class(plugin_config.pop(template_name), app.cache_dir, datetime.now(timezone.utc))
108-
)
103+
templates = [
104+
template_class(plugin_config.pop(template_name), app.cache_dir, datetime.now(timezone.utc))
105+
for template_name, template_class in sorted(template_classes.items(), key=lambda item: -item[1].PRIORITY)
106+
if template_name in plugin_config
107+
]
109108

110109
if not templates:
111110
app.abort(f'None of the defined plugins were found: {", ".join(sorted(plugin_config))}')

src/hatch/template/files_default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class PyProject(File):
109109
"""
110110

111111
def __init__(self, template_config: dict, plugin_config: dict):
112-
template_config = dict(template_config)
112+
template_config = template_config.copy()
113113
template_config['name'] = repr(template_config['name'])[1:-1]
114114

115115
project_url_data = ''

src/hatch/utils/fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def long_id(self) -> str:
3838
from hashlib import sha256
3939

4040
path = str(self)
41-
if sys.platform == 'win32' or sys.platform == 'darwin':
41+
if sys.platform in {'win32', 'darwin'}:
4242
path = path.casefold()
4343

4444
digest = sha256(path.encode('utf-8')).digest()

tests/cli/publish/test_publish.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ def remove_metadata_field(field: str, metadata_file_contents: str):
3434
lines = metadata_file_contents.splitlines(True)
3535

3636
field_marker = f'{field}: '
37-
indices_to_remove = []
38-
39-
for i, line in enumerate(lines):
40-
if line.lower().startswith(field_marker):
41-
indices_to_remove.append(i)
37+
indices_to_remove = (i for i, line in enumerate(lines) if line.lower().startswith(field_marker))
4238

4339
for i, index in enumerate(indices_to_remove):
4440
del lines[index - i]

tests/helpers/templates/wheel/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def update_record_file_contents(record_file, files, generated_files=()):
3636
):
3737
raw_contents = raw_contents.replace(b'\n', b'\r\n')
3838

39-
hash_obj = hashlib.sha256()
40-
hash_obj.update(raw_contents)
39+
hash_obj = hashlib.sha256(raw_contents)
4140
hash_digest = format_file_hash(hash_obj.digest())
4241
record_file.contents += f'{template_file.path.as_posix()},sha256={hash_digest},{len(raw_contents)}\n'
4342

0 commit comments

Comments
 (0)