Skip to content

Commit 1cef000

Browse files
authored
Maintenance (#3)
* Add docstrings to handlers * Improve Makefile * Improve README
1 parent f84d883 commit 1cef000

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
build:
@@ -14,7 +14,7 @@ jobs:
1414
python-version: ["3.8", "3.9", "3.10"]
1515

1616
steps:
17-
- name: Checkout sources
17+
- name: Checkout source code
1818
uses: actions/checkout@v2
1919

2020
- name: Setup Python

.github/workflows/publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Publish to PyPI
22

33
on:
44
release:
5-
types: [ published ]
6-
branches: [ master ]
5+
types: [published]
6+
branches: [master]
77
workflow_dispatch:
88

99
jobs:

Makefile

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
.PHONY : help test install
1+
.PHONY : install shell format lint test test/cov
22

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

7-
install: ## Install dependencies with poetry
8-
poetry install --with dev -v
7+
# Run poetry shell
8+
shell:
9+
@poetry shell
910

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

15-
shell: ## Run poetry shell
16-
poetry shell
16+
# Check format (black, isort) and linting (flake8)
17+
lint:
18+
@poetry run isort --check drf_simple_api_errors test_project
19+
@poetry run black --check drf_simple_api_errors test_project --exclude migrations
20+
@poetry run flake8 drf_simple_api_errors test_project --max-line-length 88
1721

18-
test: ## Run unittests with poetry
19-
poetry run pytest test_project
22+
# Run unittests with poetry
23+
test:
24+
@poetry run pytest test_project
2025

21-
test/cov: ## Run code coverage tests coverage with poetry
22-
poetry run pytest test_project --cov=drf_simple_api_errors --cov-report xml:coverage.xml
26+
# Run code coverage tests coverage with poetry
27+
test/cov:
28+
@poetry run pytest test_project --cov=drf_simple_api_errors --cov-report xml:coverage.xml

drf_simple_api_errors/handlers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313

1414
def exc_detail_handler(data: Dict, exc_detail: Union[Dict, List]) -> Dict:
15+
"""
16+
Handle the exception detail and set it to the `data` dictionary.
17+
18+
If the `exc_detail` is a dictionary, it will set to the `data` dictionary.
19+
If the `exc_detail` is a list, it will be set to the `data` dictionary.
20+
"""
1521
logger.debug("`exc_detail` is instance of %s" % type(exc_detail))
1622

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

2430

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

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

5764

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

6674

6775
def is_exc_detail_same_as_default_detail(exc: APIException) -> bool:
76+
"""Check if the exception detail is the same as the default detail."""
6877
return (isinstance(exc.detail, str) and exc.detail == exc.default_detail) or (
6978
isinstance(exc.detail, list)
7079
and len(exc.detail) == 1

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ Django = ">=2.2"
4242
djangorestframework = ">=3.0"
4343

4444

45-
[build-system]
46-
requires = ["poetry-core"]
47-
build-backend = "poetry.core.masonry.api"
48-
49-
5045
[tool.poetry.group.dev.dependencies]
5146
black = "^24.1.1"
5247
factory-boy = "^3.3.0"
@@ -75,3 +70,8 @@ sections = [
7570
"FIRSTPARTY",
7671
"LOCALFOLDER",
7772
]
73+
74+
75+
[build-system]
76+
requires = ["poetry-core"]
77+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)