Skip to content

Commit fa00ad2

Browse files
committed
Elminate some codacy regressions, try to get tests working on GH Action
1 parent 922e79d commit fa00ad2

12 files changed

Lines changed: 30 additions & 28 deletions

File tree

Stoner/Image/kerr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def image(self: Self) -> ImageArray: # pylint: disable=invalid-overridden-metho
115115
return self._image.view(KerrArray)
116116

117117
@ImageFile.image.setter
118-
def image(self: Self, v) -> None: # noqa F811 pylint: disable=function-redefined
118+
def image(self: Self, v) -> None: # noqa: F811 # pylint: disable=redefined-outer-name
119119
"""Ensure stored image is always an ImageArray."""
120120
filename = self.filename
121121
v = KerrArray(v)

Stoner/core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"string_to_type",
1919
"exceptions",
2020
"utils",
21-
"Typing",
2221
]
2322

2423
from . import array, base, exceptions, utils

Stoner/core/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def _load(self, filename, *args, **kargs):
686686
invalid_raise=False,
687687
comments="\0",
688688
missing_values=[""],
689-
filling_values=[np.nan],
689+
filling_values=[nan],
690690
max_rows=max_rows,
691691
)
692692
if data.ndim < 2:

Stoner/folders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Core support for working with collections of files in the :py:class:`Stoner.DataFolder`."""
22

3+
# pylint: disable=redefined-builtin
34
__all__ = ["core", "each", "groups", "hdf5", "metadata", "mixins", "utils", "zip", "DataFolder", "PlotFolder"]
45

56
from . import core, each, groups, hdf5, metadata, mixins, utils, zip

Stoner/folders/hdf5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import h5py
1616

1717
from ..compat import get_filedialog, path_types
18-
from ..core.data import Data # noqa pylint: disable=unused-import
1918
from .mixins import DataFolder
19+
from ..tools import make_Class
2020

2121

2222
class HDF5Folder(DataFolder):
@@ -109,7 +109,7 @@ def _dialog(self, message="Select Folder", new_directory=True, mode="r+"):
109109
def _visit_func(self, name, obj): # pylint: disable=unused-argument
110110
"""Walker of the HDF5 tree."""
111111
if isinstance(obj, h5py.Group) and "type" in obj.attrs:
112-
cls = globals()[obj.attrs["type"]]
112+
cls = make_Class(obj.attrs["type"], None)
113113
if issubclass(self.loader, cls):
114114
self.__setter__(obj.name, obj.name)
115115
elif obj.attrs["type"] == "HDF5Folder" and getattr(self, "recursive", True):

Stoner/folders/zip.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ZipFolder(DiskBasedFolderMixin, BaseFolder):
3939
def __init__(self, *args, **kargs):
4040
"""Initialise the file attribute."""
4141
self.File = None
42+
self.exclude = []
43+
self.flat = False
4244
super().__init__(*args, **kargs)
4345

4446
@property
@@ -58,7 +60,7 @@ def key(self, value): # pylint: disable=invalid-overridden-method
5860
"""Set the immediate filename that will be used when the file is saved."""
5961
self.path = pathjoin(self.directory, value)
6062

61-
def _dialog(self, mode="r"):
63+
def _zip_file_dialog(self, mode="r"):
6264
"""Create a file dialog box for working with.
6365
6466
Args:
@@ -94,7 +96,7 @@ def getlist(self, recursive=None, directory=None, flatten=None, **_):
9496
flatten = self.flat
9597

9698
if self.File is None and directory is None:
97-
self.File = zf.ZipFile(self._dialog(), "r")
99+
self.File = zf.ZipFile(self._zip_file_dialog(), "r")
98100
close_me = True
99101
elif isinstance(directory, zf.ZipFile):
100102
if directory.fp:
@@ -252,7 +254,7 @@ def save(self, root=None):
252254
A list of group paths in the Zip file
253255
"""
254256
if root is None:
255-
root = self._dialog(mode="w")
257+
root = self._zip_file_dialog(mode="w")
256258
elif isinstance(root, bool) and not root and isinstance(self.File, zf.ZipFile):
257259
root = self.File.filename
258260
self.File.close()
@@ -261,14 +263,16 @@ def save(self, root=None):
261263
tmp = self.walk_groups(self._save)
262264
return tmp
263265

264-
def _save(self, f, trail):
266+
def _save(self, f, trail, root=None):
265267
"""Create a virtual path of groups in the Zip file and save data.
266268
267269
Args:
268270
f(DataFile):
269271
A DataFile instance to save
270272
trail (list):
271273
The trail of groups
274+
root (string or None):
275+
a replacement root directory
272276
273277
Returns:
274278
The new filename of the saved DataFile.

Stoner/formats/maximus.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ def __init__(self, *args, **kargs):
7575
def _load(self, *args, **kargs):
7676
"""Load an ImageStack from either an hdf file or textfiles."""
7777
filename, args, kargs = get_filename(args, kargs)
78-
if filename is None or not filename:
79-
self.get_filename("r")
80-
else:
81-
self.filename = filename
78+
self.filename = filename
8279
pth = Path(self.filename)
8380
if h5py.is_hdf5(self.filename):
8481
return self.__class__.read_hdf5(self.filename)
@@ -219,14 +216,11 @@ def to_hdf5(self, filename=None):
219216
return self
220217

221218
@classmethod
222-
def read_hdf5(cls, filename, *args, **kargs):
219+
def read_hdf5(cls, *args, **kargs):
223220
"""Create a new instance from an hdf file."""
224221
self = cls(regrid=False)
225-
if filename is None or not filename:
226-
self.get_filename("r")
227-
filename = self.filename
228-
else:
229-
self.filename = filename
222+
filename, args, kargs = get_filename(args, kargs)
223+
self.filename = filename
230224
with HDFFileManager(self.filename, "r") as f:
231225
self.scan_no = f.attrs["scan_no"]
232226
if "groups" in f.attrs:

Stoner/plot/formats.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ def update(self, other=(), /, **_):
406406
if k in dir(self) and not callable(getattr(self, k)):
407407
setattr(self, k, val)
408408
elif not k.startswith("_"):
409-
setattr(self, f"template_{k}", val)
409+
try:
410+
setattr(self, f"template_{k}", val)
411+
except AttributeError:
412+
pass
410413
case _:
411414
raise SyntaxError(
412415
"Only one posotional argument which should be a Mapping subclass can be supplied toi update."

Stoner/tools/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
if TYPE_CHECKING:
1010
from ..core.data import Data
11-
from ..core.setas import setas
11+
from ..core.setas import Setas
1212
from ..image.core import ImageArray, ImageFile
1313
else:
1414
Setas = type("Setas", (), {})

scripts/BNL_FileSplitter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525
break
2626
except IOError:
2727
print("Oops I couldn't find that file.")
28-
with open(filename, "r", encoding="utf-8") as mainFP, open(
28+
with open(filename, "r", encoding="utf-8") as main_fp, open(
2929
"title.txt", "w", encoding="utf-8"
30-
) as writeFP:
30+
) as write_fp:
3131

3232
if "BNLSplitFiles" not in os.listdir(directory):
3333
os.mkdir("BNLSplitFiles")
3434
os.chdir("BNLSplitFiles")
3535

3636
# writeName=re.split(r'[.]',filename)
3737
counter = 1 # this will label the files
38-
for line in mainFP:
38+
for line in main_fp:
3939
if line[0:2] == "#S":
4040
if int(line.split()[1]) != counter:
4141
raise ValueError # check for inconsistencies with filenames and scan numbers
42-
writeFP.close()
43-
writeFP = open(str(counter) + ".bnl", "w", encoding="utf-8")
42+
write_fp.close()
43+
write_fp = open(str(counter) + ".bnl", "w", encoding="utf-8")
4444
counter += 1
4545
if line[0:2] != "#C":
46-
writeFP.write(line)
46+
write_fp.write(line)
4747
# ignore #C statements which are usually abort and rarely useful, they come
4848
# after data and before the next #S"""
4949

0 commit comments

Comments
 (0)