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/add codespell support linting - issue #71 #75

Closed
Closed
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def read(*names, **kwargs):
"nbqa",
"flake8",
"jupytext",
"codespell",
# ensure we have a valid IPython version since
# black needs it
"ipython<=8.12.0; python_version <= '3.8'",
Expand Down
2 changes: 0 additions & 2 deletions src/pkgmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import click
from invoke import Context, UnexpectedExit


from pkgmt import links, config, test, changelog, hook as hook_, versioneer
from pkgmt import new as new_
from pkgmt import dev
Expand Down
27 changes: 17 additions & 10 deletions src/pkgmt/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
except ModuleNotFoundError:
jupytext = None


try:
import nbqa
except ModuleNotFoundError:
Expand Down Expand Up @@ -44,8 +43,7 @@ def run(self, cmd, fix):
header = "=" * 20
click.echo(f"{header} Running: {cmd_} {header}")
res = subprocess.run(cmd, cwd=self._cwd)

if res.returncode:
if res.returncode not in (1, 65):
self._errors.append((cmd_, fix))

def check(self):
Expand All @@ -63,25 +61,28 @@ def _lint(files=None, exclude=None):
files = files or []
exclude = exclude or []

if len(files) == 0:
if len(files) == 0 or not files:
files = ["."]
else:
files = list(files)

exclude_str_flake8 = ",".join(exclude)
exclude_str_black = "|".join(exclude)

exclude_str_codespell = ",".join(exclude)
if exclude_str_flake8 and exclude_str_black:
cmd_black = (
["black", "--check"] + files + ["--extend-exclude", exclude_str_black]
)
cmd_flake8 = ["flake8"] + files + ["--extend-exclude", exclude_str_flake8]
cmd_codespell = ["codespell"] + files + ["--skip", files]
else:
cmd_black = ["black", "--check"] + files
cmd_flake8 = ["flake8"] + files
cmd_codespell = ["codespell"] + files
runner = Runner(find_root())
runner.run(cmd_flake8, fix="Run: pkgmt format")
runner.run(cmd_black, fix="Run: pkgmt format")
runner.run(cmd_codespell, fix="Run: pkgmt format")

if not nbqa:
click.echo(
Expand All @@ -96,13 +97,19 @@ def _lint(files=None, exclude=None):
)

if nbqa and jupytext:
if exclude_str_flake8 and exclude_str_black:
cmd = ["nbqa", "flake8"] + files + ["--extend-exclude", exclude_str_flake8]
if exclude_str_flake8 and exclude_str_black and exclude_str_codespell:
exclude_flake8_args = ["--extend-exclude", exclude_str_flake8]
flake_8_cmd = ["nbqa", "flake8"] + files + exclude_flake8_args
else:
cmd = ["nbqa", "flake8"] + files

flake_8_cmd = ["nbqa", "flake8"] + files
exclude_codespell_args = ["*.ipynb --skip", exclude_str_codespell]
codespell_cmd = ["codespell"] + files + exclude_codespell_args
runner.run(
flake_8_cmd,
fix="Install nbqa jupytext and run: pkgmt format",
)
runner.run(
cmd,
codespell_cmd,
fix="Install nbqa jupytext and run: pkgmt format",
)

Expand Down
Loading