From c46e94d16b530c8ea257aa84063cfd0acc7a095f Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Wed, 2 Sep 2020 13:45:32 +0100 Subject: [PATCH] Upgrade with pyupgrade - More concise super() - No more future, six imports - Implicit object inheritance - f-strings --- conftest.py | 4 +-- dui_app/write_setpath.py | 2 -- setup.py | 2 +- src/dui/__init__.py | 1 - src/dui/cli_utils.py | 14 ++++---- src/dui/custom_widgets.py | 34 +++++++++---------- src/dui/dynamic_reindex_gui.py | 21 +++++------- src/dui/gui_utils.py | 28 +++++++-------- src/dui/m_idials.py | 6 ++-- src/dui/m_idials_gui.py | 17 ++++------ src/dui/main_dui.py | 3 +- src/dui/outputs_gui.py | 3 +- src/dui/outputs_n_viewers/__init__.py | 2 -- .../outputs_n_viewers/compyling_boost_ext.py | 1 - src/dui/outputs_n_viewers/img_view_tools.py | 8 ++--- src/dui/outputs_n_viewers/img_viewer.py | 18 ++++------ src/dui/outputs_n_viewers/info_handler.py | 5 ++- src/dui/outputs_n_viewers/web_page_view.py | 6 ++-- src/dui/params_live_gui_generator.py | 11 +++--- src/dui/qt.py | 1 - src/dui/simpler_param_widgets.py | 21 +++++------- tests/test_basic_functions.py | 2 -- tests/test_basic_styles.py | 2 -- tests/test_gui_utils.py | 2 -- 24 files changed, 85 insertions(+), 129 deletions(-) diff --git a/conftest.py b/conftest.py index 072da42f..c7744e11 100644 --- a/conftest.py +++ b/conftest.py @@ -51,7 +51,7 @@ def screenshots(qapp, qtbot, request): if not os.path.isdir(ss_dir): os.mkdir(ss_dir) - class SSSaver(object): + class SSSaver: """Returnable object to save test-context screenshots""" def __init__(self, root_path): @@ -63,7 +63,7 @@ def _filename(self): test_file_name = os.path.splitext( os.path.basename(request.node.parent.name) )[0] - return "{}__{}_{}.png".format(test_file_name, request.node.name, self.count) + return f"{test_file_name}__{request.node.name}_{self.count}.png" def saveWidget(self, widget, filename=None): """Save a widget screenshot.""" diff --git a/dui_app/write_setpath.py b/dui_app/write_setpath.py index 04f7b803..b9d22be8 100644 --- a/dui_app/write_setpath.py +++ b/dui_app/write_setpath.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import logging import sys diff --git a/setup.py b/setup.py index f05b9526..7da5a8e1 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ def run(self): directory, ui_filename = os.path.split(infile) py_filename = ui_filename.replace(".ui", ".py") outfile = os.path.join(directory, "ui_" + py_filename) - print("Compiling: {0} -> {1}".format(infile, outfile)) + print(f"Compiling: {infile} -> {outfile}") self._compile_ui(infile, outfile) diff --git a/src/dui/__init__.py b/src/dui/__init__.py index 09b92933..1b6f268d 100644 --- a/src/dui/__init__.py +++ b/src/dui/__init__.py @@ -8,7 +8,6 @@ copyright (c) CCP4 - DLS """ -from __future__ import absolute_import, division, print_function from ._version import __version__ # noqa F401 diff --git a/src/dui/cli_utils.py b/src/dui/cli_utils.py index b2bdbd08..0b659b36 100644 --- a/src/dui/cli_utils.py +++ b/src/dui/cli_utils.py @@ -7,7 +7,6 @@ copyright (c) CCP4 - DLS """ -from __future__ import absolute_import, division, print_function import json import logging @@ -15,7 +14,6 @@ import subprocess import libtbx.phil -from six.moves import range # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -35,7 +33,7 @@ logger = logging.getLogger(__name__) -class SysArgvData(object): +class SysArgvData: """ Some data related to how the GUI gets launched from CLI """ @@ -101,7 +99,7 @@ def get_next_step(node_obj): return None -class ScopeData(object): +class ScopeData: """ class conceived to store only data related to the scope Phil object """ @@ -109,7 +107,7 @@ class conceived to store only data related to the scope Phil object pass -class tree_2_lineal(object): +class tree_2_lineal: """ Recursively navigates the Phil objects in a way that the final @@ -540,7 +538,7 @@ def generate_report(node_obj): return rep_out -class DialsCommand(object): +class DialsCommand: def __init__(self): logger.debug("creating new DialsCommand (obj)") self.full_cmd_lst = [None] @@ -664,7 +662,7 @@ def print_list(lst, curr): logger.info(stp_str) -class TreeShow(object): +class TreeShow: def __init__(self): self.ind_spc = " " self.ind_lin = "------" @@ -696,7 +694,7 @@ def add_tree(self, step=None, indent=None): else: stp_prn = " N " - str_lin_num = "{0:3}".format(int(step.lin_num)) + str_lin_num = "{:3}".format(int(step.lin_num)) stp_prn += str_lin_num + self.ind_spc * indent + r" \___" stp_prn += str(step.ll_command_lst[0][0]) diff --git a/src/dui/custom_widgets.py b/src/dui/custom_widgets.py index c907c85b..f16bbbb6 100644 --- a/src/dui/custom_widgets.py +++ b/src/dui/custom_widgets.py @@ -20,7 +20,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import logging import os @@ -34,7 +33,6 @@ from dials.command_line.refine_bravais_settings import ( phil_scope as phil_scope_r_b_settings, ) -from six.moves import range from dui.cli_utils import sys_arg from dui.gui_utils import get_import_run_string, get_main_path @@ -99,17 +97,17 @@ class BeamCentrPage(QWidget): b_centr_set = Signal() def __init__(self, parent=None): - super(BeamCentrPage, self).__init__(parent=None) + super().__init__(parent=None) main_v_box = QVBoxLayout() label_font = QFont() sys_font_point_size = label_font.pointSize() label_font.setPointSize(sys_font_point_size + 2) - step_label = QLabel(str("Modify Geometry")) + step_label = QLabel("Modify Geometry") step_label.setFont(label_font) - self.data_bc_label = QLabel(str("empty Data ... for now")) + self.data_bc_label = QLabel("empty Data ... for now") main_v_box.addWidget(step_label) main_v_box.addStretch() @@ -162,11 +160,11 @@ def set_par(self, lst_par): class InnerMask(QWidget): def __init__(self, parent=None): - super(InnerMask, self).__init__(parent=None) + super().__init__(parent=None) self.outher_box = QVBoxLayout() self.list_widg = QVBoxLayout() - self.list_widg.addWidget(QLabel(str("empty List ... for now"))) + self.list_widg.addWidget(QLabel("empty List ... for now")) self.outher_box.addStretch() self.outher_box.addLayout(self.list_widg) self.outher_box.addStretch() @@ -198,14 +196,14 @@ class MaskPage(QWidget): """ def __init__(self, parent=None): - super(MaskPage, self).__init__(parent=None) + super().__init__(parent=None) main_v_box = QVBoxLayout() label_font = QFont() sys_font_point_size = label_font.pointSize() label_font.setPointSize(sys_font_point_size + 2) - step_label = QLabel(str("Apply Mask")) + step_label = QLabel("Apply Mask") step_label.setFont(label_font) self.my_scroll_area = QScrollArea() @@ -259,17 +257,17 @@ class ExportPage(QWidget): """ def __init__(self, parent=None): - super(ExportPage, self).__init__(parent=None) + super().__init__(parent=None) main_v_box = QVBoxLayout() label_font = QFont() sys_font_point_size = label_font.pointSize() label_font.setPointSize(sys_font_point_size + 2) - step_label = QLabel(str("Export")) + step_label = QLabel("Export") step_label.setFont(label_font) - out_file_label = QLabel(str("mtz output name:")) + out_file_label = QLabel("mtz output name:") self.simple_lin = QLineEdit(self) self.simple_lin.textChanged.connect(self.update_command) @@ -278,7 +276,7 @@ def __init__(self, parent=None): self.check_scale.setChecked(False) self.check_scale.stateChanged.connect(self.update_command) - self.warning_label = QLabel(str(" ")) + self.warning_label = QLabel(" ") self.warning_label.setWordWrap(True) main_v_box.addWidget(step_label) @@ -372,14 +370,14 @@ class ImportPage(QWidget): """ def __init__(self, parent=None): - super(ImportPage, self).__init__(parent=None) + super().__init__(parent=None) main_v_box = QVBoxLayout() label_font = QFont() sys_font_point_size = label_font.pointSize() label_font.setPointSize(sys_font_point_size + 2) - step_label = QLabel(str("Import")) + step_label = QLabel("Import") step_label.setFont(label_font) self.simple_lin = QLineEdit(self) @@ -562,7 +560,7 @@ def activate_me(self, cur_nod=None): class ParamAdvancedWidget(QWidget): def __init__(self, phl_obj=None, parent=None): - super(ParamAdvancedWidget, self).__init__() + super().__init__() self.scrollable_widget = PhilWidget(phl_obj, parent=self) scrollArea = QScrollArea() @@ -644,7 +642,7 @@ class ParamMainWidget(QWidget): update_command_lst_low_level = Signal(list) def __init__(self, phl_obj=None, simp_widg=None, parent=None, upper_label=None): - super(ParamMainWidget, self).__init__() + super().__init__() self.command_lst = [[None]] self.lst_pair = [] @@ -889,7 +887,7 @@ class ParamWidget(QWidget): update_command_lst_medium_level = Signal(list) def __init__(self, label_str): - super(ParamWidget, self).__init__() + super().__init__() self.my_label = label_str inner_widgs = { diff --git a/src/dui/dynamic_reindex_gui.py b/src/dui/dynamic_reindex_gui.py index fa08a05d..c4698d42 100644 --- a/src/dui/dynamic_reindex_gui.py +++ b/src/dui/dynamic_reindex_gui.py @@ -21,14 +21,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function - import json import logging import os import sys -from six.moves import range from dui.cli_utils import sys_arg from dui.qt import ( @@ -58,7 +55,7 @@ def choice_if_decimal(num_in): - str_f = "{:6.2f}".format(num_in) + str_f = f"{num_in:6.2f}" if str_f[-3:] == ".00": str_out = str_f[0:-3] @@ -81,11 +78,11 @@ def ops_list_from_json(json_path=None): for inner_key in value: if inner_key == "rmsd": rmsd_val = value["rmsd"] - rmsd_str = " {:7.2}".format(rmsd_val) + rmsd_str = f" {rmsd_val:7.2}" elif inner_key == "min_cc": min_cc_val = value["min_cc"] - min_cc_str = " {:7.2}".format(min_cc_val) + min_cc_str = f" {min_cc_val:7.2}" if "Non" in min_cc_str: min_cc_str = " - " @@ -97,7 +94,7 @@ def ops_list_from_json(json_path=None): elif inner_key == "max_cc": max_cc_val = value["max_cc"] - max_cc_str = " {:7.2}".format(max_cc_val) + max_cc_str = f" {max_cc_val:7.2}" if "Non" in max_cc_str: max_cc_str = " - " @@ -115,7 +112,7 @@ def ops_list_from_json(json_path=None): elif inner_key == "max_angular_difference": angular_diff_val = value["max_angular_difference"] - angular_diff_str = " {:7.2} ".format(angular_diff_val) + angular_diff_str = f" {angular_diff_val:7.2} " elif inner_key == "correlation_coefficients": # corr_coeff_val = value["correlation_coefficients"] @@ -175,7 +172,7 @@ def heather_text_from_lin(lin_num, j_path): logger.debug("my_file_path: ", my_file_path) - myfile = open(my_file_path, "r") + myfile = open(my_file_path) all_lines = myfile.readlines() myfile.close() @@ -212,7 +209,7 @@ class ReindexTable(QTableWidget): opt_signal = Signal(int) def __init__(self, parent=None): - super(ReindexTable, self).__init__(parent) + super().__init__(parent) self.cellClicked.connect(self.opt_clicked) @@ -348,7 +345,7 @@ def del_opts_lst(self): class MyReindexOpts(QWidget): def __init__(self, parent=None): - super(MyReindexOpts, self).__init__(parent) + super().__init__(parent) self.setWindowTitle("Reindex") def set_ref(self, in_json_path, lin_num): @@ -407,7 +404,7 @@ def set_ref(self, in_json_path, lin_num): class MainWindow(QMainWindow): def __init__(self, parent=None): - super(MainWindow, self).__init__(parent) + super().__init__(parent) self.btn1 = QPushButton("Click me", self) diff --git a/src/dui/gui_utils.py b/src/dui/gui_utils.py index 6f11ea25..a9763bb1 100644 --- a/src/dui/gui_utils.py +++ b/src/dui/gui_utils.py @@ -20,7 +20,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import json import logging @@ -34,7 +33,6 @@ import psutil from dxtbx.sequence_filenames import template_regex, template_regex_from_list -from six.moves import range from .cli_utils import get_next_step, sys_arg from .m_idials import generate_report @@ -188,7 +186,7 @@ def try_move_last_info(export_node, gui2_log): # logger.info(f"\n ___________________ gui2_log: {gui2_log}") - except IOError: + except OSError: logger.info("ERROR: mtz file not there") logger.debug("IOError on try_move_last_info(gui_utils)") @@ -514,7 +512,7 @@ def __init__(self, action, parent=None): class TreeNavWidget(QTreeView): def __init__(self, parent=None): - super(TreeNavWidget, self).__init__() + super().__init__() logger.debug("TreeNavWidget(__init__)") self.setSortingEnabled(False) self.setAnimated(True) @@ -598,7 +596,7 @@ class ViewerThread(QThread): """ def __init__(self, process): - super(ViewerThread, self).__init__() + super().__init__() self.process = process def run(self): @@ -624,15 +622,13 @@ class ExternalProcDialog(QDialog): outputFileFound = Signal(list) def __init__(self, parent=None): - super(ExternalProcDialog, self).__init__(parent) + super().__init__(parent) vbox = QVBoxLayout() label = QLabel( - ( - "Running a pop-up viewer ...\n\n" - "remember to close the viewer before\n" - "performing any other task" - ) + "Running a pop-up viewer ...\n\n" + "remember to close the viewer before\n" + "performing any other task" ) label.setAlignment(Qt.AlignCenter) vbox.addWidget(label) @@ -683,7 +679,7 @@ def run_my_proc(self, command, json_path, pickle_path): logger.debug("\n running Popen>>>\n " + " ".join(cmd_to_run) + "\n<<<") self.my_process = subprocess.Popen(args=cmd_to_run, cwd=self.cwd_path) - logger.debug("Running PID {}".format(self.my_process.pid)) + logger.debug(f"Running PID {self.my_process.pid}") # Track the process status in a separate thread self.thrd = ViewerThread(self.my_process) @@ -715,7 +711,7 @@ def closeEvent(self, event): class OuterCaller(QWidget): def __init__(self): - super(OuterCaller, self).__init__() + super().__init__() v_box = QVBoxLayout() @@ -750,7 +746,7 @@ def run_img_dialg(self): class CliOutView(QTextEdit): def __init__(self, app=None): - super(CliOutView, self).__init__() + super().__init__() self.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) self.make_green() @@ -794,7 +790,7 @@ def refresh_txt(self, path_to_log, curr_step=None): logger.debug(" path_to_log = %s", path_to_log) if path_to_log and Path(path_to_log).is_file(): - fil_obj = open(path_to_log, "r") + fil_obj = open(path_to_log) lst_lin = fil_obj.readlines() else: logger.debug("No log file") @@ -810,7 +806,7 @@ def refresh_txt(self, path_to_log, curr_step=None): class Text_w_Bar(QProgressBar): def __init__(self, parent=None): - super(Text_w_Bar, self).__init__() + super().__init__() self.setAlignment(Qt.AlignCenter) self._text = "" logger.debug("test setStyle(QStyleFactory.create())") diff --git a/src/dui/m_idials.py b/src/dui/m_idials.py index 7e594cbc..fce22851 100644 --- a/src/dui/m_idials.py +++ b/src/dui/m_idials.py @@ -7,7 +7,6 @@ copyright (c) CCP4 - DLS """ -from __future__ import absolute_import, division, print_function import logging import os @@ -15,7 +14,6 @@ import shutil import sys -from six.moves import input from dui.cli_utils import ( DialsCommand, @@ -45,7 +43,7 @@ logger = logging.getLogger(__name__) -class CommandNode(object): +class CommandNode: dials_com_lst = [ "import", "find_spots", @@ -165,7 +163,7 @@ def get_next_step(self): return get_next_step(self) -class Runner(object): +class Runner: def __init__(self): root_node = CommandNode(prev_step=None) root_node.success = True diff --git a/src/dui/m_idials_gui.py b/src/dui/m_idials_gui.py index 652b8313..f11fde9a 100644 --- a/src/dui/m_idials_gui.py +++ b/src/dui/m_idials_gui.py @@ -20,7 +20,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import logging import os @@ -28,8 +27,6 @@ import time import traceback -from six import raise_from - from ._version import __version__ from .cli_utils import TreeShow, build_mask_command_lst, prn_lst_lst_cmd, sys_arg from .custom_widgets import BeamCentrPage, MaskPage, ParamWidget @@ -79,7 +76,7 @@ class CheckStatusThread(QThread): end_busy_box = Signal() def __init__(self, parent=None): - super(CheckStatusThread, self).__init__() + super().__init__() def __call__(self, ref_to_controler): self.ref_to_controler = ref_to_controler @@ -111,7 +108,7 @@ class CommandThread(QThread): busy_box_off = Signal() def __init__(self, parent=None): - super(CommandThread, self).__init__() + super().__init__() def __call__(self, cmd_to_run, ref_to_controler): self.cmd_to_run = cmd_to_run @@ -169,7 +166,7 @@ class ControlWidget(QWidget): click_b_centr = Signal() def __init__(self, parent=None): - super(ControlWidget, self).__init__() + super().__init__() top_box = QVBoxLayout() # top_box.setMargin(0) @@ -345,7 +342,7 @@ def gray_outs_from_lst(self, lst_nxt): class StopRunRetry(QWidget): def __init__(self, parent=None): - super(StopRunRetry, self).__init__() + super().__init__() main_path = get_main_path() @@ -404,7 +401,7 @@ def load_previous_state(dui_files_path): class MainWidget(QMainWindow): def __init__(self): - super(MainWidget, self).__init__() + super().__init__() self.my_pop = None # Any child popup windows. Only bravais_table ATM self.storage_path = sys_arg.directory @@ -422,7 +419,7 @@ def __init__(self): # Something went wrong - tell the user then close msg = traceback.format_exc() logger.error("ERROR LOADING PREVIOUS DATA:\n%s", msg) - raise_from(DUIDataLoadingError(msg), e) + raise DUIDataLoadingError(msg) from e refresh_gui = True else: @@ -533,7 +530,7 @@ def __init__(self): self.main_widget.setLayout(main_box) self.setCentralWidget(self.main_widget) - self.setWindowTitle("CCP4 DUI - {}: {}".format(__version__, dui_files_path)) + self.setWindowTitle(f"CCP4 DUI - {__version__}: {dui_files_path}") self.setWindowIcon(QIcon(self.stop_run_retry.dials_logo_path)) self.just_reindexed = False diff --git a/src/dui/main_dui.py b/src/dui/main_dui.py index 25b84045..de211b2f 100644 --- a/src/dui/main_dui.py +++ b/src/dui/main_dui.py @@ -21,7 +21,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import argparse import faulthandler @@ -82,7 +81,7 @@ def main(): logger.warning( "Unknown parameter%s %s", "s" if len(args.positionals) > 1 else "", - " ".join("'{}'".format(x) for x in args.positionals), + " ".join(f"'{x}'" for x in args.positionals), ) # Should we exit here? Maybe QT can handle it(???) diff --git a/src/dui/outputs_gui.py b/src/dui/outputs_gui.py index 05837add..0cfdd44f 100644 --- a/src/dui/outputs_gui.py +++ b/src/dui/outputs_gui.py @@ -20,7 +20,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import logging import sys @@ -69,7 +68,7 @@ def get_spacebox(size): class InfoWidget(QWidget): def __init__(self, parent=None): - super(InfoWidget, self).__init__() + super().__init__() empty_str = "__________" diff --git a/src/dui/outputs_n_viewers/__init__.py b/src/dui/outputs_n_viewers/__init__.py index 42986309..47edd7bc 100644 --- a/src/dui/outputs_n_viewers/__init__.py +++ b/src/dui/outputs_n_viewers/__init__.py @@ -21,5 +21,3 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from __future__ import absolute_import, division, print_function diff --git a/src/dui/outputs_n_viewers/compyling_boost_ext.py b/src/dui/outputs_n_viewers/compyling_boost_ext.py index e0220cc0..f5a53603 100644 --- a/src/dui/outputs_n_viewers/compyling_boost_ext.py +++ b/src/dui/outputs_n_viewers/compyling_boost_ext.py @@ -2,7 +2,6 @@ (Nick) - Appears to be file to compile optional C++ extension? Potentially unused in normal runnning? """ -from __future__ import absolute_import, division, print_function import logging from distutils import sysconfig diff --git a/src/dui/outputs_n_viewers/img_view_tools.py b/src/dui/outputs_n_viewers/img_view_tools.py index c683b6e4..cef78f94 100644 --- a/src/dui/outputs_n_viewers/img_view_tools.py +++ b/src/dui/outputs_n_viewers/img_view_tools.py @@ -19,14 +19,12 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import logging import numpy as np from dials.array_family import flex from dials_viewer_ext import rgb_img -from six.moves import range from dui.qt import QImage, QProgressDialog, Qt @@ -35,7 +33,7 @@ class ProgBarBox(QProgressDialog): def __init__(self, max_val=100, min_val=0, text="Working"): - super(ProgBarBox, self).__init__(parent=None) + super().__init__(parent=None) self.setMinimumDuration(50) if max_val > min_val: @@ -263,7 +261,7 @@ def list_arrange(bbox_lst, hkl_lst, pan_lst, n_imgs): return list_arr(bbox_lst, hkl_lst, pan_lst, n_imgs) -class img_w_cpp(object): +class img_w_cpp: def __init__(self): self.wx_bmp_arr = rgb_img() @@ -307,7 +305,7 @@ def __call__( return img_array -class build_qimg(object): +class build_qimg: def __init__(self): self.arr_img = img_w_cpp() diff --git a/src/dui/outputs_n_viewers/img_viewer.py b/src/dui/outputs_n_viewers/img_viewer.py index 45710035..ee213f37 100644 --- a/src/dui/outputs_n_viewers/img_viewer.py +++ b/src/dui/outputs_n_viewers/img_viewer.py @@ -21,7 +21,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function import logging import os @@ -34,7 +33,6 @@ ) from dials.array_family import flex from dxtbx.model.experiment_list import ExperimentListFactory -from six.moves import range from dui.cli_utils import sys_arg from dui.gui_utils import get_main_path @@ -193,7 +191,7 @@ class ImgPainter(QWidget): ll_b_centr_applied = Signal(list) def __init__(self, parent=None): - super(ImgPainter, self).__init__() + super().__init__() self.my_parent = parent self.img = None @@ -741,7 +739,7 @@ def paintEvent(self, event): class PopActionsMenu(QMenu): def __init__(self, parent=None): - super(PopActionsMenu, self).__init__(parent) + super().__init__(parent) self.my_parent = parent ref_bond_group = QButtonGroup() @@ -836,7 +834,7 @@ class PopDisplayMenu(QMenu): sliders_changed = Signal(int, int) def __init__(self, parent=None): - super(PopDisplayMenu, self).__init__(parent) + super().__init__(parent) self.my_parent = parent # group to tune up palette @@ -994,9 +992,7 @@ def test_dispersion_debug(self): elif self.algorithm == "dispersion extended": Debug = DispersionExtendedThresholdDebug else: - raise ValueError( - "Unknown spot-finding algorithm: {}".format(self.algorithm) - ) + raise ValueError(f"Unknown spot-finding algorithm: {self.algorithm}") debug = Debug( self.image, @@ -1026,7 +1022,7 @@ class MyImgWin(QWidget): new_pars_applied = Signal(list) def __init__(self, json_file_path=None, pckl_file_path=None): - super(MyImgWin, self).__init__() + super().__init__() self.my_scrollable = QScrollArea() self.my_painter = ImgPainter(self) @@ -1751,7 +1747,7 @@ def update_info_label(self, x_pos, y_pos): image_file = os.path.basename( self.ref2exp.imageset.get_image_identifier(self.img_num - 1) ) - new_label_txt += "{0}: ".format(image_file) + new_label_txt += f"{image_file}: " if self.img_arr: new_label_txt += ( @@ -1770,7 +1766,7 @@ def update_info_label(self, x_pos, y_pos): mybeam = self.ref2exp.beam p = self.ref2exp.detector[0] res_float = p.get_resolution_at_pixel(mybeam.get_s0(), (x_pos, y_pos)) - res_str = str("{: 4.2f}".format(res_float)) + res_str = str(f"{res_float: 4.2f}") new_label_txt += ", resolution = " + res_str + " " + "\u00C5" else: diff --git a/src/dui/outputs_n_viewers/info_handler.py b/src/dui/outputs_n_viewers/info_handler.py index 35eb9246..898e6221 100644 --- a/src/dui/outputs_n_viewers/info_handler.py +++ b/src/dui/outputs_n_viewers/info_handler.py @@ -6,7 +6,6 @@ copyright (c) CCP4 - DLS """ -from __future__ import absolute_import, division, print_function import json import logging @@ -36,7 +35,7 @@ logger = logging.getLogger(__name__) -class InfoData(object): +class InfoData: def __init__(self): self.a = None @@ -157,7 +156,7 @@ def update_all_data(reflections_path=None, experiments_path=None): mask_np_arr = dat.mask_flex.as_numpy_array() dat.np_mask = mask_np_arr - except IOError: + except OSError: logger.info("No mask in this node") dat.np_mask = None dat.mask_flex = None diff --git a/src/dui/outputs_n_viewers/web_page_view.py b/src/dui/outputs_n_viewers/web_page_view.py index 2349508b..a280c34a 100644 --- a/src/dui/outputs_n_viewers/web_page_view.py +++ b/src/dui/outputs_n_viewers/web_page_view.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division, print_function - import logging import os import sys @@ -20,7 +18,7 @@ class WebTab(QWidget): def __init__(self): - super(WebTab, self).__init__() + super().__init__() self.dummy_html = """ @@ -74,7 +72,7 @@ def load_finished(self, ok_bool): class TmpTstWidget(QWidget): def __init__(self, parent=None): - super(TmpTstWidget, self).__init__() + super().__init__() # self.param_widget_parent = self self.my_widget = WebTab() self.btn1 = QPushButton("Click me", self) diff --git a/src/dui/params_live_gui_generator.py b/src/dui/params_live_gui_generator.py index 76556d9a..ea5db6e3 100644 --- a/src/dui/params_live_gui_generator.py +++ b/src/dui/params_live_gui_generator.py @@ -6,7 +6,6 @@ copyright (c) CCP4 - DLS """ -from __future__ import absolute_import, division, print_function import logging import sys @@ -53,7 +52,7 @@ logger = logging.getLogger(__name__) -class ScopeData(object): +class ScopeData: """ class conceived to store only data related to the scope Phil object """ @@ -61,7 +60,7 @@ class conceived to store only data related to the scope Phil object pass -class tree_2_lineal(object): +class tree_2_lineal: """ Recursively navigates the Phil objects in a way that the final self.lst_obj is a lineal list without ramifications, this final list @@ -114,7 +113,7 @@ def deep_in_rec(self, phl_obj): class MyQComboBox(QComboBox): def __init__(self, parent=None): - super(MyQComboBox, self).__init__(parent) + super().__init__(parent) self.setFocusPolicy(Qt.ClickFocus) def wheelEvent(self, event): @@ -134,7 +133,7 @@ class PhilWidget(QWidget): def __init__(self, phl_obj, parent=None): # TODO fix the order of this two parameters - super(PhilWidget, self).__init__(parent) + super().__init__(parent) self.original_parent = parent self.bg_box = QVBoxLayout(self) @@ -383,7 +382,7 @@ def combobox_changed(self, value): class TstTmpWidget(QWidget): def __init__(self, phl_obj=None, parent=None): - super(TstTmpWidget, self).__init__(parent) + super().__init__(parent) # self.param_widget_parent = self inner_widget = PhilWidget( phl_obj, self diff --git a/src/dui/qt.py b/src/dui/qt.py index 785b0e46..bd579b1f 100644 --- a/src/dui/qt.py +++ b/src/dui/qt.py @@ -5,7 +5,6 @@ # Because we *-import as a shim in this file, ignore for flake8 purposes # flake8: noqa -from __future__ import absolute_import, division, print_function import logging import os diff --git a/src/dui/simpler_param_widgets.py b/src/dui/simpler_param_widgets.py index df23e055..0e2e00c9 100644 --- a/src/dui/simpler_param_widgets.py +++ b/src/dui/simpler_param_widgets.py @@ -21,13 +21,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from __future__ import absolute_import, division, print_function - import logging import sys import libtbx.introspection -from six.moves import range from dui.qt import ( QApplication, @@ -84,7 +81,7 @@ class DefaultComboBox(QComboBox): is default""" def __init__(self, local_path, items, default_index=0): - super(DefaultComboBox, self).__init__() + super().__init__() self.local_path = local_path self.tmp_lst = items self.default_index = default_index @@ -130,7 +127,7 @@ class FindspotsSimplerParameterTab(SimpleParamTab): """ def __init__(self, parent=None): - super(FindspotsSimplerParameterTab, self).__init__() + super().__init__() # self.param_widget_parent = parent.param_widget_parent # TODO thinks about making "None equivalent to 1" xds_gain_label = QLabel("Gain") @@ -221,7 +218,7 @@ class IndexSimplerParamTab(SimpleParamTab): """ def __init__(self, phl_obj=None, parent=None): - super(IndexSimplerParamTab, self).__init__() + super().__init__() # self.param_widget_parent = parent.param_widget_parent # indexing_method_check = QCheckBox("indexing.method") @@ -293,7 +290,7 @@ def line_changed(self): class RefineBravaiSimplerParamTab(SimpleParamTab): def __init__(self, parent=None): - super(RefineBravaiSimplerParamTab, self).__init__() + super().__init__() localLayout = QVBoxLayout() hbox_lay_outlier_algorithm = QHBoxLayout() @@ -328,7 +325,7 @@ class RefineSimplerParamTab(SimpleParamTab): """ def __init__(self, parent=None): - super(RefineSimplerParamTab, self).__init__() + super().__init__() # self.param_widget_parent = parent.param_widget_parent localLayout = QVBoxLayout() @@ -397,7 +394,7 @@ class IntegrateSimplerParamTab(SimpleParamTab): """ def __init__(self, parent=None): - super(IntegrateSimplerParamTab, self).__init__() + super().__init__() # self.param_widget_parent = parent.param_widget_parent localLayout = QVBoxLayout() @@ -473,7 +470,7 @@ class SymmetrySimplerParamTab(SimpleParamTab): """ def __init__(self, parent=None): - super(SymmetrySimplerParamTab, self).__init__() + super().__init__() hbox_d_min = QHBoxLayout() localLayout = QVBoxLayout() @@ -511,7 +508,7 @@ class ScaleSimplerParamTab(SimpleParamTab): """ def __init__(self, parent=None): - super(ScaleSimplerParamTab, self).__init__() + super().__init__() localLayout = QVBoxLayout() @@ -570,7 +567,7 @@ def __init__(self, parent=None): class TmpTstWidget(QWidget): def __init__(self, parent=None): - super(TmpTstWidget, self).__init__() + super().__init__() # self.param_widget_parent = self my_widget = RefineSimplerParamTab(self) diff --git a/tests/test_basic_functions.py b/tests/test_basic_functions.py index 498185b8..64789db3 100644 --- a/tests/test_basic_functions.py +++ b/tests/test_basic_functions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """Test running DUI, but in a screenshot-friendly way""" import pytest diff --git a/tests/test_basic_styles.py b/tests/test_basic_styles.py index abeb8a5c..c5b20cf3 100644 --- a/tests/test_basic_styles.py +++ b/tests/test_basic_styles.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """Test running DUI, but in a screenshot-friendly way""" import pytest diff --git a/tests/test_gui_utils.py b/tests/test_gui_utils.py index 4195cea1..a09831bb 100644 --- a/tests/test_gui_utils.py +++ b/tests/test_gui_utils.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import ntpath import os import posixpath