Skip to content

Commit

Permalink
Quick fixes (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
cidrblock authored Jul 29, 2024
1 parent 722ad63 commit 0ba5248
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ repos:
- id: tox-ini-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.10
rev: v0.5.5
hooks:
- id: ruff
args:
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
"python.testing.unittestEnabled": false,
"triggerTaskOnSave.tasks": {
"pydoclint": ["*.py"]
},
"sonarlint.connectedMode.project": {
"connectionId": "ansible",
"projectKey": "ansible_ansible-dev-environment"
}
}
1 change: 1 addition & 0 deletions src/ansible_dev_environment/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def parse_collection_request( # noqa: PLR0915
output.debug(msg)
collection.path = path
msg = f"Setting collection path: {collection.path}"
output.debug(msg)
collection.opt_deps = string.split("[")[1].split("]")[0]
msg = f"Setting optional dependencies: {collection.opt_deps}"
output.debug(msg)
Expand Down
9 changes: 4 additions & 5 deletions src/ansible_dev_environment/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, TypeVar
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from .utils import TermFeatures


T = TypeVar("T", bound="Level")
GOLDEN_RATIO = 1.61803398875


Expand Down Expand Up @@ -109,7 +108,7 @@ def log_level(self: Level) -> int:
return mapping[self]

@classmethod
def _longest_name(cls: type[T]) -> int:
def _longest_name(cls) -> int:
"""Return the longest exit message prefix.
Returns:
Expand All @@ -118,7 +117,7 @@ def _longest_name(cls: type[T]) -> int:
return max(len(member.value) for member in cls)

@classmethod
def longest_formatted(cls: type[T]) -> int:
def longest_formatted(cls) -> int:
"""Return the longest exit message prefix.
Returns:
Expand Down Expand Up @@ -213,7 +212,7 @@ def to_lines(
class Output:
"""Output functionality."""

def __init__( # noqa: PLR0913
def __init__(
self: Output,
log_file: str,
log_level: str,
Expand Down
14 changes: 10 additions & 4 deletions src/ansible_dev_environment/subcommands/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@


class Installer:
"""The installer class."""
"""The installer class.
Attributes:
RE_GALAXY_INSTALLED: The regular expression to match galaxy installed collections
"""

RE_GALAXY_INSTALLED = re.compile(r"(\w+\.\w+):.*installed")

def __init__(self: Installer, config: Config, output: Output) -> None:
"""Initialize the installer.
Expand Down Expand Up @@ -180,7 +186,7 @@ def _install_galaxy_collections(
err = f"Failed to install collection: {exc}\n{exc.stderr}"
self._output.critical(err)
return
installed = re.findall(r"(\w+\.\w+):.*installed", proc.stdout)
installed = self.RE_GALAXY_INSTALLED.findall(proc.stdout)
msg = f"Installed collections include: {oxford_join(installed)}"
self._output.note(msg)

Expand Down Expand Up @@ -231,7 +237,7 @@ def _install_galaxy_requirements(self: Installer) -> None:
err = f"Failed to install collections: {exc} {exc.stderr}"
self._output.critical(err)

installed = re.findall(r"(\w+\.\w+):.*installed", proc.stdout)
installed = self.RE_GALAXY_INSTALLED.findall(proc.stdout)
if not self._config.args.cpi:
msg = f"Installed collections include: {oxford_join(installed)}"
else:
Expand Down Expand Up @@ -472,7 +478,7 @@ def _install_local_collection(
collection.cache_dir / "MANIFEST.json",
)

installed = re.findall(r"(\w+\.\w+):.*installed", proc.stdout)
installed = self.RE_GALAXY_INSTALLED.findall(proc.stdout)
msg = f"Installed collections include: {oxford_join(installed)}"
self._output.note(msg)

Expand Down
14 changes: 6 additions & 8 deletions src/ansible_dev_environment/subcommands/treemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ScalarVal = bool | str | float | int | None
JSONVal = ScalarVal | list["JSONVal"] | dict[str, "JSONVal"]

NOT_A_DICT = "Tree dict is not a dict."


class TreeMaker:
"""Generate a dependency tree."""
Expand Down Expand Up @@ -99,14 +101,12 @@ def run(self: TreeMaker) -> None: # noqa: C901, PLR0912, PLR0915
else:
pruned_tree_dict: JSONVal = {}
if not isinstance(pruned_tree_dict, dict):
msg = "Tree dict is not a dict."
raise TypeError(msg)
raise TypeError(NOT_A_DICT)
for collection_name in list(tree_dict.keys()):
found = False
for value in tree_dict.values():
if not isinstance(value, dict):
msg = "Tree dict is not a dict."
raise TypeError(msg)
raise TypeError(NOT_A_DICT)
if collection_name in value:
found = True
if not found:
Expand Down Expand Up @@ -141,12 +141,10 @@ def add_python_reqs(
TypeError: If the tree dict is not a dict.
"""
if not isinstance(tree_dict, dict):
msg = "Tree dict is not a dict."
raise TypeError(msg)
raise TypeError(NOT_A_DICT)
collection = tree_dict[collection_name]
if not isinstance(collection, dict):
msg = "Tree dict is not a dict."
raise TypeError(msg)
raise TypeError(NOT_A_DICT)
collection["python requirements"] = []

for dep in sorted(python_deps):
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_dev_environment/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def is_scalar(obj: JSONVal) -> bool:
"""
return isinstance(obj, str | int | float | bool) or obj is None

def _print_tree( # noqa: C901, PLR0913, PLR0912
def _print_tree( # noqa: C901, PLR0912
self: Tree,
obj: JSONVal,
is_last: bool, # noqa: FBT001
Expand Down
14 changes: 7 additions & 7 deletions src/ansible_dev_environment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ def subprocess_run( # noqa: PLR0913
output.debug(cmd)
log_level = logging.ERROR - (verbose * 10)
if log_level == logging.DEBUG:
return subprocess_tee.run(
return subprocess_tee.run( # noqa: S604
command,
check=True,
cwd=cwd,
env=env,
shell=True, # noqa: S604
shell=True,
text=True,
)
with Spinner(message=msg, term_features=output.term_features):
return subprocess.run(
return subprocess.run( # noqa: S602
command,
check=True,
cwd=cwd,
env=env,
shell=True, # noqa: S602
shell=True,
capture_output=True,
text=True,
)
Expand Down Expand Up @@ -420,7 +420,7 @@ def __init__(
term_features: Terminal features
delay: The delay between characters
"""
self.spinner = itertools.cycle(("|", "/", "-", "\\", "|", "/", "-"))
self._spinner = itertools.cycle(("|", "/", "-", "\\", "|", "/", "-"))
self.delay = delay
self.busy = False
self.spinner_visible = False
Expand All @@ -435,9 +435,9 @@ def write_next(self: Spinner) -> None:
with self._screen_lock:
if not self.spinner_visible:
if self._term_features.color:
char = f"{Ansi.GREY}{next(self.spinner)}{Ansi.RESET}"
char = f"{Ansi.GREY}{next(self._spinner)}{Ansi.RESET}"
else:
char = next(self.spinner)
char = next(self._spinner)
sys.stdout.write(char)
self.spinner_visible = True
sys.stdout.flush()
Expand Down

0 comments on commit 0ba5248

Please sign in to comment.