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

Feature/pre hook #14

Merged
merged 3 commits into from
Oct 13, 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
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: visiumlint
name: visiumlint
description: Run visiumlint without Pylint
entry: visiumlint --hook
language: python
pass_filenames: false
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@ 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. The hook will not execute `Pylint`.

- 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
repos:
- repo: https://github.com/VisiumCH/visiumlint
rev: 1.6.0
hooks:
- id: visiumlint
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

Expand Down
38 changes: 22 additions & 16 deletions src/visiumlint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
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"
Expand All @@ -21,21 +24,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(
Expand Down
Loading