hmd-lib-mickey
Common library for code generation used in hmd-tf-mickey.
The library provides basic abstractions around building data contexts, downloading and using remote packages, and rendering Jinja templates.
It also provides mechanisms to provide pre/post-hooks to various parts of the generation process.
Basic Usage
There are two core classes required perform code generation, MickeyRunConfiguration and MickeyRun.
MickeyRunConfiguration represents the basic configuration of the current code generation run.
It contains properties for the context definitions, template paths to render, data contexts to use, etc.
The easiest way to build it is passing a simple Mickey transform instance context.
config = MickeyRunConfiguration(
project_name, # project repository name
{
"input": input_content_path,
"output": output_content_path,
"cache": cache_path,
}, # Dirs dictionary containing paths for finding inputs, where to output results, and cache location
transform_instance_context,
variables=transform_instance_context.get("variables", {}), # Additional variables to use
skip_deps=skip_deps, # Flad to download remote packages or not
hook_scripts=hooks, # Paths to hook scripts
)
The transform_instance_context has the following shape:
{
"context_definitions": {},
"template_packages": [],
"templates": [],
"contexts": [],
"hooks": []
}
A list of MickeyPhase instances and a name is passed to MickeyRun.
This represents the actual running of the code generator.
You can build your own set of phases, but it is probably easier to use the default set PHASES found in hmd_lib_mickey.phases.
from hmd_lib_mickey.types import MickeyRun
from hmd_lib_mickey.phases import PHASES
run = MickeyRun(PHASES, 'run')
The final step is to actually perform the code generation with the generate function.
from hmd_lib_mickey.hmd_lib_mickey import generate
generate(run, config)
Phase Hooks
The base class MickeyPhase has two decorator methods for extension via pre/post hooks.
The decorator methods expect a function that takes a MickeyRunConfiguration instance as its only argument and returns either the same instance or a mutated copy.
Example:
from hmd_lib_mickey.phases import BuildEnvironment
from hmd_lib_mickey.types import MickeyRunConfiguration
@BuildEnvironment.post_hook
def add_jinja_filters(config: MickeyRunConfiguration):
env = config.environment
# Mutate the Jinja Environment
# ...
return config.copy(environment=env)
The above example adds a post-hook to the BuildEnvironment phase to edit the standard Jinja Environment used.
You can use it to add filter functions to be used by templates for example.
Hooks can included in the code generation run by giving a list of paths to single Python scripts in the MickeyRunConfiguration.
Currently, you cannot import relative packages from the scripts because Mickey copies only the script to the cache location.
The MickeyRun will handle importing each listed script, which will cause any decorators used to run and register with the appropriate phase.
Metadata
Release files for hmd-lib-mickey 0.1.77
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hmd_lib_mickey-0.1.77-py3-none-any.whl | Python 3 | none | any | Details |
Release files / hmd_lib_mickey-0.1.77-py3-none-any.whl
| Download URL | hmd_lib_mickey-0.1.77-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
505aac079b3aa784e887e9ec253553c69a7dcc6a9b7639721f976c0fc891ccfa
|
|
BLAKE2b-256 checksum How to use checksums |
889e4a42faa61de73077aed054e76ac99bef1766a45d561c58b1af88bcde198e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.15
|
Security for hmd-lib-mickey 0.1.77
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.