Skip to content

Commit

Permalink
Ruff rules for comprehensions and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Dec 15, 2024
1 parent 902c495 commit 64e3dcc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.9"
rev: "v0.8.3"
hooks:
- id: ruff
args: [--fix]
Expand Down
9 changes: 4 additions & 5 deletions micropip/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def install(
if isinstance(requirements, str):
requirements = [requirements]

fetch_kwargs = dict()
fetch_kwargs = {}

if credentials:
fetch_kwargs["credentials"] = credentials
Expand Down Expand Up @@ -84,10 +84,9 @@ async def install(
)

# Now install PyPI packages
for wheel in transaction.wheels:
# detect whether the wheel metadata is from PyPI or from custom location
# wheel metadata from PyPI has SHA256 checksum digest.
wheel_promises.append(wheel.install(wheel_base))
# detect whether the wheel metadata is from PyPI or from custom location
# wheel metadata from PyPI has SHA256 checksum digest.
wheel_promises.extend(wheel.install(wheel_base) for wheel in transaction.wheels)

await asyncio.gather(*wheel_promises)

Expand Down
3 changes: 1 addition & 2 deletions micropip/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def format_row(values, widths, filler=""):

rows.append(format_row(headers, col_width))
rows.append(format_row([""] * len(col_width), col_width, filler="-"))
for line in table:
rows.append(format_row(line, col_width))
rows.extend(format_row(line, col_width) for line in table)

return "\n".join(rows)

Expand Down
8 changes: 4 additions & 4 deletions micropip/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ async def gather_requirements(
self,
requirements: list[str] | list[Requirement],
) -> None:
requirement_promises = []
for requirement in requirements:
requirement_promises.append(self.add_requirement(requirement))
requirement_promises = [
self.add_requirement(requirement) for requirement in requirements
]

await asyncio.gather(*requirement_promises)

Expand Down Expand Up @@ -132,7 +132,7 @@ def eval_marker(e: dict[str, str]) -> bool:
# self.ctx_extras is empty and hence the eval_marker() function
# will not be called at all.
if not req.marker.evaluate(self.ctx) and not any(
[eval_marker(e) for e in self.ctx_extras]
eval_marker(e) for e in self.ctx_extras
):
return
# Is some version of this package is already installed?
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ lint.select = [
"B0", # bugbear (all B0* checks enabled by default)
"B904", # bugbear (Within an except clause, raise exceptions with raise ... from err)
"B905", # bugbear (zip() without an explicit strict= parameter set.)
"C4", # flake8-comprehensions
"C90", # mccabe code complexity
"PERF", # perflint
"UP", # pyupgrade
"I", # isort
"PGH", # pygrep-hooks
"G", # flake8-logging-format
]
# Remove E999 once pattern matching is supported
# https://github.com/charliermarsh/ruff/issues/282
lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true
lint.ignore = ["E402", "E501", "E731", "E741", "E999"]
lint.mccabe.max-complexity = 13
target-version = "py311"


Expand Down
2 changes: 1 addition & 1 deletion tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async def test_install_with_credentials(selenium):
fetch_response_mock = MagicMock()

async def myfunc():
return json.dumps(dict())
return json.dumps({})

fetch_response_mock.string.side_effect = myfunc

Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_Metadata_requires(metadata_path, extras, expected):
m = Metadata(metadata)

reqs = m.requires(extras)
reqs_set = set([r.name for r in reqs])
reqs_set = {r.name for r in reqs}
assert reqs_set == set(expected)


Expand Down

0 comments on commit 64e3dcc

Please sign in to comment.