Skip to content

Remove self type #266

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

Merged
merged 1 commit into from
Nov 12, 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
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions src/ansible_dev_environment/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions src/ansible_dev_environment/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
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:
self.args.requirement = Path(self.args.requirement).expanduser().resolve()
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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/ansible_dev_environment/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ 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():
collection_cache_dir.mkdir()
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():
collection_build_dir.mkdir()
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:
Expand Down
26 changes: 13 additions & 13 deletions src/ansible_dev_environment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config:

# pylint: disable=too-many-instance-attributes
def __init__(
self: Config,
self,
args: Namespace,
output: Output,
term_features: TermFeatures,
Expand All @@ -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
Expand All @@ -56,15 +56,15 @@ 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():
cache_dir.mkdir(parents=True)
return cache_dir

@property
def venv(self: Config) -> Path:
def venv(self) -> Path:
"""Return the virtual environment path.

Raises:
Expand All @@ -80,40 +80,40 @@ 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():
site_pkg_collections_path.mkdir()
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.
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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"
Expand Down
26 changes: 13 additions & 13 deletions src/ansible_dev_environment/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Loading