Extend project to add cas_lib
attribute to Tiers.
Source code in cassini/ext/cassini_lib/extension.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 | def extend_project(project: Project, cas_lib_dir: Union[str, Path] = "cas_lib"):
"""
Extend project to add `cas_lib` attribute to Tiers.
"""
cas_lib_dir = project.project_folder / cas_lib_dir
def make_cas_lib_folder(project, cas_lib_dir=cas_lib_dir):
if not cas_lib_dir.exists():
cas_lib_dir.mkdir()
(cas_lib_dir / "0.1.0").mkdir()
project.__before_setup_files__.append(
make_cas_lib_folder
) # ensures will run even if project already setup.
for Tier in project.hierarchy:
if issubclass(Tier, NotebookTierBase):
# patch in the requried attributes to classes with notebooks!
Tier.cas_lib_version = MetaAttr( # type: ignore[attr-defined]
json_type=str,
attr_type=Version,
post_get=lambda v: Version(v) if v else v,
pre_set=str,
name="cas_lib_version",
cas_field="private",
)
Tier.cas_lib = create_cas_lib(cas_lib_dir) # type: ignore[attr-defined]
return project
|