Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
Fix deps (#91)
Browse files Browse the repository at this point in the history
* update dependencies
* add `cfg-lint --force` command
* update linting rules
* fix lint/sort
* update isort usage
  • Loading branch information
Kilo59 committed Jun 26, 2022
1 parent 744ebd1 commit e25a5ef
Show file tree
Hide file tree
Showing 7 changed files with 652 additions and 449 deletions.
3 changes: 1 addition & 2 deletions blue_chip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
~~~~~~~~~~~~~~~~~~~~~
"""
import pkg_resources
from invoke import Collection, Program # pylint: disable=import-error
from invoke import Collection, Program

import blue_chip.tasks

Expand All @@ -26,7 +26,6 @@ def get_version(pkg_name=PACKAGE_NAME):

PKG_VERSION = get_version()

# pylint: disable=invalid-name
program = Program(
namespace=Collection.from_module(blue_chip.tasks),
name=PACKAGE_NAME,
Expand Down
8 changes: 3 additions & 5 deletions blue_chip/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
- line-too-long
# black conflict
- bad-continuation
options:
logging-format-style: "fstr"
pep8:
options:
Expand All @@ -28,7 +26,7 @@
# Multi-line docstring summary should start at the first line
- D212
""",
"bc_audit.yaml": f"""strictness: veryhigh
"bc_audit.yaml": """strictness: veryhigh
test-warnings: false
doc-warnings: true
Expand All @@ -53,7 +51,7 @@
disable:
- PYR18
""",
"bc_default.yaml": f"""strictness: veryhigh
"bc_default.yaml": """strictness: veryhigh
test-warnings: false
doc-warnings: true
Expand Down Expand Up @@ -85,7 +83,7 @@
pep257:
run: True
""",
"bc_tests.yaml": f"""inherits:
"bc_tests.yaml": """inherits:
- bc_default.yaml
strictness: high
Expand Down
37 changes: 16 additions & 21 deletions blue_chip/tasks/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,31 @@

@task(
help={
"line-length": "How many characters per line to allow. [default: {}]".format(
constants.LINE_LENGTH
),
"line-length": "How many characters per line to allow."
f" [default: { constants.LINE_LENGTH}]",
"targets": "Paths/directories to format. [default: . ]",
},
)
def sort(ctx, line_length=constants.LINE_LENGTH, targets="."):
def sort(ctx, line_length=constants.LINE_LENGTH, targets=".", check=False):
"""Sort module imports."""
print("sorting imports ...")
args = [
"isort",
"--use-parentheses",
"--trailing-comma",
"--force-grid-wrap",
"0",
"--multi-line",
"3",
"--profile",
"black",
"-l",
str(line_length),
"-rc",
"--atomic",
targets,
]
if check:
args.append("--check-only")
ctx.run(" ".join(args))


def _fmt_cmd(line_length: int, targets: Union[str, List[str]]) -> str:
def _fmt_cmd(line_length: int, targets: Union[str, List[str]], check=False) -> str:
args = ["black", "--line-length", str(line_length)]
if check:
args.append("--check")
if isinstance(targets, (list, tuple, set)):
args.extend(targets)
else:
Expand All @@ -51,23 +48,21 @@ def _fmt_cmd(line_length: int, targets: Union[str, List[str]]) -> str:
@task(
pre=[sort],
help={
"line-length": "How many characters per line to allow. [default: {}]".format(
constants.LINE_LENGTH
),
"line-length": "How many characters per line to allow."
f" [default: {constants.LINE_LENGTH}]",
"targets": "Paths/directories to format. [default: . ]",
},
)
def fmt(ctx, line_length=constants.LINE_LENGTH, targets="."):
def fmt(ctx, line_length=constants.LINE_LENGTH, targets=".", check=False):
"""Format python source code & sort imports."""
print("formatting ...")
ctx.run(_fmt_cmd(line_length, targets))
ctx.run(_fmt_cmd(line_length, targets, check))


@task(
help={
"line-length": "How many characters per line to allow. [default: {}]".format(
constants.LINE_LENGTH
),
"line-length": "How many characters per line to allow."
f" [default: {constants.LINE_LENGTH}]",
"targets": "Paths/directories to format. [default: . ]",
},
)
Expand Down
10 changes: 4 additions & 6 deletions blue_chip/tasks/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@

from blue_chip import config, constants

# pylint:disable=protected-access

__all__ = ["cfg_lint", "lint"]


STAR_SEP = "*" * get_terminal_size().columns


@task
def cfg_lint(ctx): # pylint:disable=unused-argument
def cfg_lint(ctx, force=False): # pylint:disable=unused-argument
"""Configure prospector profiles."""
if constants.BC_LINTRC_PATH.exists():
if constants.BC_LINTRC_PATH.exists() and not force:
return
lintrc_path = pathlib.Path(constants.BC_LINTRC_PATH)
lintrc_path.mkdir(exist_ok=False)
lintrc_path.mkdir(exist_ok=True)
for profile_name, profile_content in config.data.LINT_DATA.items():
profile_path = lintrc_path / profile_name
print(f" Initializing {profile_name} ...")
with open(profile_path, mode="w") as f_out:
with open(profile_path, mode="w", encoding="utf-8") as f_out:
f_out.write(profile_content)
print(
"Lint configuration profiles created at:\n",
Expand Down
Loading

0 comments on commit e25a5ef

Please sign in to comment.