From 00ec6e02eb23226dd30f88265f1838752ae800f9 Mon Sep 17 00:00:00 2001 From: Pascal Epple Date: Fri, 13 Oct 2023 09:53:39 +0200 Subject: [PATCH 1/3] added pre-commit hook and new hook argument for visiumlint --- .pre-commit-hooks.yaml | 6 ++++++ src/visiumlint/main.py | 35 +++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..b8b669d --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,6 @@ +- id: visiumlint + name: visiumlint + description: Run visiumlint without Pylint + entry: visiumlint --hook + language: python + pass_filenames: false \ No newline at end of file diff --git a/src/visiumlint/main.py b/src/visiumlint/main.py index 495db7c..15e3138 100644 --- a/src/visiumlint/main.py +++ b/src/visiumlint/main.py @@ -6,7 +6,7 @@ import typer -def lint(check_lint: bool = typer.Option(False, "--check", help="Enable check mode.")) -> None: +def lint(check_lint: bool = typer.Option(False, "--check", help="Enable check mode."), hook : bool = typer.Option(False, "--hook", help="Enable hook mode.")) -> None: """Implement the logic of the lint command.""" if check_lint: check_lint = "--check" @@ -21,21 +21,24 @@ def lint(check_lint: bool = typer.Option(False, "--check", help="Enable check mo ["sh", "-c", f"isort {check_lint} --gitignore . --line-length 120 --profile black"], check=False ).returncode - run(["sh", "-c", "echo Running pylint"], check=False) - pylint_returncode = run( - [ - "sh", - "-c", - "pylint . --recursive=y --load-plugins=pylint.extensions.docstyle,pylint.extensions.docparams --disable=fixme,too-few-public-methods", - "--variable-rgx", - "^[a-z][a-z0-9_]*$", - "--argument-rgx", - "^[a-z][a-z0-9_]*$", - "--max-line-length", - "120", - ], - check=False, - ).returncode + if not hook: + run(["sh", "-c", "echo Running pylint"], check=False) + pylint_returncode = run( + [ + "sh", + "-c", + "pylint . --recursive=y --load-plugins=pylint.extensions.docstyle,pylint.extensions.docparams --disable=fixme,too-few-public-methods", + "--variable-rgx", + "^[a-z][a-z0-9_]*$", + "--argument-rgx", + "^[a-z][a-z0-9_]*$", + "--max-line-length", + "120", + ], + check=False, + ).returncode + else: + pylint_returncode = 0 run(["sh", "-c", "echo Running pydocstyle"], check=False) pydocstyle_returncode = run( From bb5e42ff39fa7754a8fa7d72334396874c69ac9a Mon Sep 17 00:00:00 2001 From: Pascal Epple Date: Fri, 13 Oct 2023 14:04:34 +0200 Subject: [PATCH 2/3] Modified readme, visiumlinted the code --- README.md | 28 +++++++++++++++++++++++++++- src/visiumlint/main.py | 5 ++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 804fc0d..72eb33a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,33 @@ Visiumlint relies on `black`, `isort`, `pylint`, `pydocstyle` and `mypy`. - Activate the environment using `pipenv shell` - Run the visium package by running the command `visiumlint` - +# Hook + +You can automate visiumlint when commiting changes with a [git hook](https://githooks.com/) and the [pre-commit](https://pre-commit.com/) library. + +- Make sure to have installed pre-commit, or else run `brew install pre-commit` + +- Add a file called `.pre-commit-config.yaml` to the root of your project: +```yaml +repos: +- repo: https://github.com/VisiumCH/visiumlint + rev: 1.6.0 + hooks: + - id: visiumlint + language: python + types: [python] + require_serial: true + +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: python + types: [python] + require_serial: true +``` +- Run `pre-commit autoupdate`. This will use the latest available version of visiumlint. # Development ## Manage your python environment diff --git a/src/visiumlint/main.py b/src/visiumlint/main.py index 15e3138..ba82f1d 100644 --- a/src/visiumlint/main.py +++ b/src/visiumlint/main.py @@ -6,7 +6,10 @@ import typer -def lint(check_lint: bool = typer.Option(False, "--check", help="Enable check mode."), hook : bool = typer.Option(False, "--hook", help="Enable hook mode.")) -> None: +def lint( + check_lint: bool = typer.Option(False, "--check", help="Enable check mode."), + hook: bool = typer.Option(False, "--hook", help="Enable hook mode."), +) -> None: """Implement the logic of the lint command.""" if check_lint: check_lint = "--check" From 0450b6ae231827aed5c0ffbc222332ec0d8caa61 Mon Sep 17 00:00:00 2001 From: Pascal Epple Date: Fri, 13 Oct 2023 15:25:51 +0200 Subject: [PATCH 3/3] Changes according to PR comments --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 72eb33a..f223db2 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ Visiumlint relies on `black`, `isort`, `pylint`, `pydocstyle` and `mypy`. # Hook -You can automate visiumlint when commiting changes with a [git hook](https://githooks.com/) and the [pre-commit](https://pre-commit.com/) library. +You can automate visiumlint when commiting changes with a [git hook](https://githooks.com/) and the [pre-commit](https://pre-commit.com/) library. The hook will not execute `Pylint`. -- Make sure to have installed pre-commit, or else run `brew install pre-commit` +- Make sure to have installed pre-commit, or else run `pip install pre-commit` - Add a file called `.pre-commit-config.yaml` to the root of your project: ```yaml @@ -32,15 +32,6 @@ repos: language: python types: [python] require_serial: true - -- repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: python - types: [python] - require_serial: true ``` - Run `pre-commit autoupdate`. This will use the latest available version of visiumlint. # Development