From 5e27d763b0ab7d0793192d4b947afd88a1047738 Mon Sep 17 00:00:00 2001 From: Tomas Perez Alvarez <72174660+Tomperez98@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:58:45 -0500 Subject: [PATCH] No new method (#32) Co-authored-by: Tomas Perez --- pyproject.toml | 2 +- pyrgo/cli/cmds/audit.py | 2 +- pyrgo/cli/cmds/build.py | 2 +- pyrgo/cli/cmds/check.py | 6 +++--- pyrgo/cli/cmds/clean.py | 2 +- pyrgo/cli/cmds/doc.py | 2 +- pyrgo/cli/cmds/fix.py | 2 +- pyrgo/cli/cmds/fmt.py | 2 +- pyrgo/cli/cmds/lock.py | 4 ++-- pyrgo/cli/cmds/sync.py | 4 ++-- pyrgo/cli/cmds/test.py | 2 +- pyrgo/core/_command_exec.py | 16 ++++++---------- tests/test_command_exec.py | 4 ++-- 13 files changed, 23 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 43fc3cf..f73a523 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/pyrgo/cli/cmds/audit.py b/pyrgo/cli/cmds/audit.py index 59fac85..b574302 100644 --- a/pyrgo/cli/cmds/audit.py +++ b/pyrgo/cli/cmds/audit.py @@ -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=[ diff --git a/pyrgo/cli/cmds/build.py b/pyrgo/cli/cmds/build.py index 8073bff..ed7aef8 100644 --- a/pyrgo/cli/cmds/build.py +++ b/pyrgo/cli/cmds/build.py @@ -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()], diff --git a/pyrgo/cli/cmds/check.py b/pyrgo/cli/cmds/check.py index 8c5eaed..e428a79 100644 --- a/pyrgo/cli/cmds/check.py +++ b/pyrgo/cli/cmds/check.py @@ -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: @@ -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), "--"], diff --git a/pyrgo/cli/cmds/clean.py b/pyrgo/cli/cmds/clean.py index 32eaa70..8cce0ad 100644 --- a/pyrgo/cli/cmds/clean.py +++ b/pyrgo/cli/cmds/clean.py @@ -32,7 +32,7 @@ def clean() -> None: program_execution = inform_and_run_program( commands=[ - PythonCommandExec.new( + PythonCommandExec( program="mypy.dmypy", ).add_args(args=["stop"]) ], diff --git a/pyrgo/cli/cmds/doc.py b/pyrgo/cli/cmds/doc.py index f04b561..b556911 100644 --- a/pyrgo/cli/cmds/doc.py +++ b/pyrgo/cli/cmds/doc.py @@ -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, ] diff --git a/pyrgo/cli/cmds/fix.py b/pyrgo/cli/cmds/fix.py index 38106dc..0e7816d 100644 --- a/pyrgo/cli/cmds/fix.py +++ b/pyrgo/cli/cmds/fix.py @@ -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"]) diff --git a/pyrgo/cli/cmds/fmt.py b/pyrgo/cli/cmds/fmt.py index e759744..94a9d98 100644 --- a/pyrgo/cli/cmds/fmt.py +++ b/pyrgo/cli/cmds/fmt.py @@ -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]: diff --git a/pyrgo/cli/cmds/lock.py b/pyrgo/cli/cmds/lock.py index dd2bfac..64a15a7 100644 --- a/pyrgo/cli/cmds/lock.py +++ b/pyrgo/cli/cmds/lock.py @@ -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( @@ -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( diff --git a/pyrgo/cli/cmds/sync.py b/pyrgo/cli/cmds/sync.py index b7c5702..02482d8 100644 --- a/pyrgo/cli/cmds/sync.py +++ b/pyrgo/cli/cmds/sync.py @@ -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=[ @@ -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"], diff --git a/pyrgo/cli/cmds/test.py b/pyrgo/cli/cmds/test.py index 2642b91..35b4500 100644 --- a/pyrgo/cli/cmds/test.py +++ b/pyrgo/cli/cmds/test.py @@ -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: diff --git a/pyrgo/core/_command_exec.py b/pyrgo/core/_command_exec.py index 506027c..aa2d43d 100644 --- a/pyrgo/core/_command_exec.py +++ b/pyrgo/core/_command_exec.py @@ -3,7 +3,6 @@ import subprocess import sys -from dataclasses import dataclass from typing import TYPE_CHECKING, Optional from result import Err, Ok, Result @@ -11,26 +10,23 @@ 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.""" diff --git a/tests/test_command_exec.py b/tests/test_command_exec.py index 4de0319..02c6dd9 100644 --- a/tests/test_command_exec.py +++ b/tests/test_command_exec.py @@ -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, @@ -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"], ),