diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1409e7a0..5d1550cc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Install build dependencies run: pip install build - name: Build distribution diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec0f35b7..17a4efca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Test run: pytest --cov=ninja_extra --cov-report=xml tests - name: Coverage diff --git a/.github/workflows/test_full.yml b/.github/workflows/test_full.yml index b7b8a593..e22ddaa6 100644 --- a/.github/workflows/test_full.yml +++ b/.github/workflows/test_full.yml @@ -46,7 +46,7 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Ruff Linting Check run: ruff check ninja_extra tests - name: mypy diff --git a/Makefile b/Makefile index 3afb3629..16856368 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,11 @@ clean: ## Removing cached python compiled files find . -name .ruff_cache | xargs rm -rfv install:clean ## Install dependencies - flit install --deps develop --symlink + pip install -r requirements.txt + flit install --symlink + +install-full: ## Install dependencies + make install pre-commit install -f lint:fmt ## Run code linters diff --git a/docs/contribution.md b/docs/contribution.md index 57b6a8e1..df2460a3 100644 --- a/docs/contribution.md +++ b/docs/contribution.md @@ -28,7 +28,7 @@ Please take a moment to review the following guidelines before getting started. 4. **Install Dependencies:** Install development libraries and pre-commit hooks. ```bash - make install + make install-full ``` ### **Code Style and Formatting** diff --git a/ninja_extra/__init__.py b/ninja_extra/__init__.py index f8f9c878..20aedcf0 100644 --- a/ninja_extra/__init__.py +++ b/ninja_extra/__init__.py @@ -1,6 +1,6 @@ """Django Ninja Extra - Class Based Utility and more for Django Ninja(Fast Django REST framework)""" -__version__ = "0.20.4" +__version__ = "0.20.5" import django diff --git a/ninja_extra/controllers/route/route_functions.py b/ninja_extra/controllers/route/route_functions.py index 509171e2..49a3eb89 100644 --- a/ninja_extra/controllers/route/route_functions.py +++ b/ninja_extra/controllers/route/route_functions.py @@ -50,7 +50,7 @@ def __call__( *args, **kwargs, ) - return self.as_view(request, *args, context=context, **kwargs) + return self.as_view(request, *args, route_context=context, **kwargs) def _get_required_api_func_signature(self) -> Tuple: skip_parameters = ["self", "request"] @@ -77,12 +77,14 @@ def _resolve_api_func_signature_(self, context_func: Callable) -> Callable: def get_view_function(self) -> Callable: def as_view( request: HttpRequest, - context: Optional[RouteContext] = None, + route_context: Optional[RouteContext] = None, *args: Any, **kwargs: Any, ) -> Any: - context = context or cast(RouteContext, service_resolver(RouteContext)) - with self._prep_controller_route_execution(context, **kwargs) as ctx: + _route_context = route_context or cast( + RouteContext, service_resolver(RouteContext) + ) + with self._prep_controller_route_execution(_route_context, **kwargs) as ctx: ctx.controller_instance.check_permissions() result = self.route.view_func( ctx.controller_instance, *args, **ctx.view_func_kwargs @@ -134,14 +136,14 @@ def get_route_execution_context( @contextmanager def _prep_controller_route_execution( - self, context: RouteContext, **kwargs: Any + self, route_context: RouteContext, **kwargs: Any ) -> Iterator[RouteFunctionContext]: controller_instance = self._get_controller_instance() - controller_instance.context = context + controller_instance.context = route_context - api_func_kwargs = dict(**kwargs) + api_func_kwargs = dict(kwargs) if self.has_request_param: - api_func_kwargs.update(request=context.request) + api_func_kwargs.update(request=route_context.request) try: yield RouteFunctionContext( controller_instance=controller_instance, **api_func_kwargs @@ -164,14 +166,16 @@ class AsyncRouteFunction(RouteFunction): def get_view_function(self) -> Callable: async def as_view( request: HttpRequest, - context: Optional[RouteContext] = None, + route_context: Optional[RouteContext] = None, *args: Any, **kwargs: Any, ) -> Any: from asgiref.sync import sync_to_async - context = context or cast(RouteContext, service_resolver(RouteContext)) - with self._prep_controller_route_execution(context, **kwargs) as ctx: + _route_context = route_context or cast( + RouteContext, service_resolver(RouteContext) + ) + with self._prep_controller_route_execution(_route_context, **kwargs) as ctx: await sync_to_async(ctx.controller_instance.check_permissions)() result = await self.route.view_func( ctx.controller_instance, *args, **ctx.view_func_kwargs @@ -201,4 +205,4 @@ async def __call__( *args, **kwargs, ) - return await self.as_view(request, *args, context=context, **kwargs) + return await self.as_view(request, *args, route_context=context, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index bbf998d8..8d6f91d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,30 +53,6 @@ requires-python = ">=3.7" [tool.flit.metadata.urls] Documentation = "https://eadwincode.github.io/django-ninja-extra/" -[tool.flit.metadata.requires-extra] -test = [ - "pytest", - "pytest-cov", - "pytest-django", - "pytest-asyncio==0.20.3", - "mypy == 1.7.1", - "ruff ==0.1.7", - "ninja-schema>=0.13.4", - "django-stubs", -] -doc = [ - "mkdocs >=1.1.2,<2.0.0", - "mkdocs-material >=7.1.9,<8.0.0", - "mdx-include >=1.4.1,<2.0.0", - "mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0", - "markdown-include", - "mkdocstrings" -] - -dev = [ - "pre-commit" -] - [tool.ruff] select = [ "E", # pycodestyle errors diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 00000000..73270a79 --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,6 @@ +markdown-include +mdx-include >=1.4.1,<2.0.0 +mkdocs >=1.1.2,<2.0.0 +mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0 +mkdocs-material >=7.1.9,<8.0.0 +mkdocstrings diff --git a/requirements-tests.txt b/requirements-tests.txt new file mode 100644 index 00000000..b38b7b12 --- /dev/null +++ b/requirements-tests.txt @@ -0,0 +1,8 @@ +django-stubs +mypy == 1.7.1 +ninja-schema>=0.13.4 +pytest +pytest-asyncio==0.20.3 +pytest-cov +pytest-django +ruff ==0.1.7 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..5e45d216 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +-e . +-r requirements-docs.txt +-r requirements-tests.txt + +pre-commit diff --git a/tests/test_route.py b/tests/test_route.py index 9ca7adee..b6148c6c 100644 --- a/tests/test_route.py +++ b/tests/test_route.py @@ -394,7 +394,9 @@ def test_route_is_protected_by_its_permissions_paramater(self): def test_route_prep_controller_route_execution_context_works(self): route_function: RouteFunction = get_route_function(SomeTestController().example) context = get_route_execution_context(request=anonymous_request) - with route_function._prep_controller_route_execution(context=context) as ctx: + with route_function._prep_controller_route_execution( + route_context=context + ) as ctx: assert isinstance(ctx.controller_instance, SomeTestController) assert ctx.controller_instance.context assert ctx.controller_instance.context is None @@ -404,7 +406,9 @@ def test_route_prep_controller_route_execution_context_cleans_controller_after_r ): route_function: RouteFunction = get_route_function(SomeTestController().example) context = get_route_execution_context(request=anonymous_request) - with route_function._prep_controller_route_execution(context=context) as ctx: + with route_function._prep_controller_route_execution( + route_context=context + ) as ctx: assert isinstance(ctx.controller_instance, SomeTestController) assert ctx.controller_instance.context