iabs2rel


Nameiabs2rel JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/PasaOpasen/iabs2rel
SummaryA Python utility / library to convert absolute Python imports to relative
upload_time2025-01-13 09:39:21
maintainerDemetry Pascal
docs_urlNone
authorDemetry Pascal
requires_pythonNone
licenseMIT
keywords import absolute relative cli
VCS
bugtrack_url
requirements typing_extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/iabs2rel.svg)](https://pypi.org/project/iabs2rel/)
[![Downloads](https://pepy.tech/badge/iabs2rel)](https://pepy.tech/project/iabs2rel)
[![Downloads](https://pepy.tech/badge/iabs2rel/month)](https://pepy.tech/project/iabs2rel)
[![Downloads](https://pepy.tech/badge/iabs2rel/week)](https://pepy.tech/project/iabs2rel)

# iabs2rel

```
pip install iabs2rel
```

A Python utility / library to convert absolute Python imports to relative

## About

This package is purposed for conversion python code imports from absolute to relative. It is very useful in case of nested packages there it is preferable to use `..parent.file` imports instead of `root.package1.package2.package3.parent.file`.

## Advantages

- many parameters to control imports depth and code zones
- high performance
- detailed logging
- CLI allowed

## Limitations

- only `from ... import ...`  imports are allowed; other imports will be not converted to relative
- to use this package u need Python3.8 environment at least, but updating (target) code may be written in older Python
- u often need to specify proper `--python-path` paths to resolve absolute imports 

## CLI

### `iabs2rel`

```
usage: iabs2rel [-h] [--dry-run] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]
                [--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]
                sources [sources ...]

Replaces absolute file imports to relative in all sources

positional arguments:
  sources               paths to python files or directories with python files

optional arguments:
  -h, --help            show this help message and exit
  --dry-run, -n         Whether to run without performing file processing operations (default: False)
  --python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]
                        PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )
  --allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]
                        allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )
  --denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]
                        forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )
  --loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}
                        using loglevel (default: DEBUG)
  --max-depth MAX_DEPTH, -d MAX_DEPTH
                        max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0
                        disable any limits (default: 1)
```

## `iabs2rel-file`

```
usage: iabs2rel-file [-h] [--destination DESTINATION] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]
                     [--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]
                     source

Replaces absolute file imports to relative

positional arguments:
  source                python file path to replace imports

optional arguments:
  -h, --help            show this help message and exit
  --destination DESTINATION, -o DESTINATION
                        destination file; empty means to print to stdout (default: None)
  --python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]
                        PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )
  --allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]
                        allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )
  --denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]
                        forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )
  --loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}
                        using loglevel (default: DEBUG)
  --max-depth MAX_DEPTH, -d MAX_DEPTH
                        max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0
                        disable any limits (default: 1)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PasaOpasen/iabs2rel",
    "name": "iabs2rel",
    "maintainer": "Demetry Pascal",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "import, absolute, relative, cli",
    "author": "Demetry Pascal",
    "author_email": "qtckpuhdsa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/41/ed/62d4b25bc181aa855425ffe1bb7db0984809f1c2fc8d16630bb29b413b2d/iabs2rel-0.1.0.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/iabs2rel.svg)](https://pypi.org/project/iabs2rel/)\n[![Downloads](https://pepy.tech/badge/iabs2rel)](https://pepy.tech/project/iabs2rel)\n[![Downloads](https://pepy.tech/badge/iabs2rel/month)](https://pepy.tech/project/iabs2rel)\n[![Downloads](https://pepy.tech/badge/iabs2rel/week)](https://pepy.tech/project/iabs2rel)\n\n# iabs2rel\n\n```\npip install iabs2rel\n```\n\nA Python utility / library to convert absolute Python imports to relative\n\n## About\n\nThis package is purposed for conversion python code imports from absolute to relative. It is very useful in case of nested packages there it is preferable to use `..parent.file` imports instead of `root.package1.package2.package3.parent.file`.\n\n## Advantages\n\n- many parameters to control imports depth and code zones\n- high performance\n- detailed logging\n- CLI allowed\n\n## Limitations\n\n- only `from ... import ...`  imports are allowed; other imports will be not converted to relative\n- to use this package u need Python3.8 environment at least, but updating (target) code may be written in older Python\n- u often need to specify proper `--python-path` paths to resolve absolute imports \n\n## CLI\n\n### `iabs2rel`\n\n```\nusage: iabs2rel [-h] [--dry-run] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]\n                [--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]\n                sources [sources ...]\n\nReplaces absolute file imports to relative in all sources\n\npositional arguments:\n  sources               paths to python files or directories with python files\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --dry-run, -n         Whether to run without performing file processing operations (default: False)\n  --python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]\n                        PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )\n  --allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]\n                        allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )\n  --denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]\n                        forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )\n  --loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}\n                        using loglevel (default: DEBUG)\n  --max-depth MAX_DEPTH, -d MAX_DEPTH\n                        max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0\n                        disable any limits (default: 1)\n```\n\n## `iabs2rel-file`\n\n```\nusage: iabs2rel-file [-h] [--destination DESTINATION] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]\n                     [--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]\n                     source\n\nReplaces absolute file imports to relative\n\npositional arguments:\n  source                python file path to replace imports\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --destination DESTINATION, -o DESTINATION\n                        destination file; empty means to print to stdout (default: None)\n  --python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]\n                        PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )\n  --allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]\n                        allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )\n  --denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]\n                        forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )\n  --loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}\n                        using loglevel (default: DEBUG)\n  --max-depth MAX_DEPTH, -d MAX_DEPTH\n                        max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0\n                        disable any limits (default: 1)\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python utility / library to convert absolute Python imports to relative",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/PasaOpasen/iabs2rel"
    },
    "split_keywords": [
        "import",
        " absolute",
        " relative",
        " cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b450e5ad1b11d620fb20776b1dc3233932a6d765c79b3bce8c1b50f215ac813e",
                "md5": "1238b2e85e65f9eb878b039bafff76c7",
                "sha256": "039f1241415d33eeea16aa3e49db1dab450cac91feff236dbc246a12376f2ad2"
            },
            "downloads": -1,
            "filename": "iabs2rel-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1238b2e85e65f9eb878b039bafff76c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15766,
            "upload_time": "2025-01-13T09:39:19",
            "upload_time_iso_8601": "2025-01-13T09:39:19.598195Z",
            "url": "https://files.pythonhosted.org/packages/b4/50/e5ad1b11d620fb20776b1dc3233932a6d765c79b3bce8c1b50f215ac813e/iabs2rel-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41ed62d4b25bc181aa855425ffe1bb7db0984809f1c2fc8d16630bb29b413b2d",
                "md5": "6cee8b34432dc5569258591c747ebd7c",
                "sha256": "a6f5486bb29b352e329a3926e28cedafee65d990641110df12d93bc02dca4c2a"
            },
            "downloads": -1,
            "filename": "iabs2rel-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6cee8b34432dc5569258591c747ebd7c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11814,
            "upload_time": "2025-01-13T09:39:21",
            "upload_time_iso_8601": "2025-01-13T09:39:21.123388Z",
            "url": "https://files.pythonhosted.org/packages/41/ed/62d4b25bc181aa855425ffe1bb7db0984809f1c2fc8d16630bb29b413b2d/iabs2rel-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-13 09:39:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PasaOpasen",
    "github_project": "iabs2rel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "typing_extensions",
            "specs": []
        }
    ],
    "lcname": "iabs2rel"
}
        
Elapsed time: 0.76566s