From 1c2b1ac920d606c95cb8e0ae3403e791db7ffae1 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Fri, 9 Sep 2022 15:55:47 +0530 Subject: [PATCH] Fix linter config parsing errors (#1010) * switch to pyproject.toml * run tests on master as well this will fix coverage reporting issues --- .coveragerc | 20 --------- .flake8 | 13 ++++++ .github/workflows/deployment.yaml | 2 +- .github/workflows/linter.yml | 6 +-- .pre-commit-config.yaml | 6 +-- docker/docker-entrypoint.sh | 2 +- pyproject.toml | 62 ++++++++++++++++++++++++++ requirements/local.txt | 2 +- setup.cfg | 73 ------------------------------- 9 files changed, 84 insertions(+), 102 deletions(-) delete mode 100644 .coveragerc create mode 100644 .flake8 create mode 100644 pyproject.toml delete mode 100644 setup.cfg diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 8c83f009b0..0000000000 --- a/.coveragerc +++ /dev/null @@ -1,20 +0,0 @@ -[run] -source = . -omit = - *migrations*, - *tests*, - *__pycache__*, - *venv*, - docs/*, - **/*.html, - **/*.txt, - **/*.yml, - **/*.yaml, - **/*.md, - **/*.rst, - **/*.json, - **/*.ini, - **/*.conf, - **/*.sh, - **/*.bat -plugins = django_coverage_plugin diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..bee71452b9 --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203,E501,E231 +exclude = + .git, + .gitignore, + *.pot, + *.py[co], + __pycache__, + .venv, + */migrations/*, + */static/CACHE/*, + docs diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 4f10a31cae..f3241ba9ea 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -26,7 +26,7 @@ env: CONTAINER_NAME_CRON: 'care-celery-beat' jobs: test: - if: github.ref == 'refs/heads/production' + if: github.ref == 'refs/heads/production' || github.ref == 'refs/heads/master' runs-on: ubuntu-latest env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/care diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index abe0ab5c44..e155680db7 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,6 +25,6 @@ jobs: VALIDATE_PYTHON_FLAKE8: true VALIDATE_PYTHON_ISORT: true LINTER_RULES_PATH: / - PYTHON_BLACK_CONFIG_FILE: "setup.cfg" - PYTHON_FLAKE8_CONFIG_FILE: "setup.cfg" - PYTHON_ISORT_CONFIG_FILE: "setup.cfg" + # PYTHON_BLACK_CONFIG_FILE: "pyproject.toml" + PYTHON_FLAKE8_CONFIG_FILE: ".flake8" + PYTHON_ISORT_CONFIG_FILE: "pyproject.toml" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 91117286d8..11ba231c1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,5 @@ exclude: "docs|node_modules|migrations|.git|.tox" default_stages: [commit] -fail_fast: true repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -16,18 +15,19 @@ repos: rev: 5.10.1 hooks: - id: isort - args: ["--profile", "black"] + additional_dependencies: ["isort[pyproject]"] - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black + args: ["--config=pyproject.toml"] - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 - args: ["--config=setup.cfg"] + args: ["--config=pyproject.toml"] additional_dependencies: [flake8-isort] ci: diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 74c6c62a81..ed6d36353b 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -6,7 +6,7 @@ python manage.py migrate echo "All migrations have been made successfully" -if ["${DJANGO_DEBUG,,}" == "true"]; then +if [[ "${DJANGO_DEBUG,,}" == "true" ]]; then python -m debugpy --wait-for-client --listen 0.0.0.0:9876 manage.py runserver_plus 0.0.0.0:9000 else python manage.py runserver 0.0.0.0:9000 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..fbcff50983 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,62 @@ +[tool.coverage.run] +branch = true +source = ["care", "config"] +parallel = true +concurrency = ["multiprocessing"] + + +[tool.coverage.report] +omit = [ + "*/tests/*", + "*/migrations/*", + "*/asgi.py", + "*/wsgi.py", + "manage.py", + ".venv/*" +] +exclude_lines = [ + "pragma: no cover", + "raise NotImplementedError" +] +ignore_errors = true + + +[tool.isort] +profile = "black" +known_third_party = [ + "allauth", + "boto3", + "celery", + "crispy_forms", + "dateparser", + "dateutil", + "django", + "django_filters", + "django_rest_passwordreset", + "djangoql", + "djqscsv", + "drf_extra_fields", + "drf_yasg", + "dry_rest_permissions", + "environ", + "fernet_fields", + "freezegun", + "hardcopy", + "healthy_django", + "jsonschema", + "jwt", + "location_field", + "multiselectfield", + "partial_index", + "phonenumber_field", + "phonenumbers", + "pytz", + "pywebpush", + "ratelimit", + "requests", + "rest_framework", + "rest_framework_nested", + "rest_framework_simplejwt", + "sentry_sdk", + "simple_history" +] diff --git a/requirements/local.txt b/requirements/local.txt index 5cdbf4b94d..84dcf6d7a7 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -18,7 +18,7 @@ django-extensions==2.2.8 # https://github.com/django-extensions/django-extensio # ------------------------------- factory-boy==2.12.0 # https://github.com/FactoryBoy/factory_boy freezegun==0.3.15 # https://github.com/spulec/freezegun -coverage==6.4.1 # https://github.com/nedbat/coveragepy +coverage[toml]==6.4.1 # https://github.com/nedbat/coveragepy django-coverage-plugin==2.0.3 tblib==1.7.0 # https://github.com/ionelmc/python-tblib # WatchDog diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 9504de8208..0000000000 --- a/setup.cfg +++ /dev/null @@ -1,73 +0,0 @@ -[coverage:run] -branch = True -source = care -parallel = true -concurrency = multiprocessing - -[coverage:report] -omit = - */tests/* - */migrations/* - */asgi.py - */wsgi.py - manage.py - .vemv/* - venv/* -exclude_lines = - pragma: no cover - raise NotImplementedError -ignore_errors = True - - -[flake8] -max-line-length = 88 -extend-ignore = E203,E501,E231 -exclude = - .git, - .gitignore, - *.pot, - *.py[co], - __pycache__, - .venv, - */migrations/*, - */static/CACHE/*, - docs - -[isort] -profile = black -known_third_party = - allauth, - boto3, - celery, - crispy_forms, - dateparser, - dateutil, - django, - django_filters, - django_rest_passwordreset, - djangoql, - djqscsv, - drf_extra_fields, - drf_yasg, - dry_rest_permissions, - environ, - fernet_fields, - freezegun, - hardcopy, - healthy_django, - jsonschema, - jwt, - location_field, - multiselectfield, - partial_index, - phonenumber_field, - phonenumbers, - pytz, - pywebpush, - ratelimit, - requests, - rest_framework, - rest_framework_nested, - rest_framework_simplejwt, - sentry_sdk, - simple_history