Skip to content

Commit 7b4ccda

Browse files
authored
Merge pull request #25 from xsuite/release/v0.3.2
Release 0.3.2
2 parents 67e98af + 615d3c5 commit 7b4ccda

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "xaux"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "Support tools for Xsuite packages"
55
authors = ["Frederik F. Van der Veken <[email protected]>",
66
"Thomas Pugnat <[email protected]>",

tests/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ do
66
fi
77
done
88

9-
for f in example_file.txt test_*.json test_*.json.lock test_cronjob.txt
9+
for f in example_file.txt test_*.json test_*.json.lock test_cronjob.txt default_file_?.txt
1010
do
1111
if [ -e $f ]
1212
then

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
from xaux import __version__
77

88
def test_version():
9-
assert __version__ == '0.3.1'
9+
assert __version__ == '0.3.2'
1010

xaux/fs/eos.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ def mkdir(self, *args, **kwargs):
200200
def rmdir(self, *args, **kwargs):
201201
return _eos_rmdir(self.expanduser(), *args, **kwargs)
202202

203+
def as_posix(self, *args, **kwargs):
204+
if hasattr(self, 'eos_path'):
205+
return self.eos_path
206+
return Path.as_posix(self, *args, **kwargs)
207+
203208
# def glob(self, *args, **kwargs):
204209
# raise NotImplementedError
205210

@@ -220,9 +225,6 @@ def rmtree(self, *args, **kwargs):
220225
def size(self, *args, **kwargs):
221226
return _eos_size(self.expanduser(), FsPath, *args, **kwargs)
222227

223-
def as_posix(self, *args, **kwargs):
224-
return self.eos_path
225-
226228

227229
class EosPosixPath(EosPath, PurePosixPath):
228230
"""EosPath subclass for EOS paths on non-Windows systems.

xaux/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
# ===================
1111
# Do not change
1212
# ===================
13-
__version__ = '0.3.1'
13+
__version__ = '0.3.2'
1414
# ===================

xaux/tools/singleton.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ def __repr__(self):
2424
"""This a default __repr__ method for the singleton."""
2525
def __getattribute__(self, name):
2626
"""The __getattribute__ method is expanded to implement the singleton."""
27+
def delete(cls):
28+
"""The delete() method removes the singleton and invalidates any existing instances,
29+
allowing to create a new instance the next time the class is instantiated. This is
30+
useful for resetting the singleton to its default values.
31+
"""
2732
def get_self(cls, **kwargs):
2833
"""The get_self(**kwargs) method returns the singleton instance, allowing to pass
2934
any kwargs to the constructor, even if they are not attributes of the singleton.
3035
This is useful for kwargs filtering in getters or specific functions.
3136
"""
32-
def delete(cls):
33-
"""The delete() method removes the singleton and invalidates any existing instances,
34-
allowing to create a new instance the next time the class is instantiated. This is
35-
useful for resetting the singleton to its default values.
37+
def filter_kwargs(cls, **kwargs):
38+
"""The filter_kwargs(**kwargs) method splits the kwargs into non-class kwargs and
39+
class kwargs. This is useful after a call to `get_self(**kwargs)` to only keep the
40+
kwargs that are not attributes of the singleton.
3641
"""
3742

3843

@@ -191,21 +196,34 @@ def delete(this_cls):
191196
@classmethod
192197
@functools.wraps(Singleton.get_self)
193198
def get_self(this_cls, **kwargs):
199+
_, filtered_kwargs = this_cls.filter_kwargs(**kwargs)
200+
if '_singleton_instance' not in this_cls.__dict__:
201+
self = this_cls()
202+
else:
203+
self = this_cls._singleton_instance
204+
for kk, vv in filtered_kwargs.items():
205+
setattr(self, kk, vv)
206+
return self
207+
208+
@classmethod
209+
@functools.wraps(Singleton.filter_kwargs)
210+
def filter_kwargs(this_cls, **kwargs):
194211
# Need to initialise in case the instance does not yet exist
195212
# (to recognise the allowed fields)
196213
if '_singleton_instance' not in this_cls.__dict__:
197214
self = this_cls()
198215
else:
199216
self = this_cls._singleton_instance
200-
filtered_kwargs = {key: value for key, value in kwargs.items()
217+
cls_kwargs = {key: value for key, value in kwargs.items()
201218
if hasattr(this_cls, key) \
202219
or hasattr(this_cls._singleton_instance, key)}
203220
if not allow_underscore_vars_in_init:
204-
filtered_kwargs = {key: value for key, value in filtered_kwargs.items()
221+
cls_kwargs = {key: value for key, value in cls_kwargs.items()
205222
if not key.startswith('_')}
206-
for kk, vv in filtered_kwargs.items():
207-
setattr(self, kk, vv)
208-
return self
223+
non_cls_kwargs = kwargs.copy()
224+
for kk in cls_kwargs.keys():
225+
non_cls_kwargs.pop(kk)
226+
return non_cls_kwargs, cls_kwargs
209227

210228
# Rename the original class, for clarity in the __mro__ etc
211229
cls.__name__ = f"{cls.__name__}Original"
@@ -253,4 +271,4 @@ def _get_cls_functions(cls):
253271
else Singleton.__init_subclass__
254272
wrap_getattribute = cls.__getattribute__ if cls.__dict__.get('__getattribute__') \
255273
is not None else Singleton.__getattribute__
256-
return wrap_new, wrap_init, wrap_init_subclass, wrap_getattribute
274+
return wrap_new, wrap_init, wrap_init_subclass, wrap_getattribute

0 commit comments

Comments
 (0)