From bab61d92210fb08e896fa21b48ff7b1fb092dce5 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Tue, 8 Oct 2024 16:21:58 -0700 Subject: [PATCH 1/9] configs for pre-commit checks --- .codespellrc | 3 ++ .flake8 | 11 ++++++ .pre-commit-config.yaml | 75 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 .codespellrc create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 000000000..299070081 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,3 @@ +[codespell] +skip = '.git,*.svg,*.secret.*,*.key,./vendor/grafana/dashboards/*' +ignore-words-list = 'demog' diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..fb5e07587 --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +[flake8] +# Ignore style and complexity +# E: style errors +# W: style warnings +# C: complexity +# E402: module level import not at top of file +# I100: Import statements are in the wrong order +# I101: Imported names are in the wrong order. Should be +# F841: local variable ... is assigned to but never used +ignore = E, C, W, I100, I101, D400, F841 +builtins = c diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..65bea6d47 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,75 @@ +# pre-commit is a tool to perform a predefined set of tasks manually and/or +# automatically before git commits are made. +# +# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level +# +# Common tasks +# +# - Run on all files: pre-commit run --all-files +# - Register git hooks: pre-commit install --install-hooks +# +repos: + # Autoformat: Python code + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.6.9 + hooks: + # Run the linter. + - id: ruff + types_or: [ python, pyi ] + args: [ --fix ] + # Run the formatter. + - id: ruff-format + types_or: [ python, pyi ] + + # Autoformat: Python code, syntax patterns are modernized + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 + hooks: + - id: pyupgrade + args: + - --py36-plus + + # Autoformat: Python code + - repo: https://github.com/pycqa/isort + rev: "5.13.2" + hooks: + - id: isort + + # Autoformat: Python code + - repo: https://github.com/psf/black + rev: "24.10.0" + hooks: + - id: black + # This is a `.py` file but is encrypted with sops + + # Lint: Python code + - repo: https://github.com/pycqa/flake8 + rev: "7.1.1" + hooks: + - id: flake8 + # This is a `.py` file but is encrypted with sops + exclude: deployer/commands/generate/cryptnono_config/enc-blocklist-generator.secret.py + + # Prevent unencrypted files from being committed + - repo: https://github.com/yuvipanda/pre-commit-hook-ensure-sops + rev: v1.1 + hooks: + - id: sops-encryption + # Add files here if they contain the word 'secret' but should not be encrypted + exclude: secrets\.md|helm-charts/support/templates/prometheus-ingres-auth/secret\.yaml|helm-charts/basehub/templates/dex/secret\.yaml|helm-charts/basehub/templates/static/secret\.yaml|config/clusters/templates/common/support\.secret\.values\.yaml|helm-charts/basehub/templates/ingress-auth/secret\.yaml + + # Prevent known typos from being committed + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + args: + # Autofix known typos + - --write-changes + additional_dependencies: + - tomli + +# pre-commit.ci config reference: https://pre-commit.ci/#configuration +#ci: +# autoupdate_schedule: monthly From a04f4064aea23a48df9426eb3cd10cbc45db29d4 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Mon, 14 Oct 2024 14:35:56 -0700 Subject: [PATCH 2/9] final tweaking of configs for a (relatively) sane pre-commit workflow --- .codespellrc | 3 --- .flake8 | 1 - .pre-commit-config.yaml | 18 ++++++++++++++++++ pyproject.toml | 10 ++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) delete mode 100644 .codespellrc create mode 100644 pyproject.toml diff --git a/.codespellrc b/.codespellrc deleted file mode 100644 index 299070081..000000000 --- a/.codespellrc +++ /dev/null @@ -1,3 +0,0 @@ -[codespell] -skip = '.git,*.svg,*.secret.*,*.key,./vendor/grafana/dashboards/*' -ignore-words-list = 'demog' diff --git a/.flake8 b/.flake8 index fb5e07587..9419e9369 100644 --- a/.flake8 +++ b/.flake8 @@ -8,4 +8,3 @@ # I101: Imported names are in the wrong order. Should be # F841: local variable ... is assigned to but never used ignore = E, C, W, I100, I101, D400, F841 -builtins = c diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65bea6d47..f1f7a5f9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,6 +70,24 @@ repos: additional_dependencies: - tomli + # misc stuff + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + # ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available + hooks: + # Autoformat: Makes sure files end in a newline and only a newline. + - id: end-of-file-fixer + + # Autoformat: Sorts entries in requirements.txt. + - id: requirements-txt-fixer + + # Lint: Check for files with names that would conflict on a + # case-insensitive filesystem like MacOS HFS+ or Windows FAT. + - id: check-case-conflict + + # Lint: Checks that non-binary executables have a proper shebang. + - id: check-executables-have-shebangs + # pre-commit.ci config reference: https://pre-commit.ci/#configuration #ci: # autoupdate_schedule: monthly diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..7fbb59e8f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[tool.black] +# target-version should be all supported versions +target-version = ['py37', 'py38', 'py39', 'py310'] + +[tool.isort] +profile = "black" + +[tool.codespell] +skip = '.git,*.pdf,*.svg,vendor/grafana/dashboards/*,deployments/*/secrets/*' +ignore-words-list = 'demog,wasn' From cd99ebff794df194e03a20e311697f2d4e2ebdcf Mon Sep 17 00:00:00 2001 From: shane knapp Date: Mon, 14 Oct 2024 14:41:30 -0700 Subject: [PATCH 3/9] remove some 2i2c specific stuff --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1f7a5f9a..2cb43fce2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,7 @@ repos: hooks: - id: sops-encryption # Add files here if they contain the word 'secret' but should not be encrypted - exclude: secrets\.md|helm-charts/support/templates/prometheus-ingres-auth/secret\.yaml|helm-charts/basehub/templates/dex/secret\.yaml|helm-charts/basehub/templates/static/secret\.yaml|config/clusters/templates/common/support\.secret\.values\.yaml|helm-charts/basehub/templates/ingress-auth/secret\.yaml + # exclude: # Prevent known typos from being committed - repo: https://github.com/codespell-project/codespell From 8263f2e83949890a561892a59442e8ab26ee31f1 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Tue, 15 Oct 2024 11:47:35 -0700 Subject: [PATCH 4/9] add py3.11 to black config --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7fbb59e8f..eea6392a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] # target-version should be all supported versions -target-version = ['py37', 'py38', 'py39', 'py310'] +target-version = ['py37', 'py38', 'py39', 'py310', 'py311'] [tool.isort] profile = "black" From c05911beb83c84b4c1c2e976007053e6a8a6a38f Mon Sep 17 00:00:00 2001 From: shane knapp Date: Tue, 15 Oct 2024 12:57:29 -0700 Subject: [PATCH 5/9] move yaml linter to pre-commit and remove GHA --- .github/workflows/yaml-lint.yaml | 15 --------------- .pre-commit-config.yaml | 7 +++++++ 2 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/yaml-lint.yaml diff --git a/.github/workflows/yaml-lint.yaml b/.github/workflows/yaml-lint.yaml deleted file mode 100644 index 787d5e3fa..000000000 --- a/.github/workflows/yaml-lint.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: "Yaml lint" -on: - - pull_request # yamllint disable-line rule:truthy - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install yamllint - run: pip install yamllint==1.35.1 - - - name: Lint YAML files - run: yamllint --no-warnings . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2cb43fce2..4d50d27f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,13 @@ # - Register git hooks: pre-commit install --install-hooks # repos: + # yaml linter + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.35.1 + hooks: + - id: yamllint + args: [--no-warnings, -c=./.yamllint.yaml] + # Autoformat: Python code - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. From 9432c52413c28cb83b0521e94e2d9816e03612b6 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Thu, 17 Oct 2024 09:43:01 -0700 Subject: [PATCH 6/9] add TODO to eventually remove the args in yamllint that skips warnings --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d50d27f8..a2e41300e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,7 @@ repos: rev: v1.35.1 hooks: - id: yamllint + # TODO: remove --no-warnings eventually args: [--no-warnings, -c=./.yamllint.yaml] # Autoformat: Python code From a05f4efd8e759df183ad67fa6f5da83c82b23803 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Thu, 17 Oct 2024 16:13:32 -0700 Subject: [PATCH 7/9] minor tweaks in the config --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a2e41300e..c0d63cb27 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,8 +56,8 @@ repos: rev: "7.1.1" hooks: - id: flake8 - # This is a `.py` file but is encrypted with sops - exclude: deployer/commands/generate/cryptnono_config/enc-blocklist-generator.secret.py + # In case a `.py` file but is encrypted with sops + # exclude: # Prevent unencrypted files from being committed - repo: https://github.com/yuvipanda/pre-commit-hook-ensure-sops @@ -78,7 +78,7 @@ repos: additional_dependencies: - tomli - # misc stuff + # pre-commit.com provided hooks - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 # ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available From 37b7d3cd9472fbdda1eea90d17555a7b4467fcfc Mon Sep 17 00:00:00 2001 From: shane knapp Date: Fri, 18 Oct 2024 11:02:28 -0700 Subject: [PATCH 8/9] adding dev reqs --- dev-requirements.txt | 13 +++++++++++++ requirements.txt | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 dev-requirements.txt diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 000000000..fe0997139 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,13 @@ +# allow for base image specification in hubploy.yaml +git+https://github.com/berkeley-dsep-infra/hubploy.git +pygithub +pyrsistent==0.19.3 +attrs==23.1.0 +chartpress +jupyter-repo2docker==2024.07.0 +myst-parser +chardet +niquests==3.7.2 +urllib3<2.0.0 +yamllint==1.35.1 +pre-commit==4.0.1 diff --git a/requirements.txt b/requirements.txt index 88193e5d1..cf410a6e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,3 @@ chardet niquests==3.7.2 urllib3<2.0.0 yamllint==1.35.1 -pre-commit==4.0.1 From d8305841fef03f9d6337db0b1218ebc312a6f175 Mon Sep 17 00:00:00 2001 From: shane knapp Date: Fri, 18 Oct 2024 11:03:46 -0700 Subject: [PATCH 9/9] adding dev reqs to labeler --- .github/labeler.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index a74875c95..4fa33334b 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -16,6 +16,7 @@ configuration: - '**/apt.txt' - '**/infra-requirements.txt' - '**/requirements.in' + - '**/dev-requirements.txt' - '**/requirements.txt' - '**/runtime.txt' - '**/*.json'