Current module relative paths and imports
Project description
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.
Links
GitHub: https://github.com/xflr6/current
Issue Tracker: https://github.com/xflr6/current/issues
Download: https://pypi.org/project/current/#files
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
Changelog
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for current-0.3.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6da96f8f206314c0be90ed911042cf115a8d1bb42e4b400260f7ed1799b9711 |
|
MD5 | 8e5d2ed22b1e15953499a0698d9aa096 |
|
BLAKE2b-256 | ecf63daf78303d6ca031b71e820bfff10da2ffeff4caa7b9278a558ad702e60b |