Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Scheltienne committed May 3, 2023
1 parent 414783a commit 05de5fa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 31 deletions.
16 changes: 4 additions & 12 deletions template/utils/_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def _ensure_int(item: Any, item_name: Optional[str] = None) -> int:
item = int(operator.index(item))
except TypeError:
item_name = "Item" if item_name is None else "'%s'" % item_name
raise TypeError(
f"{item_name} must be an integer, got {type(item)} instead."
)
raise TypeError(f"{item_name} must be an integer, got {type(item)} instead.")

return item

Expand Down Expand Up @@ -68,9 +66,7 @@ def __instancecheck__(cls, other: Any) -> bool:
}


def check_type(
item: Any, types: tuple, item_name: Optional[str] = None
) -> None:
def check_type(item: Any, types: tuple, item_name: Optional[str] = None) -> None:
"""Check that item is an instance of types.
Parameters
Expand Down Expand Up @@ -169,9 +165,7 @@ def check_value(
options += ", ".join([f"{repr(v)}" for v in allowed_values[:-1]])
options += f", and {repr(allowed_values[-1])}"
raise ValueError(
msg.format(
item_name=item_name, extra=extra, options=options, item=item
)
msg.format(item_name=item_name, extra=extra, options=options, item=item)
)


Expand Down Expand Up @@ -248,7 +242,5 @@ def ensure_path(item: Any, must_exist: bool) -> Path:
f"not {type(item)}."
)
if must_exist and not item.exists():
raise FileNotFoundError(
f"The provided path '{str(item)}' does not exist."
)
raise FileNotFoundError(f"The provided path '{str(item)}' does not exist.")
return item
4 changes: 1 addition & 3 deletions template/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def sys_info(fid: Optional[IO] = None, developer: bool = False):
# dependencies
out("\nCore dependencies\n")
dependencies = [Requirement(elt) for elt in requires(package)]
core_dependencies = [
dep for dep in dependencies if "extra" not in str(dep.marker)
]
core_dependencies = [dep for dep in dependencies if "extra" not in str(dep.marker)]
_list_dependencies_info(out, ljust, package, core_dependencies)

# extras
Expand Down
4 changes: 1 addition & 3 deletions template/utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@


@fill_doc
def _init_logger(
*, verbose: Optional[Union[bool, str, int]] = None
) -> logging.Logger:
def _init_logger(*, verbose: Optional[Union[bool, str, int]] = None) -> logging.Logger:
"""Initialize a logger.
Assigns sys.stdout as the first handler of the logger.
Expand Down
12 changes: 2 additions & 10 deletions template/utils/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@

import pytest

from .._checks import (
_ensure_int,
check_type,
check_value,
check_verbose,
ensure_path,
)
from .._checks import _ensure_int, check_type, check_value, check_verbose, ensure_path


def test_ensure_int():
Expand Down Expand Up @@ -61,9 +55,7 @@ def test_check_value():
# invalids
with pytest.raises(ValueError, match="Invalid value for the parameter."):
check_value(5, [1, 2, 3, 4])
with pytest.raises(
ValueError, match="Invalid value for the 'number' parameter."
):
with pytest.raises(ValueError, match="Invalid value for the 'number' parameter."):
check_value(5, [1, 2, 3, 4], "number")


Expand Down
4 changes: 1 addition & 3 deletions template/utils/tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def test_default_log_level(caplog):
assert "101" in caplog.text


@pytest.mark.parametrize(
"level", ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL")
)
@pytest.mark.parametrize("level", ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"))
def test_logger(level, caplog):
"""Test basic logger functionalities."""
level_functions = {
Expand Down

0 comments on commit 05de5fa

Please sign in to comment.