diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65c5080..a252010 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/micropip/install.py b/micropip/install.py index 6cf75a0..5e32b50 100644 --- a/micropip/install.py +++ b/micropip/install.py @@ -28,7 +28,7 @@ async def install( if isinstance(requirements, str): requirements = [requirements] - fetch_kwargs = dict() + fetch_kwargs = {} if credentials: fetch_kwargs["credentials"] = credentials @@ -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) diff --git a/micropip/package.py b/micropip/package.py index aa06464..d39afa8 100644 --- a/micropip/package.py +++ b/micropip/package.py @@ -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) diff --git a/micropip/transaction.py b/micropip/transaction.py index 9855db2..f29c48a 100644 --- a/micropip/transaction.py +++ b/micropip/transaction.py @@ -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) @@ -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? diff --git a/pyproject.toml b/pyproject.toml index 420e439..11f95f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,9 @@ 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 @@ -55,7 +58,9 @@ lint.select = [ ] # 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" diff --git a/tests/test_install.py b/tests/test_install.py index aa0d22e..9b7f7bc 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -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 diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 42fe80f..cf4d7a3 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -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)