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

No new method #32

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyrgo"
version = "2.2.2"
version = "2.2.3"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def audit(env: str, *, fix: bool) -> None:
config = PyrgoConf.new()
ensure_env_exist(env=env, config=config, where="lock-files")

pip_audit_cmd = PythonCommandExec.new(
pip_audit_cmd = PythonCommandExec(
program="pip_audit",
).add_args(
args=[
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build() -> None:
"""Build project with `build`."""
program_execution = inform_and_run_program(
commands=[
PythonCommandExec.new(
PythonCommandExec(
program="build",
).add_args(
[PyrgoConf.new().cwd.as_posix()],
Expand Down
6 changes: 3 additions & 3 deletions pyrgo/cli/cmds/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _build_vulture_cmd(
vulture_allowlist: str,
) -> PythonCommandExec:
configuration.cwd.joinpath(vulture_allowlist).touch(exist_ok=True)
vulture_command = PythonCommandExec.new(
vulture_command = PythonCommandExec(
program="vulture",
)
if add_noqa:
Expand Down Expand Up @@ -60,10 +60,10 @@ def _build_vulture_cmd(
def check(*, timeout: int, add_noqa: bool, ignore_noqa: bool) -> None:
"""Check code with `mypy`, `ruff` and `vulture`."""
configuration = PyrgoConf.new()
ruff_command = PythonCommandExec.new(
ruff_command = PythonCommandExec(
program="ruff",
)
mypy_command = PythonCommandExec.new(
mypy_command = PythonCommandExec(
program="mypy.dmypy",
).add_args(
args=["run", "--timeout", str(timeout), "--"],
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def clean() -> None:

program_execution = inform_and_run_program(
commands=[
PythonCommandExec.new(
PythonCommandExec(
program="mypy.dmypy",
).add_args(args=["stop"])
],
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def doc(output_dir: Optional[str], port: Optional[int]) -> None:
"""Build a package's documentation with `pdoc`."""
configuration = PyrgoConf.new()
pdoc_command = PythonCommandExec.new(program="pdoc").add_args(
pdoc_command = PythonCommandExec(program="pdoc").add_args(
args=[
configuration.project_name,
]
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def fix() -> None:
"""Automatically fix lint warnings reported by `ruff`."""
configuration = PyrgoConf.new()
ruff_command = (
PythonCommandExec.new(
PythonCommandExec(
program="ruff",
)
.add_args(args=["--unsafe-fixes", "--fix"])
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def fmt() -> None:
"""Format code with `ruff`."""
configuration = PyrgoConf.new()
fmt_command = PythonCommandExec.new(
fmt_command = PythonCommandExec(
program="ruff",
).add_args(args=["format", "."])
for command in [fmt_command]:
Expand Down
4 changes: 2 additions & 2 deletions pyrgo/cli/cmds/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def lock(*, generate_hashes: bool, envs: tuple[str, ...], upgrade: bool) -> None
if execution_mode == "all":
all_commands.extend(
_complete_cmd(
cmd=PythonCommandExec.new(
cmd=PythonCommandExec(
program="piptools",
).add_args(
args=_initial_args(
Expand All @@ -118,7 +118,7 @@ def lock(*, generate_hashes: bool, envs: tuple[str, ...], upgrade: bool) -> None
if env in configuration.env_groups:
all_commands.append(
_complete_cmd(
cmd=PythonCommandExec.new(
cmd=PythonCommandExec(
program="piptools",
).add_args(
args=_initial_args(
Expand Down
4 changes: 2 additions & 2 deletions pyrgo/cli/cmds/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def sync(env: str, *, editable: bool) -> None:
config = PyrgoConf.new()
ensure_env_exist(env=env, config=config, where="lock-files")

piptools_command = PythonCommandExec.new(
piptools_command = PythonCommandExec(
program="piptools",
).add_args(
args=[
Expand All @@ -40,7 +40,7 @@ def sync(env: str, *, editable: bool) -> None:
.as_posix(),
],
)
pip_command = PythonCommandExec.new(
pip_command = PythonCommandExec(
program="pip",
).add_args(
args=["install", "--no-deps"],
Expand Down
2 changes: 1 addition & 1 deletion pyrgo/cli/cmds/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
def test(marker: Optional[str]) -> None:
"""Run tests with `pytest`."""
pytest_command = PythonCommandExec.new(
pytest_command = PythonCommandExec(
program="pytest",
)
if marker is not None:
Expand Down
16 changes: 6 additions & 10 deletions pyrgo/core/_command_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,30 @@

import subprocess
import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional

from result import Err, Ok, Result

if TYPE_CHECKING:
import pathlib
from io import TextIOWrapper
from pathlib import Path

from typing_extensions import Self

from pyrgo.typing import PyrgoProgram


@dataclass(frozen=False)
class PythonCommandExec:
"""Python command executor."""

args: list[str]
output_file: Optional[pathlib.Path]

@classmethod
def new(
cls: type[PythonCommandExec],
def __init__(
self,
program: PyrgoProgram,
) -> PythonCommandExec:
) -> None:
"""Build a new command executor."""
return cls(args=[sys.executable, "-m", program], output_file=None)
self.args: list[str] = [sys.executable, "-m", program]
self.output_file: Path | None = None

def add_output_file(self, file: pathlib.Path) -> Self:
"""Add output file to command."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_command_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestPythonCommandExec:
@pytest.mark.parametrize(argnames="program", argvalues=["ruff", "pip"])
def test_new(self, program: PyrgoProgram) -> None:
assert PythonCommandExec.new(program=program).args == [
assert PythonCommandExec(program=program).args == [
sys.executable,
"-m",
program,
Expand All @@ -25,7 +25,7 @@ def test_new(self, program: PyrgoProgram) -> None:
argnames=["command", "args", "expected"],
argvalues=[
(
PythonCommandExec.new(program="pip"),
PythonCommandExec(program="pip"),
["1", "2"],
["pip", "1", "2"],
),
Expand Down
Loading