Skip to content

Commit

Permalink
Replaced six with Python 3 code
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkeSchomann committed Dec 5, 2024
1 parent aa6bc49 commit 9d4977e
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 111 deletions.
1 change: 0 additions & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ requirements:
- qtconsole
- qtpy
- setuptools
- six

test:
imports:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies = [
"ipython",
"numpy",
"matplotlib>=3.9.2",
"six",
"qtawesome",
"pre-commit",
"qtpy",
Expand Down
3 changes: 1 addition & 2 deletions src/mslice/cli/_mslice_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
_check_workspace_type, _correct_intensity)
from mslice.workspace.pixel_workspace import PixelWorkspace
from mslice.util.qt.qapp import QAppThreadCall, mainloop
from six import string_types
from mslice.workspace.histogram_workspace import HistogramWorkspace
from mslice.workspace.workspace import Workspace as MSliceWorkspace
from mslice.util.mantid.mantid_algorithms import * # noqa: F401, F403
Expand Down Expand Up @@ -73,7 +72,7 @@ def Load(Filename, OutputWorkspace=None):
"""
from mslice.app.presenters import get_dataloader_presenter

if not isinstance(Filename, string_types):
if not isinstance(Filename, str):
raise RuntimeError('path given to load must be a string')
merge = False
if not ospath.exists(Filename):
Expand Down
5 changes: 2 additions & 3 deletions src/mslice/models/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from matplotlib import rcParams

from six import iteritems
try:
from matplotlib.colors import to_hex
except ImportError:
Expand Down Expand Up @@ -103,11 +102,11 @@ def color_to_name(color):
:raises: ValueError if the color is not known and is not a HEX code
"""
color_as_hex = to_hex(color)
for name, hexvalue in iteritems(_BASIC_COLORS_HEX_MAPPING):
for name, hexvalue in _BASIC_COLORS_HEX_MAPPING.items():
if color_as_hex == hexvalue:
return name

for name, value in iteritems(mpl_named_colors()):
for name, value in mpl_named_colors().items():
if color_as_hex == to_hex(value):
return pretty_name(name)

Expand Down
3 changes: 1 addition & 2 deletions src/mslice/models/intensity_correction_algs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
from six import string_types
import numpy as np

from scipy import constants
Expand Down Expand Up @@ -265,7 +264,7 @@ def sample_temperature(ws_name, sample_temp_fields):
pass
except AttributeError:
sample_temp = ws.getExperimentInfo(0).run().getLogData(field_name).value
if isinstance(sample_temp, string_types):
if isinstance(sample_temp, str):
sample_temp = get_sample_temperature_from_string(sample_temp)
elif isinstance(sample_temp, np.ndarray) or isinstance(sample_temp, list):
sample_temp = np.mean(sample_temp)
Expand Down
5 changes: 2 additions & 3 deletions src/mslice/models/workspacemanager/workspace_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import numpy as np
from scipy import constants
from six import string_types

import mslice.util.mantid.init_mantid # noqa: F401

Expand Down Expand Up @@ -253,7 +252,7 @@ def save_workspaces(workspaces, path, save_name, extension):
save_method = save_matlab
else:
raise RuntimeError("unrecognised file extension")
if isinstance(save_name, string_types):
if isinstance(save_name, str):
if len(workspaces) == 1:
save_names = [save_name]
else:
Expand Down Expand Up @@ -285,7 +284,7 @@ def remove_workspace_from_ads(workspacename):
def _save_single_ws(workspace, save_name, save_method, path, extension):
save_as = save_name if save_name is not None else str(workspace) + extension
full_path = os.path.join(str(path), save_as)
if isinstance(workspace, string_types):
if isinstance(workspace, str):
workspace = get_workspace_handle(workspace)
save_method(workspace, full_path)

Expand Down
6 changes: 2 additions & 4 deletions src/mslice/models/workspacemanager/workspace_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from six import iterkeys, string_types

from mslice.workspace.base import WorkspaceBase as Workspace

_loaded_workspaces = {}
Expand Down Expand Up @@ -33,12 +31,12 @@ def rename_workspace(workspace, new_name):


def get_visible_workspace_names():
return [key for key in iterkeys(_loaded_workspaces) if key[:2] != '__']
return [key for key in _loaded_workspaces.keys() if key[:2] != '__']


def get_workspace_name(workspace):
"""Returns the name of a workspace given the workspace handle"""
if isinstance(workspace, string_types):
if isinstance(workspace, str):
return workspace
return workspace.name

Expand Down
19 changes: 9 additions & 10 deletions src/mslice/plotting/plot_window/iplot.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class IPlot(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def window_closing(self):
pass

@abc.abstractmethod
@abstractmethod
def plot_options(self):
pass

@abc.abstractmethod
@abstractmethod
def plot_clicked(self, x, y):
pass

@abc.abstractmethod
@abstractmethod
def object_clicked(self, target):
pass

@abc.abstractmethod
@abstractmethod
def update_legend(self):
pass

@abc.abstractmethod
@abstractmethod
def get_line_options(self, line):
pass

@abc.abstractmethod
@abstractmethod
def set_line_options(self, line, line_options):
pass
4 changes: 2 additions & 2 deletions src/mslice/plotting/plot_window/plot_figure_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os.path
import weakref
import io
import six

from qtpy.QtCore import Qt
from qtpy import QtCore, QtGui, QtWidgets, QtPrintSupport
from mslice.util.qt.qapp import (QAppThreadCall, create_qapp_if_required,
Expand Down Expand Up @@ -296,7 +296,7 @@ def move_window(self, x, y):
self.window.move(int(center.x() - x), int(center.y() - y))

def get_window_title(self):
return six.text_type(self.window.windowTitle())
return str(self.window.windowTitle())

def set_window_title(self, title):
self.window.setWindowTitle(title)
Expand Down
5 changes: 2 additions & 3 deletions src/mslice/plotting/plot_window/plot_options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import (absolute_import, division, print_function)

from numpy import arange as np_arange
from six import iteritems

import qtpy.QtWidgets as QtWidgets
from qtpy.QtCore import Signal
Expand Down Expand Up @@ -322,8 +321,8 @@ class LegendAndLineOptionsSetter(QtWidgets.QWidget):
'*': 'Star', 'h': 'Hexagon 1', 'H': 'Hexagon 2', '+': 'Plus', 'x': 'X', 'D': 'Diamond',
'd': 'Diamond (thin)', '|': 'Vertical line', '_': 'Horizontal line', 'None': 'None'}

inverse_styles = {v: k for k, v in iteritems(styles)}
inverse_markers = {v: k for k, v in iteritems(markers)}
inverse_styles = {v: k for k, v in styles.items()}
inverse_markers = {v: k for k, v in markers.items()}

def __init__(self, line_options, color_validator, show_legends, remove_line_callback=None):
super(LegendAndLineOptionsSetter, self).__init__()
Expand Down
13 changes: 6 additions & 7 deletions src/mslice/presenters/interfaces/data_loader_presenter.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class DataLoaderPresenterInterface(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def register_master(self, main_view):
pass

@abc.abstractmethod
@abstractmethod
def load_workspace(self, file_paths, merge):
pass

@abc.abstractmethod
@abstractmethod
def _report_load_errors(self, ws_names, not_opened, not_loaded):
pass

@abc.abstractmethod
@abstractmethod
def workspace_selection_changed(self):
pass
33 changes: 16 additions & 17 deletions src/mslice/presenters/interfaces/main_presenter.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class MainPresenterInterface(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def get_selected_workspaces(self):
pass

@abc.abstractmethod
@abstractmethod
def set_selected_workspaces(self, workspace_list):
pass

@abc.abstractmethod
@abstractmethod
def update_displayed_workspaces(self):
pass

@abc.abstractmethod
@abstractmethod
def notify_workspace_selection_changed(self):
pass

@abc.abstractmethod
@abstractmethod
def subscribe_to_workspace_selection_monitor(self, client):
pass

@abc.abstractmethod
@abstractmethod
def register_workspace_selector(self, workspace_selector):
pass

@abc.abstractmethod
@abstractmethod
def change_ws_tab(self, tab):
pass

@abc.abstractmethod
@abstractmethod
def highlight_ws_tab(self, tab):
pass

@abc.abstractmethod
@abstractmethod
def show_workspace_manager_tab(self):
pass

@abc.abstractmethod
@abstractmethod
def show_tab_for_workspace(self, ws):
pass

@abc.abstractmethod
@abstractmethod
def subscribe_to_energy_default_monitor(self, client):
pass

@abc.abstractmethod
@abstractmethod
def subscribe_to_cut_algo_default_monitor(self, client):
pass

@abc.abstractmethod
@abstractmethod
def is_energy_conversion_allowed(self):
pass

@abc.abstractmethod
@abstractmethod
def get_cut_algorithm(self):
pass
13 changes: 6 additions & 7 deletions src/mslice/presenters/interfaces/plot_selector.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class PlotSelectorPresenterInterface(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def register_master(self, main_view):
pass

# @abc.abstractmethod
# @abstractmethod
# def load_workspace(self, file_paths, merge):
# pass
#
# @abc.abstractmethod
# @abstractmethod
# def _report_load_errors(self, ws_names, not_opened, not_loaded):
# pass

# @abc.abstractmethod
# @abstractmethod
# def workspace_selection_changed(self):
# pass
11 changes: 5 additions & 6 deletions src/mslice/presenters/interfaces/powder_projection_presenter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class PowderProjectionPresenterInterface(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def register_master(self, main_view):
pass

@abc.abstractmethod
@abstractmethod
def notify(self, command):
pass

@abc.abstractmethod
@abstractmethod
def workspace_selection_changed(self):
pass
11 changes: 5 additions & 6 deletions src/mslice/presenters/interfaces/slice_plotter_presenter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import abc
from six import add_metaclass
from abc import ABCMeta, abstractmethod


@add_metaclass(abc.ABCMeta)
class SlicePlotterPresenterInterface(object):
__metaclass__ = ABCMeta

@abc.abstractmethod
@abstractmethod
def register_master(self, main_view):
pass

@abc.abstractmethod
@abstractmethod
def notify(self, command):
pass

@abc.abstractmethod
@abstractmethod
def workspace_selection_changed(self):
pass
Loading

0 comments on commit 9d4977e

Please sign in to comment.