Skip to main content

run with this

Project description

/ruːt/

RWT (Run With This) provides on-demand dependency resolution, making packages available for the duration of an interpreter session.

https://img.shields.io/pypi/v/rwt.svg https://img.shields.io/pypi/pyversions/rwt.svg https://img.shields.io/pypi/dm/rwt.svg https://img.shields.io/travis/jaraco/rwt/master.svg
  • Allows declaration of dependencies at runtime.

  • Downloads missing dependencies and makes their packages available for import.

  • Installs packages to a special staging location such that they’re not installed after the process exits.

  • Relies on pip to cache downloads of such packages for reuse.

  • Supersedes installed packages when required.

  • Relies on packages already satisfied [1].

  • Re-uses the pip tool chain for package installation.

RWT is not intended to solve production dependency management, but does aim to address the other, one-off scenarios around dependency management:

  • build setup

  • test runners

  • just in time script running

  • interactive development

RWT is a compliment to Pip and Virtualenv and Setuptools, intended to more readily address the on-demand needs and supersede some features like setup_requires.

License

License is indicated in the project metadata (typically one or more of the Trove classifiers). For more details, see this explanation.

Usage

  • as script launcher

  • as runtime dependency context manager

  • as interactive interpreter in dependency context

  • as module launcher (akin to python -m)

Examples

The examples folder in this project includes some examples demonstrating the power and usefulness of the project. Read the docs on those examples for instructions.

Script Runner

Let’s say you have a script that has a one-off purpose. It’s either not part of a library, where dependencies are normally declared, or it is normally executed outside the context of that library. Still, that script probably has dependencies, say on requests. Here’s how you can use rwt to declare the dependencies and launch the script in a context where those dependencies have been resolved.

First, add a __requires__ directive at the head of the script:

#!/usr/bin/env python

__requires__ = ['requests']

import requests

req = requests.get('https://pypi.org/project/rwt')
print(req.status_code)

Then, simply invoke that script with rwt:

$ python -m rwt -- myscript.py
Loading requirements using requests
200

rwt also recognizes a global __index_url__ attribute. If present, this value will supply --index-url to pip with the attribute value, allowing a script to specify a custom package index:

#!/usr/bin/env python

__requires__ = ['my_private_package']
__index_url__ = 'https://my.private.index/'

import my_private_package
...

Command Runner

Note that everything after the – is passed to the python invocation, so it’s possible to have a one-liner that runs under a dependency context:

$ python -m rwt requests -- -c "import requests; print(requests.get('https://pypi.io/project/rwt').status_code)"
Loading requirements using requests
200

Interactive Interpreter

RWT also offers a painless way to run a Python interactive interpreter in the context of certain dependencies:

$ /clean-install/python -m rwt boto
Loading requirements using boto
>>> import boto
>>>

Replacing setup_requires

Following the script example, you can make your setup.py file compatible with rwt by declaring your depenedencies in the __requires__ directive:

#!/usr/bin/env python

__requires__ = ['setuptools', 'setuptools_scm']

import setuptools

setuptools.setup(
    ...
    setup_requires=__requires__,
)

When invoked with rwt, the dependencies will be assured before the script is run, or if run with setuptools, the dependencies will be loaded using the older technique, so the script is backward compatible.

Replacing tests_require

You can also replace tests_require. Consider a package that runs tests using setup.py test and relies on the tests_require directive to resolve dependencies needed during testing. Simply declare your dependencies in a separate file, e.g. “tests/requirements.txt”:

cat > tests/requiremenst.txt
pytest

For compatibility, expose those same requirements as tests_require in setup.py:

with io.open('tests/requirements.txt') as tr:
    tests_require = [
            line.rstrip()
            for line in tr
            if re.match('\w+', line)
    ]

setuptools.setup(
    ...
    tests_require=tests_require,
)

Then invoke tests with rwt:

$ python -m rwt -r tests/requirements.txt -- setup.py test

While still supporting the old technique:

$ python setup.py test

How Does It Work

RWT effectively does the following:

  • pip install -t $TMPDIR

  • PYTHONPATH=$TMPDIR python

  • cleanup

For specifics, see rwt.run().

Versioning

RWT uses semver, so you can use this library with confidence about the stability of the interface, even during periods of great flux.

Testing

Invoke tests with tox.

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

rwt-3.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

rwt-3.0-py2.py3-none-any.whl (14.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file rwt-3.0.tar.gz.

File metadata

  • Download URL: rwt-3.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rwt-3.0.tar.gz
Algorithm Hash digest
SHA256 1830f10a733f57176a5b155dfcb8d10ea47e553a76f9dd673fe7b7fe7e0fa147
MD5 dc3a7dd4194c5c1935eddab221ec5a69
BLAKE2b-256 e6e993cb62ce30cf0449a1837dd84dbb36146316a4b35f64e36863c5b99b2707

See more details on using hashes here.

File details

Details for the file rwt-3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: rwt-3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rwt-3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4fd253f041b735620d2a0cb0255075da41c3e406b91777b59c0589c98368e12a
MD5 c235acfce9b46101b95dea1c751b6f53
BLAKE2b-256 b597ac789b8255627072b4ec91f88cdcf73c93af07a3d9b4a8da152052addacb

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