Skip to content

Commit

Permalink
Merge pull request #15 from VisiumCH/feature/run-on-files
Browse files Browse the repository at this point in the history
Added list of paths to visiumlint argument
  • Loading branch information
epplepascal authored Oct 17, 2023
2 parents 9179d9e + b44afda commit 0b88228
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/visiumlint/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
"""visiumlint main module."""
# pylint: disable=duplicate-code
import sys
from pathlib import Path
from subprocess import run
from typing import List

import typer


def lint(
paths: List[Path] = typer.Argument(default=None, help="Paths of files and directories to visiumlint."),
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 not paths:
paths = [Path(".")]
if check_lint:
check_lint = "--check"
else:
check_lint = ""

paths = " ".join([str(path) for path in paths if path.is_file() or path.is_dir()])

run(["sh", "-c", "echo 'Running black'"], check=False)
black_returncode = run(["sh", "-c", f"black {check_lint} . --line-length 120"], check=False).returncode
black_returncode = run(["sh", "-c", f"black {paths} {check_lint} --line-length 120"], check=False).returncode

run(["sh", "-c", "echo Running isort"], check=False)
isort_returncode = run(
["sh", "-c", f"isort {check_lint} --gitignore . --line-length 120 --profile black"], check=False
["sh", "-c", f"isort {check_lint} --gitignore {paths} --line-length 120 --profile black"], check=False
).returncode

if not hook:
Expand All @@ -30,7 +37,7 @@ def lint(
[
"sh",
"-c",
"pylint . --recursive=y --load-plugins=pylint.extensions.docstyle,pylint.extensions.docparams --disable=fixme,too-few-public-methods",
f"pylint {paths} --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",
Expand All @@ -45,15 +52,16 @@ def lint(

run(["sh", "-c", "echo Running pydocstyle"], check=False)
pydocstyle_returncode = run(
["sh", "-c", "pydocstyle .", "--add-ignore", "D107, D104, D103", "--convention", "google"], check=False
["sh", "-c", f"pydocstyle {paths}", "--add-ignore", "D107, D104, D103", "--convention", "google"],
check=False,
).returncode

run(["sh", "-c", "echo Running mypy"], check=False)
mypy_returncode = run(
[
"sh",
"-c",
'! mypy . --disallow-untyped-defs --disallow-incomplete-defs | grep "Function is missing" || false',
f'! mypy {paths} --disallow-untyped-defs --disallow-incomplete-defs | grep "Function is missing" || false',
],
check=False,
).returncode
Expand Down

0 comments on commit 0b88228

Please sign in to comment.