Skip to content

Commit bb85e3f

Browse files
committed
Refactored DirProperty to enable subclassing
1 parent 07b26e7 commit bb85e3f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

naucse/modelutils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,26 @@ def __init__(self, cls, *subdir, keyfunc=str):
9696
self.subdir = subdir
9797
self.keyfunc = keyfunc
9898

99-
def compute(self, instance):
100-
base = instance.path.joinpath(*self.subdir)
101-
99+
def get_ordered_dirs(self, base):
102100
model_paths = []
101+
103102
info_path = base.joinpath("info.yml")
104103
if info_path.is_file():
105104
with info_path.open(encoding='utf-8') as f:
106105
model_paths = [base.joinpath(p) for p in yaml.safe_load(f)['order']]
107-
108-
subdirectories = [p for p in sorted(base.iterdir()) if p.is_dir()]
106+
107+
remaining_subdirectories = [p for p in sorted(base.iterdir()) if p.is_dir() and p not in model_paths]
108+
109+
return model_paths + remaining_subdirectories
110+
111+
def compute(self, instance):
112+
base = instance.path.joinpath(*self.subdir)
113+
114+
dirs = self.get_ordered_dirs(base)
115+
109116
return OrderedDict(
110117
(self.keyfunc(p.parts[-1]), self.cls(instance.root, p))
111-
for p in model_paths + subdirectories
118+
for p in dirs
112119
)
113120

114121

0 commit comments

Comments
 (0)