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

Rewrite duties using callables rather than subprocesses #21

Closed
pawamoy opened this issue Nov 29, 2022 · 0 comments
Closed

Rewrite duties using callables rather than subprocesses #21

pawamoy opened this issue Nov 29, 2022 · 0 comments

Comments

@pawamoy
Copy link
Owner

pawamoy commented Nov 29, 2022

It is a bit more work, but we spare some resources and it should make things faster.

@duty
def check_quality(ctx, files=PY_SRC_LIST):
    """
    Check the code quality.

    Parameters:
        ctx: The context instance (passed automatically).
        files: The files to check.
    """
    from flake8.main.cli import main as flake8

    ctx.run(flake8, args=[["--config=config/flake8.ini", *files]], title="Checking code quality", pty=PTY)
@duty
def check_docs(ctx):
    """
    Check if the documentation builds correctly.

    Parameters:
        ctx: The context instance (passed automatically).
    """
    from mkdocs.__main__ import cli as mkdocs

    Path("htmlcov").mkdir(parents=True, exist_ok=True)
    Path("htmlcov/index.html").touch(exist_ok=True)
    ctx.run(mkdocs, args=[["build", "-s"]], title="Building documentation")
@duty  # noqa: WPS231
def check_types(ctx):  # noqa: WPS231
    """
    Check that the code is correctly typed.

    Parameters:
        ctx: The context instance (passed automatically).
    """
    from mypy.main import main as mypy

    class LazyStdout(StringIO):
        def __repr__(self) -> str:
            return "stdout"
        def write(self, value):
            return sys.stdout.write(value)

    class LazyStderr(StringIO):
        def __repr__(self) -> str:
            return "stderr"
        def write(self, value):
            return sys.stderr.write(value)

    os.environ["MYPY_FORCE_COLOR"] = "1"
    ctx.run(
        mypy,
        kwargs={
            "args": ["--config-file", "config/mypy.ini", *PY_SRC_LIST],
            "stdout": LazyStdout(),
            "stderr": LazyStderr(),
            "clean_exit": True,
        },
        title="Type-checking",
        command=f"mypy --config-file config/mypy.ini {PY_SRC}",
    )

It will require pawamoy/failprint#16, pawamoy/failprint#15, and pawamoy/failprint#14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant