Skip to content

Commit

Permalink
Merge pull request #5 from ISISComputingGroup/ruff
Browse files Browse the repository at this point in the history
Ruff
  • Loading branch information
Tom-Willemsen authored Aug 6, 2024
2 parents 8ac9f6b + 83e6471 commit 3c91283
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eb211431b3d7ebf3d61bc2f1f79f52e137003943
2c039635bbef50f058e9d05cb863104f8dd56509
7 changes: 7 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Linter
on: [pull_request]
jobs:
call-workflow:
uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main
with:
compare-branch: origin/master
4 changes: 1 addition & 3 deletions hotfix_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
print(f"INFO: REPO_DIR: {os.environ['REPO_DIR']}")
print(f"INFO: UPSTREAM_BRANCH: {os.environ['UPSTREAM_BRANCH_CONFIG']}")
print(f"INFO: ARTEFACT_DIR: {os.environ['WORKSPACE']}")
print(
f"INFO: USE_TEST_INSTRUMENT_LIST: {os.environ['USE_TEST_INSTRUMENT_LIST']}"
)
print(f"INFO: USE_TEST_INSTRUMENT_LIST: {os.environ['USE_TEST_INSTRUMENT_LIST']}")
print(f"INFO: TEST_INSTRUMENT_LIST: {os.environ['TEST_INSTRUMENT_LIST']}")
print(f"INFO: DEBUG_MODE: {os.environ['DEBUG_MODE']}")

Expand Down
8 changes: 3 additions & 5 deletions utils/communication_utils/channel_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from enum import (
Enum,
)
from typing import Dict, Any
from typing import Any, Dict

from genie_python.channel_access_exceptions import (
ReadAccessException,
Expand All @@ -36,7 +36,7 @@ def __init__(
def get_value(
self,
pv,
) -> str | dict | None:
) -> str | dict | None:
"""Gets the value of the PV. Returns None if PV is unavailable.
:return: The PV value as a string, or None if there was an error.
"""
Expand Down Expand Up @@ -72,9 +72,7 @@ def get_inst_list(
:return: a list of strings of instrument names.
"""
pv_value = self.get_value("CS:INSTLIST")
return (
{} if pv_value is None else json.loads(self._dehex_and_decompress(pv_value))
)
return {} if pv_value is None else json.loads(self._dehex_and_decompress(pv_value))


class PvInterestingLevel(Enum):
Expand Down
1 change: 1 addition & 0 deletions utils/communication_utils/ssh_access.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module provides utilities for SSH access."""

from typing import Dict

import paramiko
Expand Down
6 changes: 4 additions & 2 deletions utils/hotfix_utils/InstrumentChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def split_git_log(self, git_log: str, prefix: str) -> dict:
if prefix is None or message.startswith(prefix):
commit_dict[hash] = message
return commit_dict

def check_instrument(self) -> dict:
"""Check if there are any hotfixes or uncommitted changes on AN instrument.
Expand Down Expand Up @@ -257,7 +257,9 @@ def check_instrument(self) -> dict:
)

# Check if any uncommitted changes are on the instrument
self.uncommitted_changes_enum, self.uncommitted_changes_messages = self.check_for_uncommitted_changes()
self.uncommitted_changes_enum, self.uncommitted_changes_messages = (
self.check_for_uncommitted_changes()
)

def as_string(self) -> str:
"""Return the Instrument object as a string.
Expand Down
47 changes: 31 additions & 16 deletions utils/hotfix_utils/RepoChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys

import requests
from packaging.version import Version, InvalidVersion
from packaging.version import InvalidVersion, Version

from utils.hotfix_utils.InstrumentChecker import InstrumentChecker

Expand Down Expand Up @@ -67,15 +67,15 @@ def get_insts_on_latest_ibex_via_inst_config(self) -> list:

latest_major_version = versions[-1].major
second_latest_major_version = latest_major_version - 1
print(f"INFO: checking versions {latest_major_version}.x.x and {second_latest_major_version}.x.x")
print(
f"INFO: checking versions {latest_major_version}.x.x and {second_latest_major_version}.x.x"
)

# filter out the instruments that are not on the latest version
insts_on_latest_ibex = [
inst["hostname"]
for inst in result_list
if (
inst["version"].major in [latest_major_version, second_latest_major_version]
)
if (inst["version"].major in [latest_major_version, second_latest_major_version])
]

return insts_on_latest_ibex
Expand Down Expand Up @@ -105,11 +105,10 @@ def check_instruments(self) -> None:

def update_instrument_status_lists(instrument, status_list_key, messages=None):
if messages:
instrument_status_lists[status_list_key].append({instrument.hostname : messages})
instrument_status_lists[status_list_key].append({instrument.hostname: messages})
else:
instrument_status_lists[status_list_key].append(instrument.hostname)


for hostname in instrument_list:
instrument = InstrumentChecker(hostname)
try:
Expand All @@ -119,17 +118,34 @@ def update_instrument_status_lists(instrument, status_list_key, messages=None):
print(instrument.as_string())

if instrument.commits_local_not_on_upstream_enum == CHECK.TRUE:
update_instrument_status_lists(instrument, self._commits_on_local_not_upstream_key, instrument.commits_local_not_on_upstream_messages)

update_instrument_status_lists(
instrument,
self._commits_on_local_not_upstream_key,
instrument.commits_local_not_on_upstream_messages,
)

if instrument.uncommitted_changes_enum == CHECK.TRUE:
update_instrument_status_lists(instrument, self._uncommitted_changes_key, instrument.uncommitted_changes_messages)

update_instrument_status_lists(
instrument,
self._uncommitted_changes_key,
instrument.uncommitted_changes_messages,
)

if instrument.commits_upstream_not_on_local_enum == CHECK.TRUE:
update_instrument_status_lists(instrument, self._commits_on_upstream_not_local_key, instrument.commits_upstream_not_on_local_messages)
update_instrument_status_lists(
instrument,
self._commits_on_upstream_not_local_key,
instrument.commits_upstream_not_on_local_messages,
)

if instrument.commits_local_not_on_upstream_enum == CHECK.UNDETERMINABLE or instrument.uncommitted_changes_enum == CHECK.UNDETERMINABLE or instrument.commits_upstream_not_on_local_enum == CHECK.UNDETERMINABLE:
update_instrument_status_lists(instrument, self._undeterminable_at_some_point_key)
if (
instrument.commits_local_not_on_upstream_enum == CHECK.UNDETERMINABLE
or instrument.uncommitted_changes_enum == CHECK.UNDETERMINABLE
or instrument.commits_upstream_not_on_local_enum == CHECK.UNDETERMINABLE
):
update_instrument_status_lists(
instrument, self._undeterminable_at_some_point_key
)

except Exception as e:
print(f"ERROR: Could not connect to {instrument.hostname} ({str(e)})")
Expand All @@ -140,8 +156,7 @@ def update_instrument_status_lists(instrument, status_list_key, messages=None):
(self._commits_on_local_not_upstream_key, "Commits on local not upstream"),
(self._commits_on_upstream_not_local_key, "Commits on upstream not on local"),
(self._undeterminable_at_some_point_key, "Undeterminable at some point"),
]

]

print("INFO: Summary of results")
for key, prefix in keys_and_prefixes:
Expand Down
4 changes: 1 addition & 3 deletions utils/jenkins_utils/jenkins_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def save_git_status(
"""
# log the output to a workspace file for viewing later
if not os.path.exists(
os.path.join(artefact_dir, "git_status")
):
if not os.path.exists(os.path.join(artefact_dir, "git_status")):
os.makedirs(os.path.join(artefact_dir, "git_status"))

with open(
Expand Down

0 comments on commit 3c91283

Please sign in to comment.