Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precommit hook #959

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
schedule: 'after 5pm on the first day of the month',
},
baseBranches: ['master', '1.4', '1.3', '1.2', '1.1'],
'pre-commit': { enabled: true },
regexManagers: [
{
fileMatch: ['^.pre-commit-config.yaml$'],
matchStrings: [" +- '?(?<depName>[^' @=]+)(@|==)(?<currentValue>[^' @=]+)'? # (?<datasource>.+)"],
},
{
fileMatch: ['^c2cciutils/applications-versions.yaml$'],
matchStrings: [
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ jobs:
- run: python3 -m pip install --user --force-reinstall dist/c2cciutils-0.0.0-py3-none-any.whl[checks,publish]
- run: rm -rf dist build

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}\npre-commit-"
- run: pre-commit run --all-files
env:
SKIP: poetry-lock,pipenv-lock,helm-lock
- run: git diff && false
if: failure()
- name: Checks
run: c2cciutils-checks

Expand Down
95 changes: 95 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,98 @@ repos:
- id: prettier
additional_dependencies:
- prettier@2.8.4
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
- id: check-ast
- id: debug-statements
- id: check-toml
- id: check-yaml
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/sbrunner/hooks
rev: 0.3.2
hooks:
- id: copyright
- id: poetry-check
additional_dependencies:
- poetry==1.3.2 # pypi
- id: poetry-lock
additional_dependencies:
- poetry==1.3.2 # pypi
- id: pipenv-lock
additional_dependencies:
- pipenv==2022.12.19 # pypi
- id: helm-lock
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
exclude: ^(.*/)?poetry\.lock$
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: git-check
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.20.0
hooks:
- id: check-github-actions
- id: check-github-workflows
- id: check-jsonschema
name: Check GitHub Workflows set timeout-minutes
files: ^\.github/workflows/[^/]+$
types:
- yaml
args:
- --builtin-schema
- github-workflows-require-timeout
- id: check-renovate
additional_dependencies:
- pyjson5==1.6.2 # pypi
- repo: https://github.com/sirwart/ripsecrets
rev: v0.1.5
hooks:
- id: ripsecrets
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
hooks:
- id: autoflake
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/PyCQA/prospector
rev: v1.8.4
hooks:
- id: prospector
args:
- --tool=pydocstyle
- --die-on-tool-error
- --output-format=pylint
ci:
autoupdate_schedule: quarterly
skip:
- copyright
- poetry-check
- poetry-lock
- pipenv-lock
- helm-lock
- ripsecrets
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,12 @@ volumePermissions.enabled: 'true'
```

See also: [Parameters documentations](https://github.com/bitnami/charts/tree/master/bitnami/postgresql#parameters).

## Contributing

Install the pre-commit hooks:

```bash
pip install pre-commit
pre-commit install --allow-missing-config
```
2 changes: 1 addition & 1 deletion c2cciutils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class ChecksCodespellConfig(TypedDict, total=False):
"""

ignore_re: List[str]
"""
r"""
codespell ignore regular expression.

List of regular expression that should be ignored
Expand Down
2 changes: 1 addition & 1 deletion c2cciutils/lib/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_versions_config() -> Dict[str, Dict[str, str]]:
Get the versions from the config file.
"""
if os.path.exists("ci/dpkg-versions.yaml"):
with open("ci/dpkg-versions.yaml", "r", encoding="utf-8") as versions_file:
with open("ci/dpkg-versions.yaml", encoding="utf-8") as versions_file:
return cast(Dict[str, Dict[str, str]], yaml.load(versions_file.read(), Loader=yaml.SafeLoader))
return {}

Expand Down
6 changes: 3 additions & 3 deletions c2cciutils/pr_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def commits_spell(
temp_file.write(commit["commit"]["message"])
temp_file.flush()
spell = subprocess.run( # nosec # pylint: disable=subprocess-run-check
spellcheck_cmd + [temp_file.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE
spellcheck_cmd + [temp_file.name], capture_output=True
)
if spell.returncode != 0:
need_separator = _commit_intro(need_separator, commit)
Expand Down Expand Up @@ -183,7 +183,7 @@ def pull_request_spell(
temp_file.write("\n")
temp_file.flush()
spell = subprocess.run( # nosec # pylint: disable=subprocess-run-check
spellcheck_cmd + [temp_file.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE
spellcheck_cmd + [temp_file.name], capture_output=True
)
if spell.returncode != 0:
print("::error::Code spell error in pull request")
Expand All @@ -210,7 +210,7 @@ def pull_request_labels(github_event: Dict[str, Any], **kwargs: Any) -> bool:
if "labels" in section:
required_labels.extend(section["labels"])

print(f"Requird one onf the following labels: {', '.join(required_labels)}")
print(f"Required one onf the following labels: {', '.join(required_labels)}")

if required_labels:
labels = [
Expand Down
2 changes: 0 additions & 2 deletions c2cciutils/prettier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
Load prettier.js and improve the API.
"""
Expand Down
7 changes: 3 additions & 4 deletions c2cciutils/scripts/download_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def main() -> None:
argparser.add_argument("--versions-file", required=True)
args = argparser.parse_args()

with open(args.versions_file, "r", encoding="utf-8") as config_file:
with open(args.versions_file, encoding="utf-8") as config_file:
versions = cast(Dict[str, str], yaml.load(config_file, Loader=yaml.SafeLoader))
with open(args.applications_file, "r", encoding="utf-8") as config_file:
with open(args.applications_file, encoding="utf-8") as config_file:
applications = cast(
applications_definition.ApplicationsConfiguration, yaml.load(config_file, Loader=yaml.SafeLoader)
)
Expand All @@ -42,12 +42,11 @@ def download_c2cciutils_applications() -> None:
"""Download the applications defined in the c2cciutils package."""
with open(
os.path.join(os.path.dirname(os.path.dirname(__file__)), "applications-versions.yaml"),
"r",
encoding="utf-8",
) as config_file:
versions = cast(Dict[str, str], yaml.load(config_file, Loader=yaml.SafeLoader))
with open(
os.path.join(os.path.dirname(os.path.dirname(__file__)), "applications.yaml"), "r", encoding="utf-8"
os.path.join(os.path.dirname(os.path.dirname(__file__)), "applications.yaml"), encoding="utf-8"
) as config_file:
applications = cast(
applications_definition.ApplicationsConfiguration, yaml.load(config_file, Loader=yaml.SafeLoader)
Expand Down
1 change: 0 additions & 1 deletion c2cciutils/scripts/k8s/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def main() -> None:
os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "applications-versions.yaml"
),
"r",
encoding="utf-8",
) as config_file:
versions = cast(Dict[str, str], yaml.load(config_file, Loader=yaml.SafeLoader))
Expand Down
2 changes: 1 addition & 1 deletion example-project/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
All the code in this library is provided under this license:

Copyright (c) 2020, Camptocamp SA
Copyright (c) 2020-2023, Camptocamp SA
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 3 additions & 0 deletions example-project/project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Example project.
"""
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ poetry-plugin-export==1.1.0
poetry-dynamic-versioning[plugin]==0.19.0
poetry-plugin-tweak-dependencies-version==1.0.0
pip==22.3.1
pre-commit==3.2.0