Giter VIP home page Giter VIP logo

current's Introduction

Current

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.

Links

Installation

This package runs under Python 3.8+, 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.2 (in development): Drop Python 3.7 support; tag Python 3.11 support.

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.

current's People

Contributors

xflr6 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

current's Issues

Add a file parameter

If the inserted_path would have the file option, then it could omit calling the sys._getframe. E.g.

>>> with current.inserted_path(file=__file__)
...     import australia

Note, I like to call it like current.inserted_path(__file__), but it would not be backward compatible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.