Metadata-Version: 2.1
Name: import-transforms
Version: 0.6.1
Summary: 
License: MIT
Author: Adam Hupp
Author-email: adam@hupp.org
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Description-Content-Type: text/markdown

`import-transforms` is a Python library for intercepting and transforming source code at import time. Its main use is [unit-syntax](https://github.com/ahupp/unit-syntax), which modifies the Python syntax to support units of measure.

# Usage

Transforms are defined by extending `import_transforms.SourceTransform`. For a small example that adds logging of every single function call, see [call_log.py](https://github.com/ahupp/import-transforms/blob/main/test/call_log.py).

To apply a transform to future module imports:

```python
register_module_source_transform("target_module", my_transform)
import target_module # transform applied!
```

The first argument is a glob-style pattern on the fully-qualified module name:

- "foo" matches just that single module.
- "foo.\*" matches all sub-modules of "foo" (but not "foo" itself).
- "\*" will match all modules.

As a shorthand to apply a transform to all sub-modules of your package, place this in `__init__.py`:

```python
register_package_source_transform(__name__, my_transform)
```

# TODO

- check/support bytecode cached files

