From dcacdabb43447107d825ca533ea2887e81514819 Mon Sep 17 00:00:00 2001 From: thenav56 Date: Fri, 14 Jun 2024 10:13:22 +0545 Subject: [PATCH] Add pre-commit configuration --- .flake8 | 6 +++--- .github/workflows/lint.yml | 23 +++++++++++++++++++++++ .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ pyproject.toml | 18 +++++++++++++++--- utils/common.py | 2 +- 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 index 5ea7c75cd5..218f966a56 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,7 @@ [flake8] -ignore = C901, W504 -max-line-length = 125 -exclude = .git,__pycache__,old,build,dist,*/migrations/*.py +extend-ignore = C901, W504, E203, E701 +max-line-length = 130 +exclude = .git,__pycache__,old,build,dist,*migrations*,*snapshots* max-complexity = 10 per-file-ignores = /**/tests/*_mock_data.py: E501 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..eb2a1dde83 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Python lint check + +on: + push: + branches: + - develop + pull_request: + + +jobs: + pre_commit_checks: + name: 🚴 Pre-Commit checks 🚴 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@main + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@main + with: + cache: 'poetry' + - run: poetry install + - uses: pre-commit/action@main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..35422aafa3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +default_language_version: + python: python3 + +# NOTE: Update in .flake8 pyproject.toml as well +exclude: | + (?x)^( + \.git| + __pycache__| + .*snap_test_.*\.py| + .+\/.+\/migrations\/.* + ) + +repos: + - repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + + - repo: https://github.com/PyCQA/isort + rev: 5.13.2 + hooks: + - id: isort + + - repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 diff --git a/pyproject.toml b/pyproject.toml index 3265e8cb8f..a1aa3cab1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,8 +113,8 @@ reportMissingImports = true reportMissingTypeStubs = false [tool.black] -line-length = 125 -py36 = true +line-length = 130 +target-version = ['py39'] include = '\.pyi?$' exclude = ''' /( @@ -128,7 +128,19 @@ exclude = ''' | docs )/ ''' -extend-exclude = '^.*\b(migrations)\b.*$' +# NOTE: Update in .pre-commit-config.yaml as well +extend-exclude = "^.*\\b(migrations)\\b.*$ (__pycache__|.*snap_test_.*\\.py|.+/+.+/+migrations/+.*)" + +[tool.isort] +profile = "black" +multi_line_output = 3 +# NOTE: Update in .pre-commit-config.yaml as well +skip = [ + "**/__pycache__", + "**/snap_test_*.py", + "**/migrations/*.py", +] + [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/utils/common.py b/utils/common.py index e5f7aa6da5..845e629bee 100644 --- a/utils/common.py +++ b/utils/common.py @@ -433,7 +433,7 @@ def excel_to_python_date_format(excel_format): # TODO: support all formats # First replace excel's locale identifiers such as [$-409] by empty string python_format = re.sub( - '(\[\\$-\d+\])', '', excel_format.upper() # noqa: W605 + r'(\[\\$-\d+\])', '', excel_format.upper() ).\ replace('\\', '').\ replace('YYYY', '%Y').\