Utilities for refactoring imports in python-like syntax.
Project description
classify-imports
Utilities for refactoring imports in python-like syntax.
installation
pip install classify-imports
examples
splitting an import object
>>> from classify_imports import import_obj_from_str
>>> obj = import_obj_from_str('import foo, bar, baz')
>>> [str(i) for i in obj.split()]
['import foo\n', 'import bar\n', 'import baz\n']
sorting import objects
# Or to partition into blocks (even with mixed imports)
>>> import pprint
>>> from classify_imports import import_obj_from_str, sort
>>> partitioned = sort(
[
import_obj_from_str('from classify_imports import sort'),
import_obj_from_str('import sys'),
import_obj_from_str('from pyramid.view import view_config'),
import_obj_from_str('import cached_property'),
],
)
>>> pprint.pprint(partitioned)
(
(import_obj_from_str('import sys\n'),),
(
import_obj_from_str('import cached_property\n'),
import_obj_from_str('from pyramid.view import view_config\n'),
),
(import_obj_from_str('from classify_imports import sort\n'),),
)
classify a module
>>> from classify_imports import classify_base, import_obj_from_str
>>> classify_base('__future__')
<Classified.FUTURE: 0>
>>> classify_base('classify_imports')
<Classified.APPLICATION: 3>
>>> classify_base('pyramid')
<Classified.THIRD_PARTY: 2>
>>> classify_base('os')
<Classified.BUILTIN: 1>
>>> classify_base(import_obj_from_str('import os.path').module_base)
<Classified.BUILTIN: 1>
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 classify_imports-4.0.0.tar.gz
.
File metadata
- Download URL: classify_imports-4.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229b00444b096c314a2da06db4530facd9207e6e9a62a3eb847c44733d0b8ab2 |
|
MD5 | a458efcd7a46b9441558d215ede2d56a |
|
BLAKE2b-256 | 1d6b5434fa39beb9e4f6e6fcf70fbcae2a81b618dd53fe16af70579459aaa6e6 |
Provenance
File details
Details for the file classify_imports-4.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: classify_imports-4.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48e192dcfc4256d4c487b83655f789c57f26a3f0a351ffff6fc14ab8ad10ed97 |
|
MD5 | e0cb5e05177462736a14b193ab4e8cf6 |
|
BLAKE2b-256 | 57734f458039e0b5e0b9f9e190102e82e53026c513b6b41cad430377b6e734db |