import-transforms


Nameimport-transforms JSON
Version 0.6.1 PyPI version JSON
download
home_page
Summary
upload_time2023-08-16 20:47:35
maintainer
docs_urlNone
authorAdam Hupp
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            `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


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "import-transforms",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Adam Hupp",
    "author_email": "adam@hupp.org",
    "download_url": "https://files.pythonhosted.org/packages/e2/77/61fa76694f01f6ce49fb862f20f4767a479724bf41d1e63e6ed476ae014b/import_transforms-0.6.1.tar.gz",
    "platform": null,
    "description": "`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.\n\n# Usage\n\nTransforms 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).\n\nTo apply a transform to future module imports:\n\n```python\nregister_module_source_transform(\"target_module\", my_transform)\nimport target_module # transform applied!\n```\n\nThe first argument is a glob-style pattern on the fully-qualified module name:\n\n- \"foo\" matches just that single module.\n- \"foo.\\*\" matches all sub-modules of \"foo\" (but not \"foo\" itself).\n- \"\\*\" will match all modules.\n\nAs a shorthand to apply a transform to all sub-modules of your package, place this in `__init__.py`:\n\n```python\nregister_package_source_transform(__name__, my_transform)\n```\n\n# TODO\n\n- check/support bytecode cached files\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.6.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b308571cb5bfed1ff3c06fe985754571e737e5ad093605676b0f08cc99dd3071",
                "md5": "b825c30b4c1e532ec8a249786e647f86",
                "sha256": "a7ca2447a5c9dc83705abb96545877178ae9a027aeac3cbe0b1d259342a64688"
            },
            "downloads": -1,
            "filename": "import_transforms-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b825c30b4c1e532ec8a249786e647f86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 4734,
            "upload_time": "2023-08-16T20:47:34",
            "upload_time_iso_8601": "2023-08-16T20:47:34.553568Z",
            "url": "https://files.pythonhosted.org/packages/b3/08/571cb5bfed1ff3c06fe985754571e737e5ad093605676b0f08cc99dd3071/import_transforms-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e27761fa76694f01f6ce49fb862f20f4767a479724bf41d1e63e6ed476ae014b",
                "md5": "b0702e73135a76fe08e175cd212ab008",
                "sha256": "9d6a471d9d620e5cfe779a5819c128c2ca3154cd7dd167ef76305f2834e80b2f"
            },
            "downloads": -1,
            "filename": "import_transforms-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b0702e73135a76fe08e175cd212ab008",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 3886,
            "upload_time": "2023-08-16T20:47:35",
            "upload_time_iso_8601": "2023-08-16T20:47:35.974885Z",
            "url": "https://files.pythonhosted.org/packages/e2/77/61fa76694f01f6ce49fb862f20f4767a479724bf41d1e63e6ed476ae014b/import_transforms-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-16 20:47:35",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "import-transforms"
}
        
Elapsed time: 0.11141s