Skip to content

Commit

Permalink
perf: apply PERF lint rules fixes (copier-org#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Mar 16, 2024
1 parent 7a7f681 commit 4831baf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
14 changes: 4 additions & 10 deletions copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
from pathlib import Path
from shutil import rmtree
from tempfile import TemporaryDirectory
from typing import (
Callable,
Iterable,
Literal,
Mapping,
Sequence,
get_args,
)
from typing import Callable, Iterable, Literal, Mapping, Sequence, get_args
from unicodedata import normalize

from jinja2.loaders import FileSystemLoader
Expand Down Expand Up @@ -963,8 +956,9 @@ def _apply_update(self): # noqa: C901
perms_sha_mode, path = line.split("\t")
perms, sha, _ = perms_sha_mode.split()
input_lines.append(f"0 {'0' * 40}\t{path}")
for mode in (1, 2, 3):
input_lines.append(f"{perms} {sha} {mode}\t{path}")
input_lines.extend(
f"{perms} {sha} {mode}\t{path}" for mode in (1, 2, 3)
)
(
git["update-index", "--index-info"]
<< "\n".join(input_lines)
Expand Down
14 changes: 6 additions & 8 deletions copier/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ def _include(loader: yaml.Loader, node: yaml.Node) -> Any:
"_skip_if_exists",
):
for result in flattened_result:
try:
values = result[option]
except KeyError:
pass
else:
merged_options[option].extend(values)
if option in result:
merged_options[option].extend(result[option])

return dict(ChainMap(dict(merged_options), *reversed(flattened_result)))

Expand Down Expand Up @@ -391,8 +387,10 @@ def migration_tasks(
"VERSION_CURRENT": migration["version"],
"VERSION_PEP440_CURRENT": str(current),
}
for cmd in migration.get(stage, []):
result.append(Task(cmd=cmd, extra_env=extra_env))
result.extend(
Task(cmd=cmd, extra_env=extra_env)
for cmd in migration.get(stage, [])
)
return result

@cached_property
Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ style = "pep440"
vcs = "git"

[tool.ruff.lint]
extend-select = ["ARG", "B", "C90", "D", "E", "F", "FA", "I", "PGH", "UP"]
extend-select = [
"ARG",
"B",
"C90",
"D",
"E",
"F",
"FA",
"I",
"PERF",
"PGH",
"UP",
]
extend-ignore = ['B028', "B904", "D105", "D107", "E501"]

[tool.ruff.lint.per-file-ignores]
Expand Down

0 comments on commit 4831baf

Please sign in to comment.