Skip to content

Commit

Permalink
Apply a few ruff/refurb rules (FURB)
Browse files Browse the repository at this point in the history
I have fixed the few cases which I think result in more readable code.
  • Loading branch information
DimitriPapadopoulos committed May 19, 2024
1 parent ae8c3fb commit 09a0a1f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def build_bootstrap(

if self.config.scripts:
for script in self.config.scripts:
env = dict(base_env)
env = base_env.copy()
env['PYAPP_EXEC_SPEC'] = self.metadata.core.scripts[script]

self.cargo_build(install_command, cwd=context_dir, env=env)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def safe_walk(path: str) -> Iterable[tuple[str, list[str], list[str]]]:
stat = os.stat(root)
identifier = stat.st_dev, stat.st_ino
if identifier in seen:
del dirs[:]
dirs.clear()
continue

seen.add(identifier)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/dep/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def dependency_in_sync(
if extra not in available_extras:
return False

extra_environment = dict(environment)
extra_environment = environment.copy()
extra_environment['extra'] = extra
if not dependency_in_sync(transitive_requirement, extra_environment, installed_distributions):
return False
Expand Down
11 changes: 5 additions & 6 deletions src/hatch/cli/new/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ def new(app, name, location, interactive, feature_cli, initialize, setuptools_op

template_classes = app.plugins.template.collect()

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

if not templates:
app.abort(f'None of the defined plugins were found: {", ".join(sorted(plugin_config))}')
Expand Down
2 changes: 1 addition & 1 deletion src/hatch/template/files_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PyProject(File):
"""

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

project_url_data = ''
Expand Down
2 changes: 1 addition & 1 deletion src/hatch/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def long_id(self) -> str:
from hashlib import sha256

path = str(self)
if sys.platform == 'win32' or sys.platform == 'darwin':
if sys.platform in {'win32', 'darwin'}:
path = path.casefold()

digest = sha256(path.encode('utf-8')).digest()
Expand Down
6 changes: 1 addition & 5 deletions tests/cli/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def remove_metadata_field(field: str, metadata_file_contents: str):
lines = metadata_file_contents.splitlines(True)

field_marker = f'{field}: '
indices_to_remove = []

for i, line in enumerate(lines):
if line.lower().startswith(field_marker):
indices_to_remove.append(i)
indices_to_remove = (i for i, line in enumerate(lines) if line.lower().startswith(field_marker))

for i, index in enumerate(indices_to_remove):
del lines[index - i]
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers/templates/wheel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def update_record_file_contents(record_file, files, generated_files=()):
):
raw_contents = raw_contents.replace(b'\n', b'\r\n')

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

Expand Down

0 comments on commit 09a0a1f

Please sign in to comment.