Skip to content

Ruff #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 6, 2024
Merged
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
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
@@ -1,4 +1,4 @@
"""Creates a RepoChecker object and calls the check_instruments method to check for changes in the instruments repository."""

Check failure on line 1 in hotfix_checker.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (E501)

hotfix_checker.py:1:89: E501 Line too long (125 > 88)

import os

Expand All @@ -7,10 +7,10 @@
# Load environment variables from .env file
load_dotenv(find_dotenv())

# importing here so it doesn't set variables that are populated from env vars before actually having the env vars loaded

Check failure on line 10 in hotfix_checker.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (E501)

hotfix_checker.py:10:89: E501 Line too long (120 > 88)
# needed for when running locally to get the contents of a .env fil
# Jenkins will have the env vars set in the pipeline
from utils.hotfix_utils.RepoChecker import RepoChecker

Check failure on line 13 in hotfix_checker.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (E402)

hotfix_checker.py:13:1: E402 Module level import not at top of file

if __name__ == "__main__":
if os.environ["DEBUG_MODE"] == "true":
Expand All @@ -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']}")

Check failure on line 21 in hotfix_checker.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (E501)

hotfix_checker.py:21:89: E501 Line too long (90 > 88)
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 @@ -19,7 +19,7 @@
CaChannelWrapper,
)

# Some instruments may not be available. If this is the case, we don't want to wait too long for the response which

Check failure on line 22 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (E501)

utils/communication_utils/channel_access.py:22:89: E501 Line too long (115 > 88)
# will never come (which would slow down the tests)
CHANNEL_ACCESS_TIMEOUT = 5

Expand All @@ -27,19 +27,19 @@
class ChannelAccessUtils(object):
"""Class containing utility methods for interacting with a PV."""

def __init__(

Check failure on line 30 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D107)

utils/communication_utils/channel_access.py:30:9: D107 Missing docstring in `__init__`
self,
pv_prefix="",

Check failure on line 32 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

utils/communication_utils/channel_access.py:32:9: ANN001 Missing type annotation for function argument `pv_prefix`
) -> None:
self.pv_prefix = pv_prefix

def get_value(
self,
pv,

Check failure on line 38 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

utils/communication_utils/channel_access.py:38:9: ANN001 Missing type annotation for function argument `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.
"""

Check failure on line 42 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D205)

utils/communication_utils/channel_access.py:40:9: D205 1 blank line required between summary line and description

Check failure on line 42 in utils/communication_utils/channel_access.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D401)

utils/communication_utils/channel_access.py:40:9: D401 First line of docstring should be in imperative mood: "Gets the value of the PV. Returns None if PV is unavailable."
try:
return CaChannelWrapper.get_pv_value(
"{}{}".format(
Expand Down Expand Up @@ -72,9 +72,7 @@
: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
Loading