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

Quick fixes #232

Merged
merged 1 commit into from
Jul 29, 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 .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 @@
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)

Check warning on line 104 in src/ansible_dev_environment/subcommands/treemaker.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/subcommands/treemaker.py#L104

Added line #L104 was not covered by tests
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)

Check warning on line 109 in src/ansible_dev_environment/subcommands/treemaker.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/subcommands/treemaker.py#L109

Added line #L109 was not covered by tests
if collection_name in value:
found = True
if not found:
Expand Down Expand Up @@ -141,12 +141,10 @@
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)

Check warning on line 144 in src/ansible_dev_environment/subcommands/treemaker.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/subcommands/treemaker.py#L144

Added line #L144 was not covered by tests
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)

Check warning on line 147 in src/ansible_dev_environment/subcommands/treemaker.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/subcommands/treemaker.py#L147

Added line #L147 was not covered by tests
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 @@
output.debug(cmd)
log_level = logging.ERROR - (verbose * 10)
if log_level == logging.DEBUG:
return subprocess_tee.run(
return subprocess_tee.run( # noqa: S604

Check warning on line 139 in src/ansible_dev_environment/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/utils.py#L139

Added line #L139 was not covered by tests
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 @@
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 @@
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}"

Check warning on line 438 in src/ansible_dev_environment/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/utils.py#L438

Added line #L438 was not covered by tests
else:
char = next(self.spinner)
char = next(self._spinner)

Check warning on line 440 in src/ansible_dev_environment/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_dev_environment/utils.py#L440

Added line #L440 was not covered by tests
sys.stdout.write(char)
self.spinner_visible = True
sys.stdout.flush()
Expand Down
Loading