Skip to main content

Current module relative paths and imports

Project description

Latest PyPI Version License Supported Python Versions Format

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 2.7 and 3.4+, 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 Public Domain Dedication

Changelog

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.3.4.zip (8.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.3.4-py2.py3-none-any.whl (3.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file current-0.3.4.zip.

File metadata

  • Download URL: current-0.3.4.zip
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for current-0.3.4.zip
Algorithm Hash digest
SHA256 64efe3a433f77e435ca409c7dfc120a70fbcaf6c627ef6a2bebf78bf3caeae8c
MD5 741224ea0d5e5e434409b0f94b4a37a0
BLAKE2b-256 18db1dc39f80d1bf99d43bc13a491dccebe093e8698776eb61bb3b6faf128e48

See more details on using hashes here.

File details

Details for the file current-0.3.4-py2.py3-none-any.whl.

File metadata

  • Download URL: current-0.3.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for current-0.3.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ad1e07be954de0ec513b5df06f474bd317305578c95e587ee20964db9cec3ea4
MD5 3e696c3bf5c09ee65da64989ee1c6bfd
BLAKE2b-256 c782675e94ab030f89404bfc4f9e7b27171261bcf3a369a078f375d3cca15ed5

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