Skip to main content

Utilities for refactoring imports in python-like syntax.

Project description

Build Status Azure DevOps coverage pre-commit.ci status

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, Classified
>>> classify_base('__future__')
'FUTURE'
>>> classify_base('classify_imports')
'APPLICATION'
>>> classify_base('pyramid')
'THIRD_PARTY'
>>> classify_base('os')
'BUILTIN'
>>> classify_base(import_obj_from_str('import os.path').module_base)
'BUILTIN'
>>> Classified.APPLICATION
'APPLICATION'
>>> Classified.order
('FUTURE', 'BUILTIN', 'THIRD_PARTY', 'APPLICATION')

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.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

classify_imports-4.1.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file classify_imports-4.1.0.tar.gz.

File metadata

  • Download URL: classify_imports-4.1.0.tar.gz
  • Upload date:
  • Size: 5.0 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

Hashes for classify_imports-4.1.0.tar.gz
Algorithm Hash digest
SHA256 69ddc4320690c26aa8baa66bf7e0fa0eecfda49d99cf71a59dee0b57dac82616
MD5 2f4a46e24472237d3adf960d13be4333
BLAKE2b-256 5eb15c8792dee3437a13d66e0518bcd6add8ec6f54a02c89ef3f14986a05016d

See more details on using hashes here.

Provenance

File details

Details for the file classify_imports-4.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: classify_imports-4.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 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

Hashes for classify_imports-4.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45436d3c4c886ca9092a2c90551b392ba120360e7a782574169ddeb866bbc08a
MD5 38b27d708a633c26a60bbf3c1be61c5f
BLAKE2b-256 0a8e4dbeb81a1cfd89a67dbcb6a47f982679c39e2a64ab5cf6546747dc62985c

See more details on using hashes here.

Provenance

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