Skip to content

Commit 5f70bd6

Browse files
committed
feat: add option to automatically generate package documentation page
1 parent 5276868 commit 5f70bd6

1 file changed

Lines changed: 41 additions & 3 deletions

File tree

‎src/osw/controller/page_package.py‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ class CreationConfig(OswBaseModel):
375375
prefer_local_pages: bool = False
376376
"""Load the pages from the local working directory
377377
instead of the server if set to True."""
378+
generate_package_documentation_page: bool = True
379+
"""Automatically generate a documentation page for the package
380+
in the target instance and include it in the package."""
378381
generate_python_code: bool = False
379382
"""Whether to generate python code for the data models."""
380383
python_code_working_dir: Optional[Union[str, Path]] = None
@@ -407,6 +410,15 @@ def create(
407410
),
408411
)
409412
)
413+
414+
if (
415+
creation_config.generate_package_documentation_page
416+
or creation_config.generate_python_code
417+
):
418+
from osw.core import OSW
419+
420+
osw_obj = OSW(site=wtsite)
421+
410422
# Create a PagePackageBundle instance
411423
bundle = package.PagePackageBundle(
412424
publisher=self.publisher,
@@ -469,9 +481,6 @@ def create(
469481
schema_titles = [
470482
title for title in schema_titles if title.startswith("Category:")
471483
]
472-
from osw.core import OSW
473-
474-
osw_obj = OSW(site=wtsite)
475484

476485
osw_obj.fetch_schema(
477486
fetchSchemaParam=OSW.FetchSchemaParam(
@@ -493,6 +502,35 @@ def create(
493502
)
494503
)
495504

505+
if creation_config.generate_package_documentation_page:
506+
# update or create PagePackage site
507+
from opensemantic.core.v1 import Description, Label, PagePackage
508+
509+
for p in bundle.packages.values():
510+
res = wtsite.semantic_search(
511+
"[[" + PagePackage.get_cls_iri() + "]][[HasId::" + p.globalID + "]]"
512+
)
513+
pp: PagePackage = None
514+
if len(res) == 0:
515+
# generate new entity
516+
pp = PagePackage(
517+
label=[Label(text=p.globalID)],
518+
)
519+
else:
520+
# load entity
521+
pp = PagePackage[res[0]]
522+
523+
if pp.get_iri() not in self.page_titles:
524+
# prepend
525+
self.page_titles.insert(0, pp.get_iri())
526+
527+
pp.description = [Description(text=p.description)]
528+
pp.global_id = p.globalID
529+
pp.version = p.version
530+
pp.url = [bundle.publisherURL]
531+
pp.parts = self.page_titles
532+
pp.store_jsonld()
533+
496534
# Create a PagePackageConfig instance
497535
config = package.PagePackageConfig(
498536
name=self.name,

0 commit comments

Comments
 (0)