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.7+, 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.1: Drop Python 3.6 support.

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.1.zip (13.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file current-0.4.1.zip.

File metadata

  • Download URL: current-0.4.1.zip
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for current-0.4.1.zip
Algorithm Hash digest
SHA256 bf5ddb6669cd8cbd31247aff70cd90d52d69464cb1f2b23928a893dc940edfbd
MD5 0a3d455ddf7c1cb1215cbf70c05aa4d0
BLAKE2b-256 0022e2d9bd53d9d77d01f847f95a5b985d8abd6e8229be0a739300fe48771e7f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: current-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for current-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cdbe0e044a91a9b826af5ca3168305e09f12bc0fb3a55c5a7fe338b72940e6fa
MD5 055f399c76ccf328d9485d5972e03f43
BLAKE2b-256 3db0d837950186186dea77816946eedd2baa0ac0b2c1a7bbe46131cd3dea7589

See more details on using hashes here.

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