Skip to content

Commit 1bd8614

Browse files
henryiiiandrzejnovak
authored andcommitted
chore: add ruff TRY
Signed-off-by: Henry Schreiner <[email protected]>
1 parent b760c78 commit 1bd8614

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ extend-select = [
162162
"RUF", # Ruff-specific
163163
"SIM", # flake8-simplify
164164
"T20", # flake8-print
165+
"TRY", # tryceratops
165166
"UP", # pyupgrade
166167
"YTT", # flake8-2020
167168
"EXE", # flake8-executable

src/mplhep/_dev.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,22 @@ def _run_command_with_confirmation(
102102

103103
def _run_command(self, cmd: list[str], cwd: Path | None = None) -> bool:
104104
"""Run a command and return True if successful."""
105+
self._print_header(f"Running: {' '.join(cmd)}")
106+
separator = 3 * ("=" * self._get_terminal_width() + "\n")
107+
print(separator)
108+
105109
try:
106-
self._print_header(f"Running: {' '.join(cmd)}")
107-
separator = 3 * ("=" * self._get_terminal_width() + "\n")
108-
print(separator)
109110
result = subprocess.run(cmd, cwd=cwd or self.project_root, check=True)
110-
print(separator)
111-
return result.returncode == 0
112111
except subprocess.CalledProcessError as e:
113112
self._print_error(f"Command failed with exit code {e.returncode}")
114113
return False
115114
except FileNotFoundError:
116115
self._print_error(f"Command not found: {cmd[0]}")
117116
return False
118117

118+
print(separator)
119+
return result.returncode == 0
120+
119121
def _show_summary(self, items: list[Path], title: str) -> None:
120122
"""Show a formatted summary of items."""
121123
if not items:
@@ -856,13 +858,14 @@ def _check_tool_available(self, tool_name: str, check_cmd: list[str]) -> bool:
856858
result = subprocess.run(
857859
check_cmd, capture_output=True, text=True, check=True
858860
)
859-
self._print_success(f"{tool_name} version: {result.stdout.strip()}")
860-
return True
861861
except (subprocess.CalledProcessError, FileNotFoundError):
862862
self._print_error(f"{tool_name} not found!")
863863
self._print_warning(f"Please install {tool_name} to use this feature")
864864
return False
865865

866+
self._print_success(f"{tool_name} version: {result.stdout.strip()}")
867+
return True
868+
866869
def _handle_pytest_results_cleanup(self) -> None:
867870
"""Handle cleanup of pytest_results directory."""
868871
pytest_results = self.project_root / "pytest_results"

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def _has_latex():
1616
capture_output=True,
1717
timeout=5,
1818
)
19-
return True
2019
except (
2120
subprocess.CalledProcessError,
2221
subprocess.TimeoutExpired,
2322
FileNotFoundError,
2423
):
2524
return False
25+
return True
2626

2727

2828
def pytest_collection_modifyitems(config, items): # noqa: ARG001

0 commit comments

Comments
 (0)