While Scripts continue to work in the ways they used to, both outside of HyperX and by pointing to a folder from the Script Runner, you may wish to package up your Scripts to benefit from the features Packages provide.
Practical examples of this are the Scripts included with the HyperX installation. Each of those Scripts was written before the Packaging capability existed and are now included as a single Package that can be installed in a couple of clicks.
The following instructions will walk through the creation of the Package Configuration File, and therefore the Package, based on pre-existing Scripts. Included with these sample Scripts are the following (shortened for brevity):
Package Command Output:
C:. +---CreateFailureModes | changelog.md | CreateFailureModes.py | readme.md | +---CreateProperties | changelog.md | CreateProperties.py | readme.md | +---ListPicker | changelog.md | ListPicker.py | readme.md | +---PrintSizingResults | changelog.md | PrintSizingResults.py | readme.md
Tip
If you do not have readmes or changelogs associated with your Scripts, we recommend that you take this time to add them.
Script readmes and changelogs are viewable from the HyperX interface, and descriptive readmes and changelogs help people better use your tools. Later, you will have the option of providing a Package-level readme to summarize all the Scripts and tools you are bundling together, and a Package-level changelog to track changes to the overall collection.
The first step to set up a Package is to create the Configuration File. While hxpkg.exe init can automate this for us, we can also create it by hand. Create a file named hxpkg.yaml in the root of the directory of the Scripts you want to package.
The beginning of this file describes the Package itself - its version, the name of the publisher, and a description, among other things.
id: collieraerospace.scripts.sample
name: Developer Sample Scripts
description: Reference scripts for script developers
keywords: []
readme: ./readme.md
publisher: SamplePublisher
changelog: ./changelog.md
dependencies: []
include: (.*\.py|requirements.txt)
exclude: (.*\.pyc|__pycache__)
apis:
scripting:
target: 1.0.0
min: 1.0.0
Note
All keys are described in further detail in the Package Keys section of Configuration File.
Note the include and exclude keys in particular. The include key tells the Package Utility to bundle additional files that aren’t specifically called out in the modules section but may be required to run one or more of the Scripts in the Package. In this example, the Package is including any additional Python file (that is, a file ending in .py), since some of these Scripts may depend on classes or functions from them.
The exclude key tells the Package Utility to specifically ignore certain files when packaging; in this case, any temporary files ending in .pyc, as well as any files found in a folder named “__pycache__”.
The next section in the Configuration File defines the Modules contained within the Package. In this case, all of the Modules are Script Modules, as specified by the type key:
- type: script
id: demo.create.properties
name: Create Properties
version: 1.0.0
script:
folder:
- Create
- Properties
description: This script shows how to create and assign design, load, and analysis properties
main: ./src/CreateProperties/CreateProperties.py
docs: ./src/CreateProperties/readme.md
changelog: ./src/CreateProperties/changelog.md
The module definition for this Script, named “Create Properties”, specifies a version, description, changelog, and documentation file. Note the script.folder key - this tells the HyperX Script Runner to display this Script in a folder called Create\Properties.
Important
You must include a separate Module for each Script that you want to include in your Package.
After building your Package and adding your Package Source in HyperX, you can see many of the items you defined in the Configuration File: the Package description, Module description, all changelogs, all readmes, and even the Configuration File itself are all displayed.