Virtue Package Registration#
Virtue uses Pluggy to register Virtue packages and include their SKILL packages in the Virtue SKILL environment. A package can register itself as a Virtue SKILL plugin by registering a dictionary by implementing a hook.
Softworks Example#
Softworks is registered as a Virtue SKILL package with the following steps
Include all your SKILL code under your top-level Python module.
Add a Virtue entry-point in your “pyproject.toml” (recommended) or “setup.py” files which points to the module containing the hook implementation.
pyproject.toml#1[project.entry-points.virtue] 2softworks = "softworks.virtue_softworks"
Add a Virtue hook implementation to register the Virtue SKILL package. The hook must be defined in the module selected in the entry-point.
Softwork’s Virtue Package registration hook implementation
softworks.virtue_softworks#1from typing import Tuple 2from pathlib import Path 3from importlib.resources import files 4import virtue 5import softworks 6 7 8def virtue_data_reg_paths() -> Tuple[Path]: 9 return ( 10 files(softworks) / "python" / "SdmPy.data.reg", 11 files(softworks) / "skill" / "SdmSkill.data.reg", 12 files(softworks) / "pptx" / "SdmPptx.data.reg", 13 files(softworks) / "xlsx" / "SdmXlsx.data.reg", 14 files(softworks) / "pdf" / "SdmPdf.data.reg", 15 files(softworks) / "html" / "SdmHtml.data.reg", 16 ) 17 18@virtue.hookimpl 19def virtue_register_skill_package(): 20 return { 21 "python_package_name": "softworks", 22 "skill_package_name": "Softworks", 23 "cdsinit_paths": (files(softworks) / "softworks.cdsinit.ils"), 24 "cdslibmgr_paths": (files(softworks) / "softworks.cdsLibMgr.il"), 25 "cds_dev_libraries": { 26 "virtue_dev_project": (files(virtue) / "softworks_dev_work"), 27 }, 28 "data_reg_paths": virtue_data_reg_paths(), 29 }
Reference#
Virtue Registration Dictionary Entry Definitions
A SKILL package can define the following entries in its registration dictionary:
- class virtue.skill_package.metadata_data.SKillPackageMetadata(*args, **kwargs)#
Required package metadata
- python_package_name: str#
Name of the python package registering the skill package.
- skill_package_name: str#
Name of the skill package.
- class virtue.skill_package.metadata_data.SKillPackageOptionalMetadata(*args, **kwargs)#
Optional SKILL package metadata
- cds_dev_libraries: Dict[str, pathlib.Path]#
Specifies OA libraries to be included in a development environment’s cds.lib. A dictionary with OA library names as the keys and Path objects to them for their values.
- cds_libraries: Dict[str, pathlib.Path]#
Specifies OA libraries to be included in the skill environment’s cds.lib. A dictionary with OA library names as the keys and Path objects to them for their values.
- cdsinit_paths: Tuple[pathlib.Path]#
Paths to .cdsinit initialization files which will be loaded into the main SKILL environment.
- cdslibmgr_paths: Tuple[pathlib.Path]#
Paths to cdsLibMgr.il initialization files which will be loaded by the library manager to customize its menus and options.
- data_reg_paths: Tuple[pathlib.Path]#
Paths to data.reg initialization files which will register tools and view types
Virtue Registration Function Definition
- virtue.plugins.hookspecs.virtue_register_skill_package() virtue.skill_package.metadata_data.SKillPackageMetadata #
Registers a skill package with Virtue.
The skill package will be loaded in Virtue’s skill environment.
- returns:
A dict containing the required package metadata keys from the SKillPackageMetadata TypedDict and, optionally, any of the keys from SKillPackageOptionalMetadata TypedDict.
Virtue defines a subset of these for itself:
Virtue’s own hook implementations
1from importlib.resources import files
2import virtue
3
4
5@virtue.hookimpl
6def virtue_register_skill_package():
7 return {
8 "python_package_name": "virtue-skill",
9 "skill_package_name": "Virtue",
10 "cdsinit_paths": (files(virtue) / "virtue.cdsinit.ils"),
11 "cdslibmgr_paths": (files(virtue) / "virtue.cdsLibMgr.il"),
12 "cds_dev_libraries": {
13 "virtue_dev_work": (files(virtue) / "virtue_dev_work"),
14 },
15 }