Skip to content
Open
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
3 changes: 3 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore": ["./src/ibex_device_generator/templates"]
}
69 changes: 55 additions & 14 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,74 @@
# Exclude templates
# Exclude a variety of commonly ignored directories.
exclude = [
"templates",
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
"uk.ac.stfc.isis.ibex.opis",
"ReflectometryServer/test_modules/test_config/",
"src/ibex_device_generator/templates/6/",
"src/ibex_device_generator/templates/7/"
]

# Set the maximum line length to 79.
line-length = 79
# Set the maximum line length to 100.
line-length = 100
indent-width = 4

[lint]
extend-select = [
"N", # pep8-naming
"D", # pydocstyle
# "D", # pydocstyle (can use this later but for now causes too many errors)
"I", # isort (for imports)
"E501", # Line too long ({width} > {limit})
"ANN001", # Missing type annotation for function argument {name}
"ANN201", # Missing return type annotation for public function {name}
"ANN202", # Missing return type annotation for private function {name}
"ANN204", # Missing return type annotation for special method {name}
"ANN205", # Missing return type annotation for staticmethod {name}
"ANN206", # Missing return type annotation for classmethod {name}
"E",
"F",
"ANN",
]
ignore = [
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D406", # Section name should end with a newline ("{name}")
"D407", # Missing dashed underline after section ("{name}")
"N999", # Ignore this because the repo itself would need to be renamed
"ANN101", # ignore this until its removed in future versions
"ANN102", # ignore this until its removed in future versions
]
[lint.per-file-ignores]
"{**/tests/**,/tests/**,**/*tests.py,tests/**,*tests.py,*test.py,**/*test.py,common_tests/**,test_*.py}" = [
"N802",
"D100",
"D101",
"D102",
"E501",
"ANN",
]

[lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"

[format]
quote-style = "double"
indent-style = "space"
docstring-code-format = true
line-ending = "cr-lf"
line-ending = "auto"
6 changes: 2 additions & 4 deletions src/ibex_device_generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ibex_device_generator.utils.device_info import DeviceInfo


def _configure_logging(level: str = logging.INFO) -> None:
def _configure_logging(level: str = str(logging.INFO)) -> None:
logging.basicConfig(
level=level,
format="%(message)s",
Expand All @@ -26,9 +26,7 @@ def main() -> None:

_configure_logging(level=args.log_level)

device = DeviceInfo(
args.ioc_name, args.device_name, device_count=args.device_count
)
device = DeviceInfo(args.ioc_name, args.device_name, device_count=args.device_count)

IBEXDeviceGenerator(
device, args.use_git, args.github_token, args.ticket, args.interactive
Expand Down
16 changes: 4 additions & 12 deletions src/ibex_device_generator/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def __init__(self, name: str) -> None:

def __str__(self) -> str:
return (
"'%s' is an invalid device name,"
" it can only cantain ASCII characters." % self.name
"'%s' is an invalid device name," " it can only cantain ASCII characters." % self.name
)


Expand All @@ -101,10 +100,7 @@ def __init__(self, count: int) -> None:
self.count = count

def __str__(self) -> str:
return (
"'%d' is an invalid device count. This must be between 1 and 99."
% self.count
)
return "'%d' is an invalid device count. This must be between 1 and 99." % self.count


class ReassignPlaceholderError(IBEXDeviceGeneratorError):
Expand All @@ -114,10 +110,7 @@ def __init__(self, placeholder: str) -> None:
self.placeholder = placeholder

def __str__(self) -> str:
return (
"Cannot reassign value of '%s' after device info instantiation."
% self.placeholder
)
return "Cannot reassign value of '%s' after device info instantiation." % self.placeholder


# Git related
Expand All @@ -131,8 +124,7 @@ def __init__(self, path: str) -> None:

def __str__(self) -> str:
return (
"Cannot open git repository at %s."
" Check if git repo exists at location." % self.path
"Cannot open git repository at %s." " Check if git repo exists at location." % self.path
)


Expand Down
25 changes: 11 additions & 14 deletions src/ibex_device_generator/ibex_device_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Main file."""

import logging
from typing import Callable, ParamSpec

from rich.prompt import Confirm

Expand All @@ -25,6 +26,8 @@
create_submodule_structure,
)

P = ParamSpec("P")


class IBEXDeviceGenerator:
"""IBEX device generator."""
Expand Down Expand Up @@ -121,11 +124,11 @@ def run(self) -> None:

def add_step(
self,
repo_path: str,
repo_path: str | None,
commit_msg: str,
action: callable,
*args,
**kwargs,
action: Callable[P, None],
*args: P.args,
**kwargs: P.kwargs,
) -> None:
"""Add a generator step.

Expand All @@ -137,15 +140,11 @@ def add_step(
commit_msg: the commit message
action: the function to execute as this step
*args: any positional arguments for the action
**kwargs: any keywoprd arguments for the action
**kwargs: any keyword arguments for the action

"""
if self.interactive and not Confirm.ask(
f"Do '{commit_msg}'?", default="y"
):
logging.debug(
":right_arrow: Skipping step.", extra={"markup": True}
)
if self.interactive and not Confirm.ask(f"Do '{commit_msg}'?", default="y"):
logging.debug(":right_arrow: Skipping step.", extra={"markup": True})
return

try:
Expand All @@ -157,9 +156,7 @@ def add_step(
with commit_changes(repo_path, self.ticket_branch, commit_msg):
action(*args, **kwargs)
else:
logging.info(
f"Running '{commit_msg}'...", extra={"highlighter": None}
)
logging.info(f"Running '{commit_msg}'...", extra={"highlighter": None})
action(*args, **kwargs)

logging.info(
Expand Down
12 changes: 3 additions & 9 deletions src/ibex_device_generator/utils/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def parse_arguments() -> Namespace:
"""Parse cli arguments."""
parser = argparse.ArgumentParser(
description=(
"IBEX Device IOC Generator. "
"Generate boilerplate code for IBEX device support."
"IBEX Device IOC Generator. " "Generate boilerplate code for IBEX device support."
),
)
parser.add_argument(
Expand Down Expand Up @@ -68,10 +67,7 @@ def parse_arguments() -> Namespace:
parser.add_argument(
"--github_token",
type=str,
help=(
'GitHub token with "repo" scope. '
"Use to create support repository."
),
help=('GitHub token with "repo" scope. ' "Use to create support repository."),
)
parser.add_argument(
"--log_level",
Expand Down Expand Up @@ -124,7 +120,5 @@ def ticket_number_checker(val: str) -> int:
"""Check ticket number validity."""
ticket_number = int(val)
if not does_github_issue_exist_and_is_open(ticket_number):
raise ArgumentTypeError(
f"GitHub issue {ticket_number} is closed or does not exist."
)
raise ArgumentTypeError(f"GitHub issue {ticket_number} is closed or does not exist.")
return ticket_number
12 changes: 8 additions & 4 deletions src/ibex_device_generator/utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@


def run_command(
command: StrOrBytesPath | Sequence[StrOrBytesPath], working_dir: str
command: StrOrBytesPath | Sequence[StrOrBytesPath],
working_dir: str | PathLike,
) -> int:
"""Run a command using subprocess, waits for completion.

Expand All @@ -24,9 +25,12 @@ def run_command(
The exit code after running the command

"""
logging.info(
"Running command {} from {}".format(" ".join(command), working_dir)
)
if type(command) is Sequence:
logging.info(
"Running command {} from {}".format(" ".join([str(c) for c in command]), working_dir)
)
else:
logging.info("Running command {} from {}".format(command, working_dir))
with open(devnull, "w") as null_out:
cmd = subprocess.Popen(
command,
Expand Down
4 changes: 2 additions & 2 deletions src/ibex_device_generator/utils/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
self[p.INDEX] = "01" # noqa
# fmt: on

def __setitem__(self, key: Any, value: Any) -> None:
def __setitem__(self, key: Any, value: Any) -> None: # noqa - need to use any to fully overload
"""Disable value reassignment."""
if self.get(key) and key not in DeviceInfo.editable_substitutions:
# Prevent modifying values other than INDEX
Expand All @@ -101,7 +101,7 @@ def ioc_indexed_name(self, index: int) -> str:
if not 0 < index < 100:
raise InvalidDeviceCountError(index)

return "{}-IOC-{:02d}".format(self._ioc_name, index)
return "{}-IOC-{:02d}".format(self[p.IOC_NAME], index)

def ioc_boot_path(self, index: int) -> str:
"""Get IOCs indexed booth path.
Expand Down
13 changes: 4 additions & 9 deletions src/ibex_device_generator/utils/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from os.path import join


def _add_entry_to_list(text: str, list_name: str, entry: str) -> str:
"""Add entry to prefixed list in llist of strings.
def _add_entry_to_list(text: list[str], list_name: str, entry: str) -> list[str]:
"""Add entry to prefixed list in list of strings.

Check if 'list_name += entry' already exists in text and add it if not.

Expand Down Expand Up @@ -51,9 +51,7 @@ def add_to_makefile_list(directory: str, list_name: str, entry: str) -> bool:

"""
logging.info(
"Adding {} to list {} in Makefile for directory {}".format(
entry, list_name, directory
)
"Adding {} to list {} in Makefile for directory {}".format(entry, list_name, directory)
)
makefile = join(directory, "Makefile")
with open(makefile) as f:
Expand All @@ -63,10 +61,7 @@ def add_to_makefile_list(directory: str, list_name: str, entry: str) -> bool:

if old_lines == new_lines:
logging.warn(
(
f"Entry '{entry}' is already added to list '{list_name}' in"
f" '{makefile}'."
)
(f"Entry '{entry}' is already added to list '{list_name}' in" f" '{makefile}'.")
)
return False

Expand Down
Loading