Skip to main content

Resolves a (possibly relative) module import to its fully qualified module name.

Project description

resolve-module-import

Resolves a (possibly relative) module import to its fully qualified module name.

Features

  • Resolves both absolute and relative Python module imports
  • Helps with tooling (e.g., linters, code analysis) that needs to resolve imports

Installation

pip install resolve-module-import

Usage

resolve_module_import(
    current_module_name,  # type: str
    current_module_is_package,  # type: bool
    imported_module_name,  # type: Optional[str]
    imported_module_level,  # type: int
)
from resolve_module_import import resolve_module_import

# from . import foo inside 'mypkg/subpkg/mymodule.py'
resolve_module_import('mypkg.subpkg.mymodule', False, 'foo', 1)
# Output: 'mypkg.subpkg.foo'

# from .. import foo inside 'pkg/bar/' (a package)
resolve_module_import('pkg.bar', True, 'foo', 2)
# Output: pkg.foo

# import sys
resolve_module_import('any.module', False, 'sys', 0)
# Output: 'sys'

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

resolve_module_import-0.1.0a0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resolve_module_import-0.1.0a0-py2.py3-none-any.whl (3.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file resolve_module_import-0.1.0a0.tar.gz.

File metadata

  • Download URL: resolve_module_import-0.1.0a0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for resolve_module_import-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 c6e9c50b8eee95e872aaaba6e0f8b274e71d77fa1028417544b6bd02da48a87a
MD5 dfffca6f34c525995aaa4e032b5492a7
BLAKE2b-256 27e61a5860c44b404f24d9877cffc5c3a7e6edf942c765c0cedb0904cea973a9

See more details on using hashes here.

File details

Details for the file resolve_module_import-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for resolve_module_import-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 323944d5005690832c424be23588d3820f3f18329c7f986c90d6fed879e4578a
MD5 a61bead5630e7a3a8d361497bb4121c0
BLAKE2b-256 bbb42d7f7d2062c638fe74ec9427ed99968c7bc2d85b5aea8211da200d1a51fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page