Skip to content

Commit

Permalink
added support for codespell in linting - issue ploomber#71
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielOX committed Dec 25, 2023
1 parent 1aabfd3 commit aeba509
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 3 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 Expand Up @@ -205,3 +203,6 @@ def lint(files, exclude):

if returncode:
raise SystemExit("Error linting")

if __name__ == '__main__':
cli()
27 changes: 19 additions & 8 deletions src/pkgmt/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def run(self, cmd, fix):
header = "=" * 20
click.echo(f"{header} Running: {cmd_} {header}")
res = subprocess.run(cmd, cwd=self._cwd)

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

def check(self):
Expand All @@ -63,25 +65,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 +101,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:
flake_8_cmd = ["nbqa", "flake8"] + files + ["--extend-exclude", exclude_str_flake8]
codespell_cmd = ['codespell'] + files + ['*.ipynb'] + ["--skip", exclude_str_codespell]
else:
cmd = ["nbqa", "flake8"] + files
flake_8_cmd = ["nbqa", "flake8"] + files
codespell_cmd = ['codespell'] + files

runner.run(
cmd,
flake_8_cmd,
fix="Install nbqa jupytext and run: pkgmt format",
)
runner.run(
codespell_cmd,
fix="Install nbqa jupytext and run: pkgmt format",
)

Expand Down

0 comments on commit aeba509

Please sign in to comment.