Skip to content

Commit

Permalink
refactor: Reorganize CLI commands
Browse files Browse the repository at this point in the history
Also fix typing.
  • Loading branch information
pawamoy committed Apr 12, 2021
1 parent 7e86c9a commit 3497d2b
Show file tree
Hide file tree
Showing 29 changed files with 1,316 additions and 1,214 deletions.
2 changes: 2 additions & 0 deletions config/flake8.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ ignore =
WPS358
# noqa overuse
WPS402
# __all__ variables
WPS410
# __init__ modules with logic
WPS412
# print statements
Expand Down
22 changes: 11 additions & 11 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def check_types(ctx):
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY, nofail=True, quiet=True)
ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY)


@duty(silent=True, post=["clean_tests"])
Expand Down Expand Up @@ -308,7 +308,7 @@ def coverage(ctx):


@duty(pre=[lambda ctx: clean_tests.run()])
def test(ctx, match="", markers="", cpus="auto", sugar=True, verbose=False, cov=True):
def test(ctx, match="", markers="", cpus="auto", sugar: bool = True, verbose: bool = False, cov: bool = True):
"""
Run the test suite.
Expand All @@ -322,19 +322,19 @@ def test(ctx, match="", markers="", cpus="auto", sugar=True, verbose=False, cov=
cov: Compute coverage, default True.
"""
if WINDOWS and CI:
cpus = ["--dist", "no"]
verbose = ["-vv"]
sugar = ["-p", "no:sugar"]
cov = ["--no-cov"]
cpus_opts = ["--dist", "no"]
verbose_opts = ["-vv"]
sugar_opts = ["-p", "no:sugar"]
cov_opts = ["--no-cov"]
else:
cpus = ["--dist", "no"] if cpus == "no" else ["-n", cpus]
sugar = [] if sugar is True else ["-p", "no:sugar"]
verbose = [] if verbose is False else ["-vv"]
cov = [] if cov is True else ["--no-cov"]
cpus_opts = ["--dist", "no"] if cpus == "no" else ["-n", cpus]
sugar_opts = [] if sugar is True else ["-p", "no:sugar"]
verbose_opts = [] if verbose is False else ["-vv"]
cov_opts = [] if cov is True else ["--no-cov"]

match = ["-k", match] if match else []
markers = ["-m", markers] if markers else []
options = [*cov, *verbose, *sugar, *cpus, *match, *markers] # noqa: WPS221
options = [*cov_opts, *verbose_opts, *sugar_opts, *cpus_opts, *match, *markers] # noqa: WPS221

ctx.run(
["pytest", "-c", "config/pytest.ini", *options, "tests"],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tui = [
]

[project.scripts]
aria2p = "aria2p.cli:main"
aria2p = "aria2p.cli.main:main"

[project.urls]
Repository = "https://github.com/pawamoy/aria2p"
Expand Down
2 changes: 1 addition & 1 deletion src/aria2p/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def enable_logger(sink=sys.stderr, level="WARNING"):
logger.enable("aria2p")


__all__ = [ # noqa: WPS410 (the only __variable__ we use)
__all__ = [
"API",
"ClientException",
"Client",
Expand Down
2 changes: 1 addition & 1 deletion src/aria2p/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import sys

from aria2p.cli import main
from aria2p.cli.main import main

if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
11 changes: 7 additions & 4 deletions src/aria2p/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def __init__(self, client: Optional[Client] = None) -> None:
def __repr__(self) -> str:
return f"API({self.client!r})"

def add(
def add( # noqa: WPS231 (not that complex)
self,
uri: str,
options: OptionsType = None,
position: int = None,
) -> List[Download]: # noqa: WPS231 (not that complex)
) -> List[Download]:
"""
Add a download (guess its type).
Expand Down Expand Up @@ -406,7 +406,10 @@ def retry_downloads( # noqa: WPS231 (not that complex)
for download in downloads:
if not download.has_failed:
continue
uri = download.files[0].uris[0]["uri"] # noqa: WPS219 (deep access)
try:
uri = download.files[0].uris[0]["uri"] # noqa: WPS219 (deep access)
except IndexError:
continue
try:
new_download_gid = self.add_uris([uri], download.options)
except ClientException as error:
Expand Down Expand Up @@ -887,7 +890,7 @@ def split_input_file(self, lines): # noqa: WPS231 (not complex)
if block:
yield block

def parse_input_file(self, input_file: str) -> InputFileContentsType:
def parse_input_file(self, input_file: PathOrStr) -> InputFileContentsType:
"""
Parse a file with URIs or an aria2c input file.
Expand Down
Loading

0 comments on commit 3497d2b

Please sign in to comment.