Skip to content

Commit

Permalink
Update linters (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jun 23, 2023
1 parent 7309984 commit 8f56b0c
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -8,7 +8,7 @@ default_language_version:
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
# keep it before yamllint
rev: "v3.0.0-alpha.6"
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
# Temporary excludes so we can gradually normalize the formatting
Expand All @@ -21,7 +21,7 @@ repos:
- prettier
- prettier-plugin-toml
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.5
hooks:
- id: codespell
- repo: https://github.com/psf/black
Expand All @@ -42,19 +42,19 @@ repos:
language_version: python3

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.30.0
rev: v1.32.0
hooks:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.262"
rev: "v0.0.275"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.4.0
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
Expand Down
1 change: 0 additions & 1 deletion src/molecule/interpolation.py
Expand Up @@ -98,7 +98,6 @@ def convert(mo):
# Check the most common path first.
named = mo.group("named") or mo.group("braced")
if named is not None:
# TODO(retr0h): This needs to be better handled.
if keep_string and named.startswith(keep_string):
return f"${named}"
if ":-" in named:
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/model/schema_v3.py
Expand Up @@ -71,7 +71,7 @@ def validate(c):
):
wrong_driver_name = str(exc.message.split()[0])
driver_name_err_msg = exc.schema["messages"]["anyOf"]
result.append(" ".join((wrong_driver_name, driver_name_err_msg)))
result.append(f"{wrong_driver_name} {driver_name_err_msg}")
else:
result.append(exc.message)

Expand Down
10 changes: 6 additions & 4 deletions src/molecule/provisioner/ansible.py
Expand Up @@ -20,12 +20,14 @@
"""Ansible Provisioner Module."""

# pylint: disable=too-many-lines
from __future__ import annotations

import collections
import copy
import logging
import os
import shutil
from typing import Any, Optional
from typing import Any

from ansible_compat.ports import cached_property

Expand Down Expand Up @@ -853,7 +855,7 @@ def manage_inventory(self):
else:
self._link_or_update_vars()

def abs_path(self, path: str) -> Optional[str]:
def abs_path(self, path: str) -> str | None:
return util.abs_path(os.path.join(self._config.scenario.directory, path))

def _add_or_update_vars(self):
Expand All @@ -869,7 +871,7 @@ def _add_or_update_vars(self):
for target in ["host_vars", "group_vars"]:
if target == "host_vars":
vars_target = copy.deepcopy(self.host_vars)
for instance_name, _ in self.host_vars.items():
for instance_name in self.host_vars.keys():
instance_key = instance_name
vars_target[instance_key] = vars_target.pop(instance_name)

Expand Down Expand Up @@ -985,7 +987,7 @@ def _get_modules_directories(self) -> list[str]:
Adds modules directory from molecule and its plugins.
"""
paths: list[Optional[str]] = []
paths: list[str | None] = []
if os.environ.get("ANSIBLE_LIBRARY"):
paths = list(map(util.abs_path, os.environ["ANSIBLE_LIBRARY"].split(":")))

Expand Down
1 change: 0 additions & 1 deletion src/molecule/provisioner/ansible_playbooks.py
Expand Up @@ -131,7 +131,6 @@ def _normalize_playbook(self, playbook):
Currently used to deprecate use of playbook.yml in favour of converge.yml
"""
# TODO(ssbarnea): Remove that deprecation fallback in 3.1+
if not playbook or os.path.isfile(playbook):
return playbook

Expand Down
1 change: 0 additions & 1 deletion src/molecule/scenario.py
Expand Up @@ -199,7 +199,6 @@ def sequence(self) -> list[str]:
if not isinstance(result, list):
raise RuntimeError("Unexpected sequence type {result}.")
except KeyError:
# TODO(retr0h): May change this handling in the future.
pass
return result

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/shell.py
Expand Up @@ -62,7 +62,7 @@ def print_version(ctx, param, value):

msg += f" [repr.attrib_name]ansible[/][dim]:[/][repr.number]{app.runtime.version}[/]"
for driver in drivers():
msg += f"\n [repr.attrib_name]{str(driver)}[/][dim]:[/][repr.number]{driver.version}[/][dim] from {driver.module}"
msg += f"\n [repr.attrib_name]{driver!s}[/][dim]:[/][repr.number]{driver.version}[/][dim] from {driver.module}"
if driver.required_collections:
msg += " requiring collections:"
for name, version in driver.required_collections.items():
Expand Down
2 changes: 0 additions & 2 deletions src/molecule/test/functional/test_command.py
Expand Up @@ -119,8 +119,6 @@ def test_command_create(scenario_to_test, with_scenario, scenario_name, tmp_path
cmd = ["molecule", "create", "--scenario-name", scenario_name]
assert run_command(cmd, env=os.environ).returncode == 0

# TODO(ssbarnea): Include these additional checks


@pytest.mark.parametrize(
("scenario_to_test", "driver_name", "scenario_name"),
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/test/unit/model/v2/test_driver_section.py
Expand Up @@ -75,7 +75,7 @@ def test_driver_has_errors(_config):
# add single quotes for string
driver_name = f"'{_config['driver']['name']}'"

error_msg = [" ".join((driver_name, base_error_msg))]
error_msg = [f"{driver_name} {base_error_msg}"]
assert error_msg == schema_v3.validate(_config)


Expand Down
13 changes: 0 additions & 13 deletions src/molecule/test/unit/model/v2/test_platforms_section.py
Expand Up @@ -30,16 +30,3 @@
)
def test_platforms_delegated(_config):
assert not schema_v3.validate(_config)


# todo: https://github.com/json-schema-org/json-schema-vocabularies/issues/22
# @pytest.mark.parametrize(
# def test_platforms_unique_names(_config):

# "platforms": [
# 0: [{"name": [f"'{instance_name}' is not unique"]}],
# 1: [{"name": [f"'{instance_name}' is not unique"]}],


# def test_platforms_driver_name_required(_config):
# if "platforms" in _config:

0 comments on commit 8f56b0c

Please sign in to comment.