No project description provided
Project description
import-transforms
is a Python library for intercepting and transforming source code at import time. The main use case is unit-syntax, which modifies the Python syntax to support units of measure.
Usage
Transforms are a function that takes the raw module source as input and returns the transformed source as a str
or ast.AST
. So for example, this transform would print the name of the module when it is imported:
def print_name(source, path):
return f'print(f"{__name__}")\n' + source
Transforms are registed with a glob-style module pattern:
- "foo" matches just that single module.
- "foo.*" matches all sub-modules of "foo" (but not "foo" itself).
- "*" will match all modules.
Typically you'll want to register the transform in your pacakge's __init__.py
, with a pattern that applies to just the sub-modules of your package, e.g:
register_package_source_transform(__name__, my_transform)
Example
TODO
- check/support bytecode cached files
- how do I define a type parameter that matches a function?
- bare module import fails check_module?
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for import_transforms-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa74a8959db9e2be7a1dc6940edeb6168168eb9d722b99536b609e3910d8909b |
|
MD5 | fb9f3e6faf1bee38b227eb9be7bc07fb |
|
BLAKE2b-256 | 308ef90d26311aa56f29b499dcf3331cdf3320da40c5823c9a56582ac21f0b33 |