Skip to content

Maintenance #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
Expand All @@ -14,7 +14,7 @@ jobs:
python-version: ["3.8", "3.9", "3.10"]

steps:
- name: Checkout sources
- name: Checkout source code
uses: actions/checkout@v2

- name: Setup Python
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish to PyPI

on:
release:
types: [ published ]
branches: [ master ]
types: [published]
branches: [master]
workflow_dispatch:

jobs:
Expand Down
38 changes: 22 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
.PHONY : help test install
.PHONY : install shell format lint test test/cov

format: ## Run formatters (black, isort) with poetry
poetry run isort drf_simple_api_errors test_project
poetry run black drf_simple_api_errors test_project
# Install dependencies with poetry
install:
@poetry install --with dev -v

install: ## Install dependencies with poetry
poetry install --with dev -v
# Run poetry shell
shell:
@poetry shell

lint: ## Check format (black, isort) and linting (flake8)
poetry run isort --check drf_simple_api_errors test_project
poetry run black --check drf_simple_api_errors test_project --exclude migrations
poetry run flake8 drf_simple_api_errors test_project --max-line-length 88
# Run formatters (black, isort) with poetry
format:
@poetry run isort drf_simple_api_errors test_project
@poetry run black drf_simple_api_errors test_project

shell: ## Run poetry shell
poetry shell
# Check format (black, isort) and linting (flake8)
lint:
@poetry run isort --check drf_simple_api_errors test_project
@poetry run black --check drf_simple_api_errors test_project --exclude migrations
@poetry run flake8 drf_simple_api_errors test_project --max-line-length 88

test: ## Run unittests with poetry
poetry run pytest test_project
# Run unittests with poetry
test:
@poetry run pytest test_project

test/cov: ## Run code coverage tests coverage with poetry
poetry run pytest test_project --cov=drf_simple_api_errors --cov-report xml:coverage.xml
# Run code coverage tests coverage with poetry
test/cov:
@poetry run pytest test_project --cov=drf_simple_api_errors --cov-report xml:coverage.xml
9 changes: 9 additions & 0 deletions drf_simple_api_errors/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@


def exc_detail_handler(data: Dict, exc_detail: Union[Dict, List]) -> Dict:
"""
Handle the exception detail and set it to the `data` dictionary.

If the `exc_detail` is a dictionary, it will set to the `data` dictionary.
If the `exc_detail` is a list, it will be set to the `data` dictionary.
"""
logger.debug("`exc_detail` is instance of %s" % type(exc_detail))

if isinstance(exc_detail, dict):
Expand All @@ -23,6 +29,7 @@ def exc_detail_handler(data: Dict, exc_detail: Union[Dict, List]) -> Dict:


def __exc_detail_as_dict_handler(data: Dict, exc_detail: Dict):
"""Handle the exception detail as a dictionary."""
exc_detail = flatten_dict(copy.deepcopy(exc_detail))

invalid_params = []
Expand Down Expand Up @@ -56,6 +63,7 @@ def __exc_detail_as_dict_handler(data: Dict, exc_detail: Dict):


def __exc_detail_as_list_handler(data: Dict, exc_detail: List):
"""Handle the exception detail as a list."""
detail = []
for error in exc_detail:
detail.append(error if not isinstance(error, list) else error[0])
Expand All @@ -65,6 +73,7 @@ def __exc_detail_as_list_handler(data: Dict, exc_detail: List):


def is_exc_detail_same_as_default_detail(exc: APIException) -> bool:
"""Check if the exception detail is the same as the default detail."""
return (isinstance(exc.detail, str) and exc.detail == exc.default_detail) or (
isinstance(exc.detail, list)
and len(exc.detail) == 1
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ Django = ">=2.2"
djangorestframework = ">=3.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.poetry.group.dev.dependencies]
black = "^24.1.1"
factory-boy = "^3.3.0"
Expand Down Expand Up @@ -75,3 +70,8 @@ sections = [
"FIRSTPARTY",
"LOCALFOLDER",
]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading