Skip to content
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

Switch to using ruff, re: python project template #140

Merged
merged 7 commits into from
Feb 17, 2025
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: 0 additions & 2 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
auto-update-conda: true
miniforge-version: latest
environment-file: environment.yml
- name: flake8
run: flake8 --statistics RefRed test scripts
- name: mypy type annotations
run: mypy RefRed test scripts
- name: dependencies synced
Expand Down
30 changes: 19 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ repos:
# args: ['--maxkb=4096']
- id: check-yaml

- repo: https://github.com/psf/black
rev: 24.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: black
exclude: test/data

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
exclude: dev-docs|docs|versioneer.py|RefRed/_version.py|create_graph.py|test/data
args: ['--extend-ignore=E999,F821,E402,E127']
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: |
dev-docs
docs
versioneer.py
RefRed/_version.py
create_graph.py
test/data
- id: ruff-format
exclude: |
dev-docs
docs
versioneer.py
RefRed/_version.py
create_graph.py
test/data
8 changes: 4 additions & 4 deletions RefRed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ._version import get_versions

# set by versioneer
__version__ = get_versions()['version']
__version__ = get_versions()["version"]
del get_versions

ORGANIZATION = 'neutrons'
APPNAME = 'RefRed'
WINDOW_TITLE = 'Liquids Reflectometer Reduction - '
ORGANIZATION = "neutrons"
APPNAME = "RefRed"
WINDOW_TITLE = "Liquids Reflectometer Reduction - "
8 changes: 4 additions & 4 deletions RefRed/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_config():
return cfg


class NotThisMethod(Exception):
class NotThisMethod(Exception): # noqa: N818
"""Exception raised if a method is not valid for the current scenario."""


Expand Down Expand Up @@ -192,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
tags = set([r for r in refs if re.search(r"\d", r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
Expand Down Expand Up @@ -273,7 +273,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):

if "-" in git_describe:
# TAG-NUM-gHEX
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
Expand Down Expand Up @@ -502,7 +502,7 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split('/'):
for i in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
Expand Down
14 changes: 8 additions & 6 deletions RefRed/about_dialog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from numpy.version import version as numpy_version_str
from matplotlib import __version__ as matplotlib_version_str
from RefRed import __version__ as RefRed_version_str
from qtpy import QtWidgets, QT_VERSION, PYQT_VERSION
import sys
import mantid

import lr_reduction
import mantid
from matplotlib import __version__ as matplotlib_version_str
from numpy.version import version as numpy_version_str
from qtpy import PYQT_VERSION, QT_VERSION, QtWidgets

from RefRed import __version__ as refred_version_str


class AboutDialog(object):
Expand All @@ -23,7 +25,7 @@ def display(self):

message = f"""RefRed - Liquids Reflectrometry Reduction program

RefRed version {RefRed_version_str}
RefRed version {refred_version_str}
Reduction version {lr_reduction.__version__}

Library versions:
Expand Down
9 changes: 5 additions & 4 deletions RefRed/autopopulatemaintable/auto_fill_widgets_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from qtpy.QtWidgets import QApplication
from qtpy import QtCore, QtGui
import time

from qtpy import QtCore, QtGui
from qtpy.QtWidgets import QApplication


class AutoFillWidgetsHandler(object):
def __init__(self, parent=None):
Expand All @@ -14,7 +15,7 @@ def setup(self):
self.parent.ui.progressBar_check5.setValue(0)
self.parent.ui.progressBar_check2.setVisible(False)
self.parent.ui.progressBar_check5.setVisible(False)
pixmap = QtGui.QPixmap(':/General/check_icon.png')
pixmap = QtGui.QPixmap(":/General/check_icon.png")
self.parent.ui.check1.setPixmap(pixmap)
self.parent.ui.check2.setPixmap(pixmap)
self.parent.ui.check3.setPixmap(pixmap)
Expand Down Expand Up @@ -48,7 +49,7 @@ def step1(self):
QApplication.processEvents()

def error_step1(self):
pixmap = QtGui.QPixmap(':/General/clear_icon.png')
pixmap = QtGui.QPixmap(":/General/clear_icon.png")
self.parent.ui.check1.setFixedWidth(25)
self.parent.ui.check1.setFixedHeight(25)
self.parent.ui.check1.setPixmap(pixmap)
Expand Down
12 changes: 6 additions & 6 deletions RefRed/autopopulatemaintable/extract_lconfigdataset_runs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class ExtractLConfigDataSetRuns(object):
'''This class get an array of LConfigDataSet and extract the data sets
"""This class get an array of LConfigDataSet and extract the data sets
and append them in a list that is returned

#TODO: this doesn't need to be a class
'''
"""

def __init__(self, lconfigdataset=None, data_type='data'):
def __init__(self, lconfigdataset=None, data_type="data"):
self.lconfigdataset = lconfigdataset
self.data_type = data_type

Expand All @@ -14,14 +14,14 @@ def list_runs(self):

for _lconfig in self.lconfigdataset:
if _lconfig is not None:
if self.data_type == 'data':
if self.data_type == "data":
_list_run = _lconfig.data_sets
else:
_list_run = _lconfig.norm_sets

if _list_run is not ['']:
if _list_run != [""]:
for _run in _list_run:
if _run != '':
if _run != "":
int_run = int(_run)
full_list_runs.append(int_run)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# standard imports

# third party imports
import numpy as np

# application imports
from RefRed.interfaces.mytablewidget import ReductionTableColumnIndex
from RefRed.reduction_table_handling.reduction_table_handler import ReductionTableHandler
from RefRed.tabledata import TableData


class PopulateReductionTableFromListLRData(object):

list_lrdata_sorted = None
list_wks_sorted = None
list_runs_sorted = None
Expand All @@ -20,7 +15,6 @@ class PopulateReductionTableFromListLRData(object):
THI_TOLERANCE = 0.015

def __init__(self, parent=None, list_lrdata=None, list_wks=None, list_run=None, list_nexus=None, is_data=True):

self.parent = parent
self.list_run = list_run
self.list_lrdata = list_lrdata
Expand Down
46 changes: 22 additions & 24 deletions RefRed/autopopulatemaintable/reductiontable_auto_fill.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# import sys
import time
import numpy as np
from itertools import chain

import numpy as np
from qtpy.QtWidgets import QApplication

from RefRed.calculations.run_sequence_breaker import RunSequenceBreaker
from RefRed.autopopulatemaintable.auto_fill_widgets_handler import AutoFillWidgetsHandler
from RefRed.autopopulatemaintable.extract_lconfigdataset_runs import ExtractLConfigDataSetRuns
from RefRed.thread.locate_run import LocateRunThread
from RefRed.calculations.load_list_nexus import LoadListNexus
from RefRed.calculations.sort_lrdata_list import SortLRDataList
from RefRed.calculations.lr_data import LRData
from RefRed.autopopulatemaintable.populate_reduction_table_from_list_lrdata import PopulateReductionTableFromListLRData
from RefRed.calculations.check_list_run_compatibility_and_display import CheckListRunCompatibilityAndDisplay
from RefRed.calculations.load_list_nexus import LoadListNexus
from RefRed.calculations.lr_data import LRData
from RefRed.calculations.run_sequence_breaker import RunSequenceBreaker
from RefRed.calculations.sort_lrdata_list import SortLRDataList
from RefRed.mantid_utility import MantidUtility
from RefRed.utilities import format_to_list
from RefRed.autopopulatemaintable.auto_fill_widgets_handler import AutoFillWidgetsHandler
from RefRed.nexus_utilities import get_run_number
from RefRed.thread.locate_run import LocateRunThread
from RefRed.utilities import format_to_list


class ReductionTableAutoFill(object):

list_full_file_name = []
list_nxs = []
list_lrdata = []
Expand All @@ -29,14 +29,13 @@ class ReductionTableAutoFill(object):
list_wks_sorted = []
list_nexus_sorted = []

data_type_selected = 'data'
data_type_selected = "data"
o_auto_fill_widgets_handler = None

def __init__(self, parent=None, list_of_run_from_input='', data_type_selected='data', reset_table=False):

def __init__(self, parent=None, list_of_run_from_input="", data_type_selected="data", reset_table=False):
self.parent = parent

if data_type_selected == 'data':
if data_type_selected == "data":
# add to norm box, previous loaded norm
_str_old_runs = self.retrieve_list_norm_previously_loaded()
if not _str_old_runs == "":
Expand All @@ -48,16 +47,16 @@ def __init__(self, parent=None, list_of_run_from_input='', data_type_selected='d
self.parent.ui.norm_sequence_lineEdit.setText(new_str)

self.browsing_files_flag = False
if not (self.parent.browsed_files[data_type_selected] is None):
if self.parent.browsed_files[data_type_selected] is not None:
self.browsing_files_flag = True

if list_of_run_from_input == '':
if list_of_run_from_input == "":
self.sorted_list_of_runs = []
if not self.browsing_files_flag:
return

if data_type_selected != 'data':
data_type_selected = 'norm'
if data_type_selected != "data":
data_type_selected = "norm"
self.data_type_selected = data_type_selected

self.init_variable()
Expand Down Expand Up @@ -85,13 +84,12 @@ def __init__(self, parent=None, list_of_run_from_input='', data_type_selected='d
self.run()

def merge_list_of_runs(self, new_runs=None):

# manual entry of the runs
self.raw_run_from_input = new_runs
self.calculate_discrete_list_of_runs() # step1 -> list_of_runs_from_input

self.big_table_data = None
if (not self.reset_table) and (self.data_type_selected == 'data'):
if (not self.reset_table) and (self.data_type_selected == "data"):
self.retrieve_bigtable_list_data_loaded() # step2 -> list_of_runs_from_lconfig

_full_list_of_runs = []
Expand Down Expand Up @@ -151,7 +149,7 @@ def loading_full_reductionTable(self):
_list_nexus_sorted = self.list_nexus_sorted
_list_runs_sorted = self.list_runs_sorted
# _data_type_selected = self.data_type_selected
_is_working_with_data_column = True if self.data_type_selected == 'data' else False
_is_working_with_data_column = True if self.data_type_selected == "data" else False

self.parent.ui.progressBar_check5.setMinimum(0)
self.parent.ui.progressBar_check5.setValue(0)
Expand Down Expand Up @@ -275,7 +273,7 @@ def updating_reductionTable(self):
list_runs_sorted = self.list_runs_sorted
list_wks_sorted = self.list_wks_sorted
list_nexus_sorted = self.list_nexus_sorted
is_data = True if self.data_type_selected == 'data' else False
is_data = True if self.data_type_selected == "data" else False
o_pop_reduction_table = PopulateReductionTableFromListLRData(
parent=self.parent,
list_lrdata=list_lrdata_sorted,
Expand All @@ -297,7 +295,7 @@ def init_filename_thread_array(self, sz):
_list_full_file_name = []
for i in range(sz):
_filename_thread_array.append(LocateRunThread())
_list_full_file_name.append('')
_list_full_file_name.append("")
self.filename_thread_array = _filename_thread_array
self.list_nxs = _list_full_file_name

Expand All @@ -320,7 +318,7 @@ def retrieve_list_norm_previously_loaded(self):
if parent is None:
return
_big_table_data = parent.big_table_data
_extract_runs = ExtractLConfigDataSetRuns(_big_table_data[:, 2], data_type='norm')
_extract_runs = ExtractLConfigDataSetRuns(_big_table_data[:, 2], data_type="norm")
_runs = _extract_runs.list_runs()
_str_runs = ",".join([str(run) for run in _runs])
return _str_runs
Expand All @@ -332,7 +330,7 @@ def remove_duplicate_runs(self):

def check_minimum_requirements(self):
_data_type_selected = self.data_type_selected
if _data_type_selected == 'data':
if _data_type_selected == "data":
return True

big_table_data = self.parent.big_table_data
Expand Down
3 changes: 2 additions & 1 deletion RefRed/browsing_runs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

from qtpy import QtWidgets

from RefRed import nexus_utilities


class BrowsingRuns(object):

list_files = None
list_runs = None

Expand Down
11 changes: 5 additions & 6 deletions RefRed/calculations/add_list_nexus.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from mantid.simpleapi import Plus

from RefRed.calculations.check_if_same_nxs_property import CheckIfSameNxsProperty
from RefRed.calculations.load_list_nexus import LoadListNexus
from RefRed.calculations.load_nexus import LoadNexus
from RefRed.calculations.check_if_same_nxs_property import CheckIfSameNxsProperty


class AddListNexus(object):

wks = None
addition_worked = True
prefix = 'data'
prefix = "data"

def __init__(
self, list_nexus=None, list_run=None, metadata_only=False, check_nexus_compatibility=True, prefix='data'
self, list_nexus=None, list_run=None, metadata_only=False, check_nexus_compatibility=True, prefix="data"
):
if list_nexus is None:
return
Expand All @@ -36,11 +36,10 @@ def __init__(
if len(_list_wks) > 1:
is_same_property = False
if check_nexus_compatibility:
check_same_property = CheckIfSameNxsProperty(list_wks=_list_wks, property_name='LambdaRequest')
check_same_property = CheckIfSameNxsProperty(list_wks=_list_wks, property_name="LambdaRequest")
is_same_property = check_same_property.is_same_property

else: # we force true

is_same_property = True

if is_same_property:
Expand Down
Loading
Loading