Skip to main content

No project description provided

Project description

import-transforms is a Python library for intercepting and transforming source code at import time. Its main use is 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.

To apply a transform to future module imports:

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:

register_package_source_transform(__name__, my_transform)

TODO

  • check/support bytecode cached files

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

import_transforms-0.6.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

import_transforms-0.6.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page