Skip to main content

Current module relative paths and imports

Project description

Latest PyPI Version License Supported Python Versions Wheel format

Build Codecov

Get the path of a file relative to the current module. Import a Python module relative to the current module. Temporarily change sys.path for imports. Get the path of a file relative to the module of the current caller.

Installation

This package runs under Python 3.6+, use pip to install:

$ pip install current

Usage

Get paths relative to the current module:

>>> import current

>>> here = current.current_path()
>>> parent = current.current_path('..')
>>> bruces = current.current_path('..', 'australia', 'bruces', 'bruces.ini')

Temporarily add the parent directory to sys.path:

>>> with current.inserted_path()
...     import australia

Get paths relative to the module of the callers of the current code:

>>> caller = current.caller_path()
>>> callercaller = current.caller_path(steps=2)

Potential issues

This package uses sys._getframe (which is almost the same as inspect.currentframe, see docs). Under IronPython this might require enabling the FullFrames option of the interpreter.

License

CC0 1.0 Universal

Changelog

Version 0.4: Drop Python 2 and 3.5 support; tag Python 3.9 and 3.10 support.

Version 0.3.6: Tag Python 3.8 support. Extend test coverage.

Version 0.3.5: Drop Python 3.4 support.

Version 0.3.4: Tag Python 3.7 support.

Version 0.3.3: Drop Python 3.3 support. Add python_requires.

Version 0.3.2: Port tests from nose/unittest to pytest. Update meta data, tag Python 3.5/3.6 support.

Version 0.3.1: Added wheel.

Version 0.3: Added Python 3.3+ support.

Version 0.2.1: Fixed caller_path. Documented sys._getframe dependency.

Version 0.2: Added caller_path.

Version 0.1: First public release.

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

current-0.4.zip (13.7 kB view details)

Uploaded Source

Built Distribution

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

current-0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file current-0.4.zip.

File metadata

  • Download URL: current-0.4.zip
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for current-0.4.zip
Algorithm Hash digest
SHA256 bbcdf1bcc5b124a2bff37c8a5ad08b6767e7eefac2b8817bfa62e4532933c757
MD5 37765b4895e431802c7465a04ccf7fdf
BLAKE2b-256 7fd9ca7654b0d7bbe81a506d357797be10fab2734a2ab64eedaed197e9ba840d

See more details on using hashes here.

File details

Details for the file current-0.4-py3-none-any.whl.

File metadata

  • Download URL: current-0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for current-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 821625f220481c69bdd4c3a325ae5835c459415ee85656811062921ae0d19874
MD5 bbce1ce8112026d2bcd7cdf77429edfe
BLAKE2b-256 5b21e27dc242627592f26f9e218373a6b5042e4dcb9633beb7d0e32942a470d6

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