Skip to content

Commit 7615ae4

Browse files
committed
reworked excluding of classes; prepared for release
1 parent 5663031 commit 7615ae4

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

CHANGES.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
Changelog
22
=========
33

4-
0.2.3 (2024-05-3)
4+
0.2.4 (2024-05-06)
5+
------------------
6+
7+
- reworked excluding of classes
8+
9+
10+
0.2.3 (2024-05-03)
511
------------------
612

713
- `_determine_from_entry_points` method of `ClassListerRegistry` class now checks whether

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _read(f):
3030
'': 'src'
3131
},
3232
packages=find_namespace_packages(where='src'),
33-
version="0.2.3",
33+
version="0.2.4",
3434
author='Peter Reutemann',
3535
author_email='fracpete@waikato.ac.nz',
3636
entry_points={

src/seppl/_class_registry.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,20 @@ def _determine_from_class_listers(self, c: str, class_listers: List[str]) -> Lis
323323
result = []
324324

325325
if len(class_listers) > 0:
326-
try:
327-
cls = get_class(c)
328-
except:
329-
print("Failed to instantiate class: %s" % c, file=sys.stderr)
330-
traceback.print_exc()
331-
return result
326+
cls = None
332327

333328
for class_lister in class_listers:
329+
if class_lister == "":
330+
continue
331+
332+
if cls is None:
333+
try:
334+
cls = get_class(c)
335+
except:
336+
print("Failed to instantiate class: %s" % c, file=sys.stderr)
337+
traceback.print_exc()
338+
return result
339+
334340
try:
335341
func = get_class_lister(class_lister)
336342
except:
@@ -385,7 +391,8 @@ def _determine_from_env(self, c: str) -> List[str]:
385391
result = []
386392

387393
if os.getenv(self.env_class_listers) is not None:
388-
# format: "module:function,module:function,...",
394+
# format: "classlister1,classlister2,..."
395+
# classlister format: "module_name:function_name" or "module_name" if "list_classes" as method
389396
class_listers = os.getenv(self.env_class_listers).split(",")
390397
result = self._determine_from_class_listers(c, class_listers)
391398

@@ -410,11 +417,15 @@ def _initialize(self, c: str):
410417
# register from class listers as well?
411418
if (len(all_classes) == 0) or ((self._custom_class_listers is not None) and (len(self._custom_class_listers) > 0)) or self.has_env_class_listers():
412419
actual = self.actual_fallback_class_listers()
413-
for excl in self.actual_excluded_class_listers():
414-
if excl in actual:
415-
actual.remove(excl)
416420
all_classes.update(self._determine_from_class_listers(c, actual))
417421

422+
# excluded classes?
423+
excluded_listers = self.actual_excluded_class_listers()
424+
excluded_classes = self._determine_from_class_listers(c, excluded_listers)
425+
for cls in excluded_classes:
426+
if cls in all_classes:
427+
all_classes.remove(cls)
428+
418429
self._classes[c] = sorted(list(all_classes))
419430

420431
def plugins(self, c: Union[str, Type], fail_if_empty: bool = True) -> Dict[str, Plugin]:

0 commit comments

Comments
 (0)