Skip to content

Commit

Permalink
ci: run slotscheck cli as ci job (#3275)
Browse files Browse the repository at this point in the history
This PR moves running slotscheck from within pre-commit to its own job in ci (same as we've done with other tools that require the configured environment to run).

This partially fixes an issue identified in #3251 where the `litestar` package was inadvertently excluded from this check due to an incorrect regex pattern.

Applies fixes for issues identified by the tool.

Co-authored-by: Arie Bovenberg <a.c.bovenberg@gmail.com>
  • Loading branch information
peterschutt and ariebovenberg authored Mar 28, 2024
1 parent b38f530 commit d2cb891
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 25 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ jobs:
- name: Run pyright
run: pdm run pyright

slotscheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.8"
allow-prereleases: false

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
with:
python-version: "3.8"
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: pdm install -G:all

- name: Run slotscheck
run: pdm run slotscheck litestar

test:
name: "test (${{ matrix.python-version }})"
strategy:
Expand Down
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ repos:
- id: ensure-dunder-all
exclude: "test*|examples*|tools"
args: ["--use-tuple"]
- repo: https://github.com/ariebovenberg/slotscheck
rev: v0.19.0
hooks:
- id: slotscheck
exclude: "test_*|docs|.github"
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.9.1"
hooks:
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ pre-commit: ## Runs pre-commit hooks; includes ruff formatting and lin
@$(PDM) run pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: slots-check
slots-check: ## Check for slots usage in classes
@echo "=> Checking for slots usage in classes"
@$(PDM) run slotscheck litestar
@echo "=> Slots check complete"

.PHONY: lint
lint: pre-commit type-check ## Run all linting
lint: pre-commit type-check slots-check ## Run all linting

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
Expand Down
4 changes: 0 additions & 4 deletions litestar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,17 @@ class Litestar(Router):
"csrf_config",
"event_emitter",
"get_logger",
"include_in_schema",
"logger",
"logging_config",
"multipart_form_part_limit",
"on_shutdown",
"on_startup",
"openapi_config",
"request_class",
"response_cache_config",
"route_map",
"signature_namespace",
"state",
"stores",
"template_engine",
"websocket_class",
"pdb_on_exception",
"experimental_features",
)
Expand Down
2 changes: 0 additions & 2 deletions litestar/contrib/opentelemetry/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
class OpenTelemetryInstrumentationMiddleware(AbstractMiddleware):
"""OpenTelemetry Middleware."""

__slots__ = ("open_telemetry_middleware",)

def __init__(self, app: ASGIApp, config: OpenTelemetryConfig) -> None:
"""Middleware that adds OpenTelemetry instrumentation to the application.
Expand Down
3 changes: 0 additions & 3 deletions litestar/dto/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ class MappingType(CompositeType):
@dataclass(frozen=True)
class TransferDTOFieldDefinition(DTOFieldDefinition):
__slots__ = (
"default_factory",
"dto_field",
"model_name",
"is_excluded",
"is_partial",
"serialization_name",
Expand Down
5 changes: 2 additions & 3 deletions litestar/handlers/websocket_handlers/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ class WebsocketListenerRouteHandler(WebsocketRouteHandler):
"connection_accept_handler": "Callback to accept a WebSocket connection. By default, calls WebSocket.accept",
"on_accept": "Callback invoked after a WebSocket connection has been accepted",
"on_disconnect": "Callback invoked after a WebSocket connection has been closed",
"weboscket_class": "WebSocket class",
"_connection_lifespan": None,
"_handle_receive": None,
"_handle_send": None,
"_receive_handler": None,
"_receive_mode": None,
"_send_handler": None,
"_send_mode": None,
}

Expand Down
2 changes: 2 additions & 0 deletions litestar/handlers/websocket_handlers/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WebsocketRouteHandler(BaseRouteHandler):
Use this decorator to decorate websocket handler functions.
"""

__slots__ = ("websocket_class",)

def __init__(
self,
path: str | list[str] | None = None,
Expand Down
2 changes: 2 additions & 0 deletions litestar/middleware/compression/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class CompressionFacade(Protocol):
"""A unified facade offering a uniform interface for different compression libraries."""

__slots__ = ()

encoding: ClassVar[str]
"""The encoding of the compression."""

Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
class CORSMiddleware(AbstractMiddleware):
"""CORS Middleware."""

__slots__ = ("config",)

def __init__(self, app: ASGIApp, config: CORSConfig) -> None:
"""Middleware that adds CORS validation to the application.
Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
class LoggingMiddleware(AbstractMiddleware):
"""Logging middleware."""

__slots__ = ("config", "logger", "request_extractor", "response_extractor", "is_struct_logger")

logger: Logger

def __init__(self, app: ASGIApp, config: LoggingMiddlewareConfig) -> None:
Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class CacheObject:
class RateLimitMiddleware(AbstractMiddleware):
"""Rate-limiting middleware."""

__slots__ = ("app", "check_throttle_handler", "max_requests", "unit", "request_quota", "config")

def __init__(self, app: ASGIApp, config: RateLimitConfig) -> None:
"""Initialize ``RateLimitMiddleware``.
Expand Down
2 changes: 2 additions & 0 deletions litestar/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def to_openapi_schema(self, field_definition: FieldDefinition, schema_creator: S
class OpenAPISchemaPlugin(OpenAPISchemaPluginProtocol):
"""Plugin to extend the support of OpenAPI schema generation for non-library types."""

__slots__ = ()

@staticmethod
def is_plugin_supported_type(value: Any) -> bool:
"""Given a value of indeterminate type, determine if this value is supported by the plugin.
Expand Down
4 changes: 4 additions & 0 deletions litestar/stores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
class Store(ABC):
"""Thread and process safe asynchronous key/value store."""

__slots__ = ()

@abstractmethod
async def set(self, key: str, value: str | bytes, expires_in: int | timedelta | None = None) -> None:
"""Set a value.
Expand Down Expand Up @@ -97,6 +99,8 @@ class NamespacedStore(Store):
should be isolated.
"""

__slots__ = ("namespace",)

@abstractmethod
def with_namespace(self, namespace: str) -> Self:
"""Return a new instance of :class:`NamespacedStore`, which exists in a child namespace of the current namespace.
Expand Down
7 changes: 6 additions & 1 deletion litestar/stores/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
class RedisStore(NamespacedStore):
"""Redis based, thread and process safe asynchronous key/value store."""

__slots__ = ("_redis",)
__slots__ = (
"_delete_all_script",
"_get_and_renew_script",
"_redis",
"handle_client_shutdown",
)

def __init__(
self, redis: Redis, namespace: str | None | EmptyType = Empty, handle_client_shutdown: bool = False
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ reportUnnecessaryTypeIgnoreComments = true

[tool.slotscheck]
strict-imports = false
exclude-classes = """
(
# github.com/python/cpython/pull/106771
(^litestar.events.emitter:BaseEventEmitterBackend)
)
"""

[tool.ruff]
lint.select = [
Expand Down

0 comments on commit d2cb891

Please sign in to comment.