From 1c4ea9f4c85fece8af41e55156d239de8d7c8616 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 12 Nov 2024 13:02:25 +0000 Subject: [PATCH] Remove self type (#266) --- .pre-commit-config.yaml | 13 +++++- pyproject.toml | 4 ++ src/ansible_dev_environment/arg_parser.py | 6 +-- src/ansible_dev_environment/cli.py | 14 +++---- src/ansible_dev_environment/collection.py | 8 ++-- src/ansible_dev_environment/config.py | 26 ++++++------ src/ansible_dev_environment/output.py | 26 ++++++------ .../subcommands/checker.py | 10 ++--- .../subcommands/inspector.py | 4 +- .../subcommands/installer.py | 24 +++++------ .../subcommands/lister.py | 4 +- .../subcommands/treemaker.py | 4 +- .../subcommands/uninstaller.py | 6 +-- src/ansible_dev_environment/tree.py | 10 ++--- src/ansible_dev_environment/utils.py | 14 +++---- tests/unit/test_cli.py | 16 ++++---- tests/unit/test_installer.py | 40 ++++++++++++++----- 17 files changed, 132 insertions(+), 97 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 561425a..fb937e5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,14 +59,23 @@ repos: - id: tox-ini-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.7.3 hooks: - id: ruff args: + - --fix - --exit-non-zero-on-fix + types_or: [python, pyi] + - id: ruff-format # must be after ruff + types_or: [python, pyi] + + - repo: https://github.com/psf/black # must be after ruff + rev: 24.10.0 + hooks: + - id: black - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v8.15.2 + rev: v8.16.0 hooks: - id: cspell name: Spell check with cspell diff --git a/pyproject.toml b/pyproject.toml index daaa97f..81b0a58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -333,6 +333,10 @@ line-length = 100 target-version = "py310" [tool.ruff.lint] +ignore = [ + "COM812", # conflicts with ISC001 on format + "ISC001" # conflicts with COM812 on format +] select = ["ALL"] [tool.ruff.lint.flake8-pytest-style] diff --git a/src/ansible_dev_environment/arg_parser.py b/src/ansible_dev_environment/arg_parser.py index 06724cc..9dd4aa3 100644 --- a/src/ansible_dev_environment/arg_parser.py +++ b/src/ansible_dev_environment/arg_parser.py @@ -223,7 +223,7 @@ class ArgumentParser(argparse.ArgumentParser): """A custom argument parser.""" def add_argument( # type: ignore[override] - self: ArgumentParser, + self, *args: Any, # noqa: ANN401 **kwargs: Any, # noqa: ANN401 ) -> None: @@ -244,7 +244,7 @@ def add_argument( # type: ignore[override] class CustomHelpFormatter(HelpFormatter): """A custom help formatter.""" - def __init__(self: CustomHelpFormatter, prog: str) -> None: + def __init__(self, prog: str) -> None: """Initialize the help formatter. Args: @@ -260,7 +260,7 @@ def __init__(self: CustomHelpFormatter, prog: str) -> None: ) def _format_action_invocation( - self: CustomHelpFormatter, + self, action: argparse.Action, ) -> str: """Format the action invocation. diff --git a/src/ansible_dev_environment/cli.py b/src/ansible_dev_environment/cli.py index 99448a8..fe7e0c6 100644 --- a/src/ansible_dev_environment/cli.py +++ b/src/ansible_dev_environment/cli.py @@ -24,14 +24,14 @@ class Cli: """The Cli class.""" - def __init__(self: Cli) -> None: + def __init__(self) -> None: """Initialize the CLI and parse CLI args.""" self.args: Namespace self.config: Config self.output: Output self.term_features: TermFeatures - def parse_args(self: Cli) -> None: + def parse_args(self) -> None: """Parse the command line arguments.""" self.args = parse() if hasattr(self.args, "requirement") and self.args.requirement: @@ -39,7 +39,7 @@ def parse_args(self: Cli) -> None: if self.args.cpi: self.args.requirement = Path(".config/source-requirements.yml").expanduser().resolve() - def init_output(self: Cli) -> None: + def init_output(self) -> None: """Initialize the output object.""" if not sys.stdout.isatty(): self.term_features = TermFeatures(color=False, links=False) @@ -57,7 +57,7 @@ def init_output(self: Cli) -> None: verbosity=self.args.verbose, ) - def args_sanity(self: Cli) -> None: + def args_sanity(self) -> None: """Perform some sanity checking on the args.""" # Missing args if ( @@ -88,7 +88,7 @@ def args_sanity(self: Cli) -> None: err = "Editable can not be used with a requirements file." self.output.critical(err) - def ensure_isolated(self: Cli) -> None: + def ensure_isolated(self) -> None: """Ensure the environment is isolated.""" env_vars = os.environ errored = False @@ -139,7 +139,7 @@ def ensure_isolated(self: Cli) -> None: self.output.critical(err) - def run(self: Cli) -> None: + def run(self) -> None: """Run the application.""" self.config = Config( args=self.args, @@ -153,7 +153,7 @@ def run(self: Cli) -> None: subcommand.run() self._exit() - def _exit(self: Cli) -> None: + def _exit(self) -> None: """Exit the application setting the return code.""" if self.output.call_count["error"]: sys.exit(1) diff --git a/src/ansible_dev_environment/collection.py b/src/ansible_dev_environment/collection.py index f84deca..c43f3b7 100644 --- a/src/ansible_dev_environment/collection.py +++ b/src/ansible_dev_environment/collection.py @@ -43,12 +43,12 @@ class Collection: # pylint: disable=too-many-instance-attributes original: str @property - def name(self: Collection) -> str: + def name(self) -> str: """Return the collection name.""" return f"{self.cnamespace}.{self.cname}" @property - def cache_dir(self: Collection) -> Path: + def cache_dir(self) -> Path: """Return the collection cache directory.""" collection_cache_dir = self.config.venv_cache_dir / self.name if not collection_cache_dir.exists(): @@ -56,7 +56,7 @@ def cache_dir(self: Collection) -> Path: return collection_cache_dir @property - def build_dir(self: Collection) -> Path: + def build_dir(self) -> Path: """Return the collection cache directory.""" collection_build_dir = self.cache_dir / "build" if not collection_build_dir.exists(): @@ -64,7 +64,7 @@ def build_dir(self: Collection) -> Path: return collection_build_dir @property - def site_pkg_path(self: Collection) -> Path: + def site_pkg_path(self) -> Path: """Return the site packages collection path. Returns: diff --git a/src/ansible_dev_environment/config.py b/src/ansible_dev_environment/config.py index 539ab73..a44482a 100644 --- a/src/ansible_dev_environment/config.py +++ b/src/ansible_dev_environment/config.py @@ -26,7 +26,7 @@ class Config: # pylint: disable=too-many-instance-attributes def __init__( - self: Config, + self, args: Namespace, output: Output, term_features: TermFeatures, @@ -47,7 +47,7 @@ def __init__( self.venv_interpreter: Path self.term_features: TermFeatures = term_features - def init(self: Config) -> None: + def init(self) -> None: """Initialize the configuration.""" if self.args.venv: self._create_venv = True @@ -56,7 +56,7 @@ def init(self: Config) -> None: self._set_site_pkg_path() @property - def cache_dir(self: Config) -> Path: + def cache_dir(self) -> Path: """Return the cache directory.""" cache_dir = self.venv / ".ansible-dev-environment" if not cache_dir.exists(): @@ -64,7 +64,7 @@ def cache_dir(self: Config) -> Path: return cache_dir @property - def venv(self: Config) -> Path: + def venv(self) -> Path: """Return the virtual environment path. Raises: @@ -80,22 +80,22 @@ def venv(self: Config) -> Path: raise SystemExit(1) # pragma: no cover # critical exits @property - def venv_cache_dir(self: Config) -> Path: + def venv_cache_dir(self) -> Path: """Return the virtual environment cache directory.""" return self.cache_dir @property - def discovered_python_reqs(self: Config) -> Path: + def discovered_python_reqs(self) -> Path: """Return the discovered python requirements file.""" return self.venv_cache_dir / "discovered_requirements.txt" @property - def discovered_bindep_reqs(self: Config) -> Path: + def discovered_bindep_reqs(self) -> Path: """Return the discovered system package requirements file.""" return self.venv_cache_dir / "discovered_bindep.txt" @property - def site_pkg_collections_path(self: Config) -> Path: + def site_pkg_collections_path(self) -> Path: """Return the site packages collection path.""" site_pkg_collections_path = self.site_pkg_path / "ansible_collections" if not site_pkg_collections_path.exists(): @@ -103,17 +103,17 @@ def site_pkg_collections_path(self: Config) -> Path: return site_pkg_collections_path @property - def venv_bindir(self: Config) -> Path: + def venv_bindir(self) -> Path: """Return the virtual environment bin directory.""" return self.venv / "bin" @property - def interpreter(self: Config) -> Path: + def interpreter(self) -> Path: """Return the current interpreter.""" return Path(sys.executable) @property - def galaxy_bin(self: Config) -> Path: + def galaxy_bin(self) -> Path: """Find the ansible galaxy command. Prefer the venv over the system package over the PATH. @@ -141,7 +141,7 @@ def galaxy_bin(self: Config) -> Path: raise SystemExit(1) # pragma: no cover # critical exits def _set_interpreter( - self: Config, + self, ) -> None: """Set the interpreter.""" if not self.venv.exists(): @@ -179,7 +179,7 @@ def _set_interpreter( self._output.debug(msg) self.venv_interpreter = venv_interpreter - def _set_site_pkg_path(self: Config) -> None: + def _set_site_pkg_path(self) -> None: """Use the interpreter to find the site packages path.""" command = ( f"{self.venv_interpreter} -c" diff --git a/src/ansible_dev_environment/output.py b/src/ansible_dev_environment/output.py index 0b17854..a056bc6 100644 --- a/src/ansible_dev_environment/output.py +++ b/src/ansible_dev_environment/output.py @@ -91,7 +91,7 @@ class Level(Enum): WARNING = "Warning" @property - def log_level(self: Level) -> int: + def log_level(self) -> int: """Return a log level. :returns: The log level @@ -125,7 +125,7 @@ def longest_formatted(cls) -> int: """ return max(len(str(member)) for member in cls) - def __str__(self: Level) -> str: + def __str__(self) -> str: """Return the exit message prefix as a string. Returns: @@ -144,7 +144,7 @@ class Msg: prefix: Level = Level.ERROR @property - def color(self: Msg) -> str: + def color(self) -> str: """Return a color for the prefix. :returns: The color for the prefix @@ -161,7 +161,7 @@ def color(self: Msg) -> str: return color_mapping[self.prefix] def to_lines( - self: Msg, + self, color: bool, # noqa: FBT001 width: int, with_prefix: bool, # noqa: FBT001 @@ -213,7 +213,7 @@ class Output: """Output functionality.""" def __init__( # pylint: disable=too-many-positional-arguments - self: Output, + self, log_file: str, log_level: str, log_append: str, @@ -258,7 +258,7 @@ def __init__( # pylint: disable=too-many-positional-arguments else: self.log_to_file = False - def critical(self: Output, msg: str) -> None: + def critical(self, msg: str) -> None: """Print a critical message to the console. Args: @@ -268,7 +268,7 @@ def critical(self: Output, msg: str) -> None: self.log(msg, level=Level.CRITICAL) sys.exit(1) - def debug(self: Output, msg: str) -> None: + def debug(self, msg: str) -> None: """Print a debug message to the console. Args: @@ -277,7 +277,7 @@ def debug(self: Output, msg: str) -> None: self.call_count["debug"] += 1 self.log(msg, level=Level.DEBUG) - def error(self: Output, msg: str) -> None: + def error(self, msg: str) -> None: """Print an error message to the console. Args: @@ -286,7 +286,7 @@ def error(self: Output, msg: str) -> None: self.call_count["error"] += 1 self.log(msg, level=Level.ERROR) - def hint(self: Output, msg: str) -> None: + def hint(self, msg: str) -> None: """Print a hint message to the console. Args: @@ -295,7 +295,7 @@ def hint(self: Output, msg: str) -> None: self.call_count["hint"] += 1 self.log(msg, level=Level.HINT) - def info(self: Output, msg: str) -> None: + def info(self, msg: str) -> None: """Print a hint message to the console. Args: @@ -304,7 +304,7 @@ def info(self: Output, msg: str) -> None: self.call_count["info"] += 1 self.log(msg, level=Level.INFO) - def note(self: Output, msg: str) -> None: + def note(self, msg: str) -> None: """Print a note message to the console. Args: @@ -313,7 +313,7 @@ def note(self: Output, msg: str) -> None: self.call_count["note"] += 1 self.log(msg, level=Level.NOTE) - def warning(self: Output, msg: str) -> None: + def warning(self, msg: str) -> None: """Print a warning message to the console. Args: @@ -322,7 +322,7 @@ def warning(self: Output, msg: str) -> None: self.call_count["warning"] += 1 self.log(msg, level=Level.WARNING) - def log(self: Output, msg: str, level: Level = Level.ERROR) -> None: + def log(self, msg: str, level: Level = Level.ERROR) -> None: """Print a message to the console. Args: diff --git a/src/ansible_dev_environment/subcommands/checker.py b/src/ansible_dev_environment/subcommands/checker.py index 99da3f7..71c493f 100644 --- a/src/ansible_dev_environment/subcommands/checker.py +++ b/src/ansible_dev_environment/subcommands/checker.py @@ -26,7 +26,7 @@ class Checker: """The dependency checker.""" - def __init__(self: Checker, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the checker. Args: @@ -38,14 +38,14 @@ def __init__(self: Checker, config: Config, output: Output) -> None: self._output: Output = output self._system_dep_missing: bool - def run(self: Checker) -> None: + def run(self) -> None: """Run the checker.""" builder_introspect(config=self._config, output=self._output) self._collection_deps() self.system_deps() self._python_deps() - def _collection_deps(self: Checker) -> None: # noqa: C901, PLR0912, PLR0915 + def _collection_deps(self) -> None: # noqa: C901, PLR0912, PLR0915 """Check collection dependencies.""" collections = collect_manifests( target=self._config.site_pkg_collections_path, @@ -131,7 +131,7 @@ def _collection_deps(self: Checker) -> None: # noqa: C901, PLR0912, PLR0915 self._output.note(msg) self._collections_missing = missing - def _python_deps(self: Checker) -> None: + def _python_deps(self) -> None: """Check Python dependencies.""" if self._system_dep_missing: msg = "System packages are missing. Python dependency checking may fail." @@ -179,7 +179,7 @@ def _python_deps(self: Checker) -> None: msg = f"Try running `pip install {' '.join(missing)}`." self._output.hint(msg) - def system_deps(self: Checker) -> None: + def system_deps(self) -> None: """Check the bindep file.""" msg = "Checking system packages." self._output.info(msg) diff --git a/src/ansible_dev_environment/subcommands/inspector.py b/src/ansible_dev_environment/subcommands/inspector.py index 81af182..0bb2b91 100644 --- a/src/ansible_dev_environment/subcommands/inspector.py +++ b/src/ansible_dev_environment/subcommands/inspector.py @@ -24,7 +24,7 @@ class Inspector: """The Inspector class.""" - def __init__(self: Inspector, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the Inspector. Args: @@ -34,7 +34,7 @@ def __init__(self: Inspector, config: Config, output: Output) -> None: self._config = config self._output = output - def run(self: Inspector) -> None: + def run(self) -> None: """Run the Inspector.""" collections = collect_manifests( target=self._config.site_pkg_collections_path, diff --git a/src/ansible_dev_environment/subcommands/installer.py b/src/ansible_dev_environment/subcommands/installer.py index 42d01e1..370701a 100644 --- a/src/ansible_dev_environment/subcommands/installer.py +++ b/src/ansible_dev_environment/subcommands/installer.py @@ -37,7 +37,7 @@ class Installer: RE_GALAXY_INSTALLED = re.compile(r"(\w+\.\w+):.*installed") - def __init__(self: Installer, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the installer. Args: @@ -48,7 +48,7 @@ def __init__(self: Installer, config: Config, output: Output) -> None: self._output = output self._current_collection_spec: str - def run(self: Installer) -> None: + def run(self) -> None: """Run the installer.""" if self._config.args.collection_specifier and any( "," in s for s in self._config.args.collection_specifier @@ -97,7 +97,7 @@ def run(self: Installer) -> None: ) self._output.note(msg) - def _install_core(self: Installer) -> None: + def _install_core(self) -> None: """Install ansible-core if not installed already.""" msg = "Installing ansible-core." self._output.info(msg) @@ -119,7 +119,7 @@ def _install_core(self: Installer) -> None: err = f"Failed to install ansible-core: {exc}" self._output.critical(err) - def _install_dev_tools(self: Installer) -> None: + def _install_dev_tools(self) -> None: """Install ansible developer tools.""" msg = "Installing ansible-dev-tools." self._output.info(msg) @@ -142,7 +142,7 @@ def _install_dev_tools(self: Installer) -> None: self._output.critical(err) def _install_galaxy_collections( - self: Installer, + self, collections: list[Collection], ) -> None: """Install the collection from galaxy. @@ -195,7 +195,7 @@ def _install_galaxy_collections( msg = f"Installed collections include: {oxford_join(installed)}" self._output.note(msg) - def _install_galaxy_requirements(self: Installer) -> None: + def _install_galaxy_requirements(self) -> None: """Install the collections using requirements.yml.""" method = "Pre-installing" if self._config.args.cpi else "Installing" msg = f"{method} collections from requirements file: {self._config.args.requirement}" @@ -242,7 +242,7 @@ def _install_galaxy_requirements(self: Installer) -> None: self._output.note(msg) def _find_files_using_git_ls_files( - self: Installer, + self, local_repo_path: Path | None, ) -> tuple[str | None, str | None]: """Copy collection files tracked using git ls-files to the build directory. @@ -274,7 +274,7 @@ def _find_files_using_git_ls_files( return "git ls-files", tracked_files_output.stdout def _find_files_using_ls( - self: Installer, + self, local_repo_path: Path | None, ) -> tuple[str | None, str | None]: """Copy collection files tracked using ls to the build directory. @@ -306,7 +306,7 @@ def _find_files_using_ls( return "ls", tracked_files_output.stdout def _copy_repo_files( - self: Installer, + self, local_repo_path: Path, destination_path: Path, ) -> None: @@ -363,7 +363,7 @@ def _copy_repo_files( self._output.critical(err) def _install_local_collection( - self: Installer, + self, collection: Collection, ) -> None: """Install the collection from the build directory. @@ -478,7 +478,7 @@ def _install_local_collection( msg = f"Installed collections include: {oxford_join(installed)}" self._output.note(msg) - def _swap_editable_collection(self: Installer, collection: Collection) -> None: + def _swap_editable_collection(self, collection: Collection) -> None: """Swap the installed collection with the current working directory. Args: @@ -500,7 +500,7 @@ def _swap_editable_collection(self: Installer, collection: Collection) -> None: self._output.debug(msg) collection.site_pkg_path.symlink_to(collection.path) - def _pip_install(self: Installer) -> None: + def _pip_install(self) -> None: """Install the dependencies.""" msg = "Installing python requirements." self._output.info(msg) diff --git a/src/ansible_dev_environment/subcommands/lister.py b/src/ansible_dev_environment/subcommands/lister.py index 70cf93c..744c2b4 100644 --- a/src/ansible_dev_environment/subcommands/lister.py +++ b/src/ansible_dev_environment/subcommands/lister.py @@ -15,7 +15,7 @@ class Lister: """The Lister class.""" - def __init__(self: Lister, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the Lister. Args: @@ -25,7 +25,7 @@ def __init__(self: Lister, config: Config, output: Output) -> None: self._config = config self._output = output - def run(self: Lister) -> None: + def run(self) -> None: """Run the Lister.""" collections = collect_manifests( target=self._config.site_pkg_collections_path, diff --git a/src/ansible_dev_environment/subcommands/treemaker.py b/src/ansible_dev_environment/subcommands/treemaker.py index b7d3b35..10e1b97 100644 --- a/src/ansible_dev_environment/subcommands/treemaker.py +++ b/src/ansible_dev_environment/subcommands/treemaker.py @@ -22,7 +22,7 @@ class TreeMaker: """Generate a dependency tree.""" - def __init__(self: TreeMaker, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the object. Args: @@ -32,7 +32,7 @@ def __init__(self: TreeMaker, config: Config, output: Output) -> None: self._config = config self._output = output - def run(self: TreeMaker) -> None: # noqa: C901, PLR0912, PLR0915 + def run(self) -> None: # noqa: C901, PLR0912, PLR0915 """Run the command.""" builder_introspect(self._config, self._output) diff --git a/src/ansible_dev_environment/subcommands/uninstaller.py b/src/ansible_dev_environment/subcommands/uninstaller.py index 9d27dba..7434939 100644 --- a/src/ansible_dev_environment/subcommands/uninstaller.py +++ b/src/ansible_dev_environment/subcommands/uninstaller.py @@ -22,7 +22,7 @@ class UnInstaller: """The uninstaller class.""" - def __init__(self: UnInstaller, config: Config, output: Output) -> None: + def __init__(self, config: Config, output: Output) -> None: """Initialize the installer. Args: @@ -33,7 +33,7 @@ def __init__(self: UnInstaller, config: Config, output: Output) -> None: self._output = output self._collection: Collection - def run(self: UnInstaller) -> None: + def run(self) -> None: """Run the uninstaller.""" if len(self._config.args.collection_specifier) > 1: msg = "Only one collection can be uninstalled at a time." @@ -60,7 +60,7 @@ def run(self: UnInstaller) -> None: ) self._remove_collection() - def _remove_collection(self: UnInstaller) -> None: + def _remove_collection(self) -> None: """Remove the collection.""" msg = f"Checking {self._collection.name} at {self._collection.site_pkg_path}" self._output.debug(msg) diff --git a/src/ansible_dev_environment/tree.py b/src/ansible_dev_environment/tree.py index 29ad0f3..2d90488 100644 --- a/src/ansible_dev_environment/tree.py +++ b/src/ansible_dev_environment/tree.py @@ -27,7 +27,7 @@ class Tree: # pylint: disable=R0902 SPACE_PREFIX = " " def __init__( - self: Tree, + self, obj: JSONVal, term_features: TermFeatures, ) -> None: @@ -53,7 +53,7 @@ def __init__( self.links: dict[str, str] = {} self.term_features = term_features - def in_color(self: Tree, val: ScalarVal) -> str: + def in_color(self, val: ScalarVal) -> str: """Colorize the string. Args: @@ -108,7 +108,7 @@ def is_scalar(obj: JSONVal) -> bool: return isinstance(obj, str | int | float | bool) or obj is None def _print_tree( # noqa: C901, PLR0912 # pylint: disable=too-many-positional-arguments - self: Tree, + self, obj: JSONVal, is_last: bool, # noqa: FBT001 is_root: bool, # noqa: FBT001 @@ -184,7 +184,7 @@ def _print_tree( # noqa: C901, PLR0912 # pylint: disable=too-many-positional-a err = f"Invalid type {type(obj)}" raise TypeError(err) - def append(self: Tree, string: str) -> None: + def append(self, string: str) -> None: """Append a line to the output. Args: @@ -192,7 +192,7 @@ def append(self: Tree, string: str) -> None: """ self._lines.append(string) - def render(self: Tree) -> str: + def render(self) -> str: """Render the root of the tree. Returns: diff --git a/src/ansible_dev_environment/utils.py b/src/ansible_dev_environment/utils.py index e4da9b1..4eaf872 100644 --- a/src/ansible_dev_environment/utils.py +++ b/src/ansible_dev_environment/utils.py @@ -46,7 +46,7 @@ class TermFeatures: color: bool links: bool - def any_enabled(self: TermFeatures) -> bool: + def any_enabled(self) -> bool: """Return True if any features are enabled. Returns: @@ -408,7 +408,7 @@ class Spinner: # pylint: disable=too-many-instance-attributes """A spinner.""" def __init__( - self: Spinner, + self, message: str, term_features: TermFeatures, delay: float = 0.1, @@ -430,7 +430,7 @@ def __init__( self.thread: threading.Thread self.msg: str = message.rstrip(".").rstrip(":").rstrip() - def write_next(self: Spinner) -> None: + def write_next(self) -> None: """Write the next char.""" with self._screen_lock: if not self.spinner_visible: @@ -443,7 +443,7 @@ def write_next(self: Spinner) -> None: sys.stdout.flush() def remove_spinner( - self: Spinner, + self, cleanup: bool = False, # noqa: FBT001,FBT002 ) -> None: """Remove the spinner. @@ -463,14 +463,14 @@ def remove_spinner( sys.stdout.write("\033[K") # clear line sys.stdout.flush() - def spinner_task(self: Spinner) -> None: + def spinner_task(self) -> None: """Spin the spinner.""" while self.busy: self.write_next() time.sleep(self.delay) self.remove_spinner() - def __enter__(self: Spinner) -> None: + def __enter__(self) -> None: """Enter the context handler.""" # set the start time self._start_time = time.time() @@ -488,7 +488,7 @@ def __enter__(self: Spinner) -> None: self.thread.start() def __exit__( - self: Spinner, + self, typ: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None, diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 586b257..793f883 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -203,35 +203,35 @@ def test_collections_in_user( usr_path = Path("/usr/share/ansible/collections") exists = Path.exists - def _exists(self: Path) -> bool: + def _exists(path: Path) -> bool: """Patch the exists method. Args: - self: Path object. + path: Path object. Returns: bool: True if the path exists. """ - if self == usr_path: + if path == usr_path: return True - return exists(self) + return exists(path) monkeypatch.setattr(Path, "exists", _exists) iterdir = Path.iterdir - def _iterdir(self: Path) -> list[Path] | Generator[Path, None, None]: + def _iterdir(path: Path) -> list[Path] | Generator[Path, None, None]: """Patch the iterdir method. Args: - self: Path object. + path: Path object. Returns: List of paths or generator. """ - if self == usr_path: + if path == usr_path: return [usr_path / "ansible_collections"] - return iterdir(self) + return iterdir(path) monkeypatch.setattr(Path, "iterdir", _iterdir) diff --git a/tests/unit/test_installer.py b/tests/unit/test_installer.py index 56339fe..8323590 100644 --- a/tests/unit/test_installer.py +++ b/tests/unit/test_installer.py @@ -1,5 +1,6 @@ # pylint: disable=C0302 """Tests for the installer.""" + from __future__ import annotations import os @@ -332,7 +333,13 @@ def test_multiple_specifiers( monkeypatch: The monkeypatch fixture. capsys: The capsys fixture. """ - command = ["ade", "install", "ansible.utils[dev,test]", "--venv", str(tmp_path / "venv")] + command = [ + "ade", + "install", + "ansible.utils[dev,test]", + "--venv", + str(tmp_path / "venv"), + ] monkeypatch.setattr("sys.argv", command) args = parse() installer = Installer( @@ -359,7 +366,14 @@ def test_editable_not_local( monkeypatch: The monkeypatch fixture. capsys: The capsys fixture. """ - command = ["ade", "install", "-e", "ansible.utils", "--venv", str(tmp_path / "venv")] + command = [ + "ade", + "install", + "-e", + "ansible.utils", + "--venv", + str(tmp_path / "venv"), + ] monkeypatch.setattr("sys.argv", command) args = parse() config = Config(args=args, output=output, term_features=output.term_features) @@ -369,11 +383,11 @@ def test_editable_not_local( config=config, ) - def install_core(self: Installer) -> None: + def install_core(installer: Installer) -> None: """Don't install core. Args: - self: The installer instance. + installer: Installer instance. """ monkeypatch.setattr(Installer, "_install_core", install_core) @@ -1193,20 +1207,28 @@ def test_local_collection_without_tar_install( config.init() installer = Installer(config=config, output=config._output) installer.run() - pre_mtime = os.lstat(config.site_pkg_collections_path / "ansible" / "posix").st_mtime + pre_mtime = os.lstat( + config.site_pkg_collections_path / "ansible" / "posix", + ).st_mtime - def install_local_collection(self: Installer, collection: Collection) -> None: + def install_local_collection(installer: Installer, collection: Collection) -> None: """Do nothing. Args: - self: The installer instance. + installer: Installer instance. collection: The collection to install. """ - monkeypatch.setattr(Installer, "_install_local_collection", install_local_collection) + monkeypatch.setattr( + Installer, + "_install_local_collection", + install_local_collection, + ) installer.run() - post_mtime = os.lstat(config.site_pkg_collections_path / "ansible" / "posix").st_mtime + post_mtime = os.lstat( + config.site_pkg_collections_path / "ansible" / "posix", + ).st_mtime assert post_mtime > pre_mtime