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
classify_imports-4.0.2.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for classify_imports-4.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09bbc28481a9f464aca30b054f74243c035324aa93cdf72f56e5fe78412fe52e |
|
MD5 | 8e1564f997f2af06f28bff6153a43906 |
|
BLAKE2b-256 | 5201714076d74df63edfab0b98c0a8ae8ff190fc1111262b4cebe4916d36ca98 |