diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ba0f4e6..0d6097e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: build: @@ -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 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 992a6e9..db55992 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -2,8 +2,8 @@ name: Publish to PyPI on: release: - types: [ published ] - branches: [ master ] + types: [published] + branches: [master] workflow_dispatch: jobs: diff --git a/Makefile b/Makefile index ba40780..b6e5d0c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/drf_simple_api_errors/handlers.py b/drf_simple_api_errors/handlers.py index 0038746..07eea7a 100644 --- a/drf_simple_api_errors/handlers.py +++ b/drf_simple_api_errors/handlers.py @@ -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): @@ -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 = [] @@ -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]) @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 429675b..df76c2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -75,3 +70,8 @@ sections = [ "FIRSTPARTY", "LOCALFOLDER", ] + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"