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
File details
Details for the file import_transforms-0.2.4.tar.gz
.
File metadata
- Download URL: import_transforms-0.2.4.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
25b9b2c684943738e3ca610820183be8bc50538fec55cd4b89680893dd66f64b
|
|
MD5 |
019c1fdabbd0564e64d3a433bfb94d1b
|
|
BLAKE2b-256 |
c7b87b6cbfb20168d31d881613d3a4725e76a28b6e135ee2ad5cd4e32d5f5d49
|
File details
Details for the file import_transforms-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: import_transforms-0.2.4-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
aa74a8959db9e2be7a1dc6940edeb6168168eb9d722b99536b609e3910d8909b
|
|
MD5 |
fb9f3e6faf1bee38b227eb9be7bc07fb
|
|
BLAKE2b-256 |
308ef90d26311aa56f29b499dcf3331cdf3320da40c5823c9a56582ac21f0b33
|