Skip to content

Commit

Permalink
Run ruff --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LowriJenkins committed Jul 12, 2024
1 parent d1291db commit 02e3d5d
Show file tree
Hide file tree
Showing 58 changed files with 428 additions and 711 deletions.
31 changes: 9 additions & 22 deletions SECI_Config_Analyser/Directory_Operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
# 3. for each file, parse XML for required tag and add value to list
# 4. remove duplicates from list

from os import listdir
from fnmatch import fnmatch
import xml.etree.ElementTree as ET

Check failure on line 6 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (N817)

SECI_Config_Analyser/Directory_Operations.py:6:8: N817 CamelCase `ElementTree` imported as acronym `ET`
from fnmatch import fnmatch
from os import listdir


class ReadConfigFiles:
"""
Reads SECI configuration files and extracts VI names
"""Reads SECI configuration files and extracts VI names
"""

Check failure on line 13 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D200)

SECI_Config_Analyser/Directory_Operations.py:12:5: D200 One-line docstring should fit on one line

Check failure on line 13 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D415)

SECI_Config_Analyser/Directory_Operations.py:12:5: D415 First line should end with a period, question mark, or exclamation point

def __init__(self, search_path):
"""
create lists for filenames and initialise to empty lists
"""Create lists for filenames and initialise to empty lists
call methods for reading directory contents and searching for config filenames
:param search_path: the search path for files
"""

Check failure on line 19 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D205)

SECI_Config_Analyser/Directory_Operations.py:16:9: D205 1 blank line required between summary line and description

Check failure on line 19 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D415)

SECI_Config_Analyser/Directory_Operations.py:16:9: D415 First line should end with a period, question mark, or exclamation point

self.full_path = search_path
self.directory_contents = listdir(self.full_path)
self.config_filenames = []
Expand All @@ -28,11 +25,9 @@ def __init__(self, search_path):
self._extract_config_filenames()

def _extract_config_filenames(self):
"""
extract SECI config (*.conf) & component (*.comp) filenames
"""Extract SECI config (*.conf) & component (*.comp) filenames
add to separate lists
"""

Check failure on line 30 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D205)

SECI_Config_Analyser/Directory_Operations.py:28:9: D205 1 blank line required between summary line and description

Check failure on line 30 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D415)

SECI_Config_Analyser/Directory_Operations.py:28:9: D415 First line should end with a period, question mark, or exclamation point

for filename in self.directory_contents:
if fnmatch(filename, "*.conf"):
self.config_filenames.append(filename)
Expand All @@ -41,12 +36,10 @@ def _extract_config_filenames(self):
self.comp_filenames.append(filename)

def _parse_vis_from_files(self, filenames):
"""
extracts VI names and paths from config files
"""Extracts VI names and paths from config files
:param filenames: list of filenames to process
:return: vis_in_files: list of VIs with fullpaths
"""

Check failure on line 42 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D205)

SECI_Config_Analyser/Directory_Operations.py:39:9: D205 1 blank line required between summary line and description

Check failure on line 42 in SECI_Config_Analyser/Directory_Operations.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (D415)

SECI_Config_Analyser/Directory_Operations.py:39:9: D415 First line should end with a period, question mark, or exclamation point

vis_in_files = []

for filename in filenames:
Expand All @@ -58,12 +51,10 @@ def _parse_vis_from_files(self, filenames):

@staticmethod
def _parse_file(filename_and_path):
"""
reads XML file and creates list of values for "FilePath" tag
"""Reads XML file and creates list of values for "FilePath" tag
:param filename_and_path: absolute path of file to be parsed
:return: vis_in_file: list of VIs in file
"""

vis_in_file = []
tree = ET.parse(filename_and_path)
root = tree.getroot()
Expand All @@ -75,12 +66,10 @@ def _parse_file(filename_and_path):

@staticmethod
def _remove_duplicates(input_list):
"""
remove duplicates from list, then sort alphabetically
"""Remove duplicates from list, then sort alphabetically
:param input_list: input list
:return: output_list: original list with duplicates removed
"""

# maintain list of "encountered" items in dummy list
# if item not in this list, add item to it and to output list

Expand All @@ -99,12 +88,10 @@ def _remove_duplicates(input_list):
return output_list

def analyse_config_files(self):
"""
call methods to process files
"""Call methods to process files
:return: config_vis: list containing absolute paths of VIs within SECI config file
:return: comp_vis: list containing absolute paths of VIs within SECI sub-config file
"""

config_vis = self._remove_duplicates(self._parse_vis_from_files(self.config_filenames))
comp_vis = self._remove_duplicates(self._parse_vis_from_files(self.comp_filenames))

Expand Down
6 changes: 3 additions & 3 deletions SECI_Config_Analyser/SECI_Config_Analyser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Script to analyse SECI configurations and components and output results to file
"""Script to analyse SECI configurations and components and output results to file
"""

from Directory_Operations import ReadConfigFiles
import argparse
from os import system

from Directory_Operations import ReadConfigFiles

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Analyse the SECI configuration files of specified instrument and output results to file"
Expand Down
8 changes: 4 additions & 4 deletions build_tools/check_builds_are_recent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os
from typing import Union
from datetime import datetime
import sys
import json
from datetime import datetime
from typing import Union

kits_root = r"\\isis\inst$\kits$\CompGroup\ICP"

Expand Down Expand Up @@ -85,7 +85,7 @@ def check_build_dirs(build_dirs):
if __name__ == "__main__":
builds_to_check = os.getenv("BUILDS_TO_CHECK")
if builds_to_check is None:
print(f"ERROR: BUILDS_TO_CHECK enviroment variable not set")
print("ERROR: BUILDS_TO_CHECK enviroment variable not set")
sys.exit(1)
try:
builds_by_stale_times = json.loads(builds_to_check)
Expand Down
2 changes: 1 addition & 1 deletion build_tools/purge_archive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob
import os
import shutil
import stat
import glob
from datetime import datetime, timedelta

max_build_age_in_days = 30
Expand Down
16 changes: 6 additions & 10 deletions data_gathering_scripts/data_sizes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Look at the size of
"""Look at the size of
"""

import getpass
import os
import subprocess

from six.moves import input

areas = {
Expand All @@ -32,16 +32,14 @@


class CalibrationsFolder:
"""
Context manager for accessing calibration folders on remote instruments.
"""Context manager for accessing calibration folders on remote instruments.
"""

DRIVE_LETTER = "q"

@staticmethod
def disconnect_from_drive():
"""
Returns: True if disconnect is successful, else False.
"""Returns: True if disconnect is successful, else False.
"""
return (
subprocess.call(
Expand All @@ -53,8 +51,7 @@ def disconnect_from_drive():
)

def connect_to_drive(self):
"""
Returns: True if the connection is successful, else False
"""Returns: True if the connection is successful, else False
"""
print("connecting")
net_use_cmd_line = [
Expand All @@ -73,8 +70,7 @@ def __init__(self, instrument_host, username, password):
self.password = password

def __enter__(self):
"""
Returns: A git repository for the remote calibration folder if connection is successful, else None.
"""Returns: A git repository for the remote calibration folder if connection is successful, else None.
"""
self.connect_to_drive()
return self
Expand Down
24 changes: 10 additions & 14 deletions data_gathering_scripts/nexus_file_sample_data_log.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
"""
Uses h5py to extract given log values from an ISIS NeXus file over a given time period. It is assumed
"""Uses h5py to extract given log values from an ISIS NeXus file over a given time period. It is assumed
that the control software has logged when values changed.
"""

# std imports
from argparse import ArgumentParser
from collections import OrderedDict
from datetime import datetime, timedelta
import logging
import os.path as osp
import sys
from argparse import ArgumentParser
from collections import OrderedDict
from datetime import datetime, timedelta

import numpy as np

# third party imports
from h5py import File as HDF5File
import numpy as np
from six import iteritems

# Logger for this module
Expand Down Expand Up @@ -48,8 +48,7 @@ def parse_args():


def fatal(msg, exit_code=1):
"""
End program by logging message and calling sys.exit with exit code = 1
"""End program by logging message and calling sys.exit with exit code = 1
:param msg: Message to display at error log level
:param exit_code: Exit code for program. Default=1
Expand All @@ -59,8 +58,7 @@ def fatal(msg, exit_code=1):


def logs_info(h5file, rel_time_start, names=None):
"""
Return values of log parameters when they change, i.e do not use every
"""Return values of log parameters when they change, i.e do not use every
log entry but only display values when they change.
:param h5file: Reference to H5File open at root level
Expand All @@ -82,8 +80,7 @@ def logs_info(h5file, rel_time_start, names=None):


def find_log_info(h5group, start_timestamp, rel_time_start):
"""
Assumes that the times in the time array are relative to run start
"""Assumes that the times in the time array are relative to run start
:param h5group: The open log entry group
:param start_timestamp: Start datetime of run
:param rel_time_start: A time relative to run start to begin processing logs
Expand Down Expand Up @@ -125,8 +122,7 @@ def append_value(value_list, time_in_seconds, value):


def write_out(info, out_file):
"""
:param info: The dictionary of log information
""":param info: The dictionary of log information
:param out_file: Destination to write output
"""
for log_name, values in iteritems(info):
Expand Down
8 changes: 3 additions & 5 deletions data_gathering_scripts/nexus_files_with_changing_blocks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
Utility
"""Utility
"""

import os
from datetime import datetime, timedelta

import h5py
import os

# List of machines to perform analysis for
machines = (
Expand All @@ -32,8 +31,7 @@


def check(machine, cycle, outf):
"""
Check that every data file contains the same blocks as previous data files or that the last data file is 1000s ago
"""Check that every data file contains the same blocks as previous data files or that the last data file is 1000s ago
:param machine: machine to look at
:param cycle: cycle to use
:param outf: file to output results to
Expand Down
30 changes: 11 additions & 19 deletions developer_support_script/build_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
Utility to help create build dependencies
"""Utility to help create build dependencies
"""

import argparse

import os
import re

Expand Down Expand Up @@ -301,8 +299,7 @@


def find(pattern, path):
"""
Find a file which matches a regex
"""Find a file which matches a regex
Args:
pattern: regex to find
path: path to start in
Expand All @@ -319,8 +316,7 @@ def find(pattern, path):


def macro_dependencies(ioc_dir):
"""
Get a list of possible dependenices for the macros
"""Get a list of possible dependenices for the macros
Args:
ioc_dir:
Expand Down Expand Up @@ -355,12 +351,10 @@ def macro_dependencies(ioc_dir):


def build_dependencies(ioc_dir):
"""
Create a list of dependencies from build.mak
"""Create a list of dependencies from build.mak
:param ioc_dir: path for the IOC
:return: set of dependencies
"""

file_list = find(r"(build.mak)|(Makefile)", ioc_dir)

if len(file_list) < 1:
Expand Down Expand Up @@ -388,8 +382,7 @@ def build_dependencies(ioc_dir):


def get_entries(dependencies, macros):
"""
Get entries to add to release file
"""Get entries to add to release file
Args:
dependencies: dependencies for the IOC
macros: macros to add (yes I know it is not nice but it works)
Expand All @@ -415,15 +408,14 @@ def get_entries(dependencies, macros):
)
print("A list of possible dependencies can be found in EPICS\\configure\\MASTER_RELEASE)")
exit(1)
sorted_lines = sorted([line for line in lines if line is not ""])
sorted_lines = sorted([line for line in lines if line != ""])
to_print = "\n".join(sorted_lines)
print(" - Adding lines:\n {}".format(to_print.replace("\n", "\n ")))
return sorted_lines


def write_extra_lines(outfile, lines):
"""
Add extra lines in to build file
"""Add extra lines in to build file
Args:
outfile: file to out to
lines: lines to add
Expand All @@ -435,8 +427,8 @@ def write_extra_lines(outfile, lines):


def replace_config_lines(lines, ioc_dir):
"""
Replace the expected config lines with generated lines.
"""Replace the expected config lines with generated lines.
Args:
lines: lines to replace.
ioc_dir: ioc directory
Expand Down Expand Up @@ -465,8 +457,8 @@ def replace_config_lines(lines, ioc_dir):


def replace_dependencies_in_release_file(base_dir):
"""
Replaces the dependencies in the RELEASE file with dependencies from the base directory.
"""Replaces the dependencies in the RELEASE file with dependencies from the base directory.
Args:
base_dir: the base directory which contains the release file
"""
Expand Down
Loading

0 comments on commit 02e3d5d

Please sign in to comment.