Skip to content

Commit 16644af

Browse files
authored
switch to ruff and format codebase (#32)
1 parent 5b63705 commit 16644af

File tree

13 files changed

+49
-57
lines changed

13 files changed

+49
-57
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929

30+
- name: Run linting
31+
run: |
32+
make lint
33+
3034
- name: Run tests
3135
run: |
3236
make test

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ clean:
2020
clean-dist: clean
2121
rm -rf dist/
2222

23-
format:
24-
$(VENV_ACTIVATE); python -m isort .; python -m black .
23+
lint: venv
24+
$(VENV_ACTIVATE); python -m ruff check .
25+
26+
format: venv
27+
$(VENV_ACTIVATE); python -m ruff format . && python -m ruff check . --fix
2528

2629
test: venv
2730
$(VENV_ACTIVATE); python -m pytest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Plux
55
<a href="https://github.com/localstack/plux/actions/workflows/build.yml"><img alt="CI badge" src="https://github.com/localstack/plux/actions/workflows/build.yml/badge.svg"></img></a>
66
<a href="https://pypi.org/project/plux/"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/plux?color=blue"></a>
77
<a href="https://img.shields.io/pypi/l/plux.svg"><img alt="PyPI License" src="https://img.shields.io/pypi/l/plux.svg"></a>
8-
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
8+
<a href="https://github.com/astral-sh/ruff"><img alt="Code style: ruff" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json"></a>
99
</p>
1010

1111
plux is the dynamic code loading framework used in [LocalStack](https://github.com/localstack/localstack).

plux/build/config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Module for our config wrapper. Currently, this only supports ``pyproject.toml`` files but could be extended in the
33
future to support ``tox.ini``, ``setup.cfg``, etc.
44
"""
5+
56
import dataclasses
67
import enum
78
import os
@@ -18,6 +19,7 @@ class EntrypointBuildMode(enum.Enum):
1819
The alternative is ``manual``, where build hooks are disabled and the user is responsible for generating and
1920
referencing entry points.
2021
"""
22+
2123
MANUAL = "manual"
2224
BUILD_HOOK = "build-hook"
2325

@@ -54,8 +56,12 @@ def merge(
5456
return PluxConfiguration(
5557
path=path if path is not None else self.path,
5658
exclude=list(set((exclude if exclude is not None else []) + self.exclude)),
57-
entrypoint_build_mode=entrypoint_build_mode if entrypoint_build_mode is not None else self.entrypoint_build_mode,
58-
entrypoint_static_file=entrypoint_static_file if entrypoint_static_file is not None else self.entrypoint_static_file,
59+
entrypoint_build_mode=entrypoint_build_mode
60+
if entrypoint_build_mode is not None
61+
else self.entrypoint_build_mode,
62+
entrypoint_static_file=entrypoint_static_file
63+
if entrypoint_static_file is not None
64+
else self.entrypoint_static_file,
5965
)
6066

6167

plux/build/discovery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Buildtool independent utils to discover plugins from the codebase, and write index files.
33
"""
4+
45
import configparser
56
import inspect
67
import json

plux/build/setuptools.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Bindings to integrate plux into setuptools build processes.
33
"""
4+
45
import importlib
56
import json
67
import logging
@@ -30,6 +31,7 @@ def run(self):
3031
def _ensure_dist_info(self, *args, **kwargs):
3132
pass
3233

34+
3335
from setuptools.command.egg_info import InfoCommon, write_entries
3436

3537
from plux.core.entrypoint import EntryPointDict, discover_entry_points
@@ -44,6 +46,7 @@ def _ensure_dist_info(self, *args, **kwargs):
4446
# The following classes and methods are a way for plux to hook into
4547
# the setuptools build process either indirectly or programmatically.
4648

49+
4750
class plugins(InfoCommon, setuptools.Command):
4851
"""
4952
Setuptools command that discovers plugins and writes them into the egg_info directory to a ``plux.json`` file.
@@ -57,11 +60,15 @@ class plugins(InfoCommon, setuptools.Command):
5760
``patch_egg_info_command`` where we could implement this logic. More background can be found here:
5861
https://github.com/pypa/setuptools/discussions/4223.
5962
"""
63+
6064
description = "Discover plux plugins and store them in .egg_info"
6165

6266
user_options: t.ClassVar[t.List[t.Tuple[str, str, str]]] = [
63-
('exclude=', 'e',
64-
"a sequence of paths to exclude; '*' can be used as a wildcard in the names. 'foo.*' will exclude all subpackages of 'foo' (but not 'foo' itself)."),
67+
(
68+
"exclude=",
69+
"e",
70+
"a sequence of paths to exclude; '*' can be used as a wildcard in the names. 'foo.*' will exclude all subpackages of 'foo' (but not 'foo' itself).",
71+
),
6572
# TODO: add more
6673
]
6774

@@ -84,7 +91,7 @@ def finalize_options(self) -> None:
8491
)
8592

8693
def run(self) -> None:
87-
index_builder = create_plugin_index_builder(self.plux_config,self.distribution, output_format="json")
94+
index_builder = create_plugin_index_builder(self.plux_config, self.distribution, output_format="json")
8895

8996
self.debug_print(f"writing discovered plugins into {self.plux_json_path}")
9097
self.mkpath(os.path.dirname(self.plux_json_path))
@@ -233,14 +240,10 @@ def find_plugins(where=".", exclude=(), include=("*",)) -> EntryPointDict:
233240
)
234241
"""
235242

236-
return discover_entry_points(
237-
PackagePathPluginFinder(where=where, exclude=exclude, include=include)
238-
)
243+
return discover_entry_points(PackagePathPluginFinder(where=where, exclude=exclude, include=include))
239244

240245

241-
def load_entry_points(
242-
where=".", exclude=(), include=("*",), merge: EntryPointDict = None
243-
) -> EntryPointDict:
246+
def load_entry_points(where=".", exclude=(), include=("*",), merge: EntryPointDict = None) -> EntryPointDict:
244247
"""
245248
Finds plugins and builds and entry point map. This is to be used in a setup.py in the setup call:
246249
@@ -289,6 +292,7 @@ def load_entry_points(
289292
# =========
290293
# The remaining methods are utilities
291294

295+
292296
def get_plux_json_path(distribution: setuptools.Distribution) -> str:
293297
"""
294298
Returns the full path of ``plux.json`` file for the given distribution. The file is located within the .egg-info
@@ -327,11 +331,10 @@ def update_entrypoints(distribution: setuptools.Distribution, ep: EntryPointDict
327331
distribution.entry_points.update(ep)
328332

329333

330-
331334
def create_plugin_index_builder(
332335
cfg: config.PluxConfiguration,
333336
distribution: setuptools.Distribution,
334-
output_format: t.Literal["json", "ini"] = "json"
337+
output_format: t.Literal["json", "ini"] = "json",
335338
) -> PluginIndexBuilder:
336339
"""
337340
Creates a PluginIndexBuilder instance for discovering plugins from a setuptools distribution. It uses a

plux/cli/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ def main(argv=None):
101101
subparsers = parser.add_subparsers(title="commands", dest="command", help="Available commands")
102102

103103
# Subparser for the 'generate' subcommand
104-
generate_parser = subparsers.add_parser(
105-
"entrypoints", help="Discover plugins and generate entry points"
106-
)
104+
generate_parser = subparsers.add_parser("entrypoints", help="Discover plugins and generate entry points")
107105
generate_parser.add_argument(
108106
"-e",
109107
"--exclude",

plux/core/plugin.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ def __repr__(self):
8585
return self.__str__()
8686

8787
def __eq__(self, other):
88-
return (
89-
self.namespace == other.namespace
90-
and self.name == other.name
91-
and self.factory == other.factory
92-
)
88+
return self.namespace == other.namespace and self.name == other.name and self.factory == other.factory
9389

9490

9591
class PluginFinder(abc.ABC):
@@ -231,7 +227,7 @@ def load(self, *args, **kwargs):
231227

232228
def should_load(self) -> bool:
233229
if self._should_load is not None:
234-
if type(self._should_load) == bool:
230+
if type(self._should_load) is bool:
235231
return self._should_load
236232
else:
237233
return self._should_load()

plux/runtime/manager.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ def __init__(
197197
if not filters:
198198
self.filters = [global_plugin_filter]
199199

200-
self.finder = finder or MetadataPluginFinder(
201-
self.namespace, self._fire_on_resolve_exception
202-
)
200+
self.finder = finder or MetadataPluginFinder(self.namespace, self._fire_on_resolve_exception)
203201

204202
self._plugin_index = None
205203
self._init_mutex = threading.RLock()
@@ -234,9 +232,7 @@ def load(self, name: str) -> P:
234232
raise container.load_error
235233

236234
if not container.is_loaded:
237-
raise PluginException(
238-
"plugin did not load correctly", namespace=self.namespace, name=name
239-
)
235+
raise PluginException("plugin did not load correctly", namespace=self.namespace, name=name)
240236

241237
return container.plugin
242238

plux/runtime/resolve.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def to_plugin_spec(self, entry_point: EntryPoint) -> PluginSpec:
4949
return self.spec_resolver.resolve(source)
5050
except Exception as e:
5151
if LOG.isEnabledFor(logging.DEBUG):
52-
LOG.exception(
53-
"error resolving PluginSpec for plugin %s.%s", self.namespace, entry_point.name
54-
)
52+
LOG.exception("error resolving PluginSpec for plugin %s.%s", self.namespace, entry_point.name)
5553

5654
if self.on_resolve_exception_callback:
5755
self.on_resolve_exception_callback(self.namespace, entry_point, e)

0 commit comments

Comments
 (0)