Skip to content

Commit

Permalink
Merge pull request #35 from jaraco/feature/pip-run
Browse files Browse the repository at this point in the history
Rename project to pip-run
  • Loading branch information
jaraco committed Nov 5, 2018
2 parents d0e335c + 7255e23 commit 3920a2b
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 76 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
5.0
---

#34: Renamed project from ``rwt`` to ``pip-run``.

4.4.2
-----

Expand Down
90 changes: 44 additions & 46 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
.. image:: https://img.shields.io/pypi/v/rwt.svg
:target: https://pypi.org/project/rwt
.. image:: https://img.shields.io/pypi/v/pip-run.svg
:target: https://pypi.org/project/pip-run

.. image:: https://img.shields.io/pypi/pyversions/rwt.svg
.. image:: https://img.shields.io/pypi/pyversions/pip-run.svg

.. image:: https://img.shields.io/travis/jaraco/rwt/master.svg
:target: https://travis-ci.org/jaraco/rwt
.. image:: https://img.shields.io/travis/jaraco/pip-run/master.svg
:target: https://travis-ci.org/jaraco/pip-run

.. image:: https://img.shields.io/appveyor/ci/jaraco/rwt/master.svg
:target: https://ci.appveyor.com/project/jaraco/rwt/branch/master
.. image:: https://img.shields.io/appveyor/ci/jaraco/pip-run/master.svg
:target: https://ci.appveyor.com/project/jaraco/pip-run/branch/master

.. image:: https://readthedocs.org/projects/rwt/badge/?version=latest
:target: https://rwt.readthedocs.io/en/latest/?badge=latest
.. image:: https://readthedocs.org/projects/pip-run/badge/?version=latest
:target: https://pip-run.readthedocs.io/en/latest/?badge=latest

/ruːt/

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

Expand All @@ -26,14 +24,14 @@ session.
- 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:
``pip-run`` 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
``pip-run`` 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``.

Expand All @@ -47,13 +45,13 @@ Usage
- as interactive interpreter in dependency context
- as module launcher (akin to `python -m`)

Invoke ``rwt`` from the command-line using the console entry
script (simply ``rwt``) or using the module executable (
``python -m rwt``).
Invoke ``pip-run`` from the command-line using the console entry
script (simply ``pip-run``) or using the module executable (
``python -m pip-run``).

Parameters following rwt are passed directly to ``pip install``,
so ``rwt numpy`` will install ``numpy`` (reporting any work done
during the install) and ``rwt -q -r requirements.txt`` will quietly
Parameters following pip-run are passed directly to ``pip install``,
so ``pip-run numpy`` will install ``numpy`` (reporting any work done
during the install) and ``pip-run -q -r requirements.txt`` will quietly
install all the requirements listed in a file called requirements.txt.

Following the parameters to ``pip install``, one may optionally
Expand All @@ -67,16 +65,16 @@ 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.

In many of these examples, the option ``-q`` is passed to ``rwt``
In many of these examples, the option ``-q`` is passed to ``pip-run``
to suppress the output from pip.

Interactive Interpreter
-----------------------

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

$ /clean-install/python -m rwt -q boto
$ /clean-install/python -m pip-run -q boto
>>> import boto
>>>

Expand All @@ -88,7 +86,7 @@ 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 -q requests -- -c "import requests; print(requests.get('https://pypi.org/project/rwt').status_code)"
$ python -m pip-run -q requests -- -c "import requests; print(requests.get('https://pypi.org/project/pip-run').status_code)"
200

Script Runner
Expand All @@ -98,7 +96,7 @@ 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
<https://pypi.org/project/requests>`_. Here's how you can use rwt to
<https://pypi.org/project/requests>`_. Here's how you can use pip-run to
declare the dependencies and launch the script in a context where
those dependencies have been resolved.

Expand All @@ -110,17 +108,17 @@ First, add a ``__requires__`` directive at the head of the script::

import requests

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

Then, simply invoke that script with rwt::
Then, simply invoke that script with pip-run::

$ python -m rwt -q -- myscript.py
$ python -m pip-run -q -- myscript.py
200

The format for requirements must follow `PEP 508 <https://www.python.org/dev/peps/pep-0508/>`_.

Note that URLs specifiers are not supported by pip, but ``rwt`` supports a
Note that URLs specifiers are not supported by pip, but ``pip-run`` supports a
global ``__dependency_links__`` attribute which can be used, for example, to
install requirement from a project VCS URL::

Expand All @@ -131,7 +129,7 @@ install requirement from a project VCS URL::

[...]

``rwt`` also recognizes a global ``__index_url__`` attribute. If present,
``pip-run`` 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::

Expand All @@ -147,7 +145,7 @@ Replacing setup_requires
------------------------

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

#!/usr/bin/env python
Expand All @@ -161,7 +159,7 @@ the ``__requires__`` directive::
setup_requires=__requires__,
)

When invoked with rwt, the dependencies will be assured before
When invoked with pip-run, 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.
Expand Down Expand Up @@ -198,9 +196,9 @@ tests_require in setup.py::
tests_require=tests_require,
)

Then invoke tests with rwt::
Then invoke tests with pip-run::

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

While still supporting the old technique::

Expand All @@ -209,45 +207,45 @@ While still supporting the old technique::
Supplying parameters to Pip
---------------------------

If you've been using ``rwt``, you may have defined some requirements
If you've been using ``pip-run``, you may have defined some requirements
in the ``__requires__`` of a script, but now you wish to install those
to a more permanent environment. rwt provides a routine to facilitate
to a more permanent environment. pip-run provides a routine to facilitate
this case:

$ python -m rwt.read-deps script.py
$ python -m pip_run.read-deps script.py
my_dependency

If you're on Unix, you may pipe this result directly to pip:

$ pip install $(python -m rwt.read-deps script.py)
$ pip install $(python -m pip_run.read-deps script.py)

And since `pipenv <https://docs.pipenv.org/>`_ uses the same syntax,
the same technique works for pipenv:

$ pipenv install $(python -m rwt.read-deps script.py)
$ pipenv install $(python -m pip_run.read-deps script.py)

How Does It Work
================

RWT effectively does the following:
``pip-run`` effectively does the following:

- ``pip install -t $TMPDIR``
- ``PYTHONPATH=$TMPDIR python``
- cleanup

For specifics, see `rwt.run()
<https://github.com/jaraco/rwt/blob/master/rwt/__init__.py#L9-L16>`_.
For specifics, see `pip_run.run()
<https://github.com/jaraco/pip-run/blob/master/pip_run/__init__.py#L9-L16>`_.

Limitations
===========

- Due to limitations with ``pip``, RWT cannot run with "editable"
- Due to limitations with ``pip``, ``pip-run`` cannot run with "editable"
(``-e``) requirements.

- RWT uses a ``sitecustomize`` module to ensure that ``.pth`` files
- ``pip-run`` uses a ``sitecustomize`` module to ensure that ``.pth`` files
in the requirements are installed. As a result, any environment
that has a ``sitecustomize`` module will find that module masked
when running under RWT.
when running under ``pip-run``.


Integration
Expand All @@ -264,7 +262,7 @@ please upvote or comment in that ticket.
Versioning
==========

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

Expand Down
11 changes: 11 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
collect_ignore = ['examples']


def pytest_configure():
workaround_sugar_issue_159()


def workaround_sugar_issue_159():
"https://github.com/Frozenball/pytest-sugar/159"
import pytest_sugar
pytest_sugar.SugarTerminalReporter.pytest_runtest_logfinish = \
lambda self: None
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Welcome to rwt documentation!
Welcome to pip-run documentation!
=============================

.. toctree::
Expand All @@ -7,7 +7,7 @@ Welcome to rwt documentation!
history


.. automodule:: rwt
.. automodule:: pip_run
:members:
:undoc-members:
:show-inheritance:
Expand Down
10 changes: 5 additions & 5 deletions examples/test-mongodb-covered-query.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
This script demonstrates how RWT facilitates the
This script demonstrates how ``pip-run`` facilitates the
simple execution of complex tasks with their
dependencies.
Run this example with ``rwt -- $script``.
Run this example with ``pip-run -- $script``.
It creates a MongoDB instance, and then runs some
assertions against it.
Expand All @@ -15,13 +15,13 @@
specify the MongoDB version to use for the ephemeral
instance.
Running this script with RWT leaves no trace of its
Running this script with ``pip-run``` leaves no trace of its
execution, other than adding packages to the pip
cache (if available), so feel free to give it a try.
This script gets read three times:
- First ``rwt`` reads it statically to determine the
- First ``pip-run`` reads it statically to determine the
dependencies found in ``__requires__`` and
installs those dependencies in a temp dir.
- Then, the script is executed by a Python interpreter
Expand All @@ -33,7 +33,7 @@
fixture for the test.
Alternately, the script could be
invoked thus: ``rwt -- -m pytest $script``, which would
invoked thus: ``pip-run -- -m pytest $script``, which would
eliminate the need for the ``__main__`` block and
would skip the second processing of the script.
"""
Expand Down
4 changes: 4 additions & 0 deletions pip-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pip_run import run


__name__ == '__main__' and run()
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions rwt/commands.py → pip_run/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def parse_script_args(args):
help_doc = textwrap.dedent("""
Usage:
Arguments to rwt prior to `--` are used to specify the requirements
Arguments to pip-run prior to `--` are used to specify the requirements
to make available, just as arguments to pip install. For example,
rwt -r requirements.txt "requests>=2.0"
pip-run -r requirements.txt "requests>=2.0"
That will launch python after installing the deps in requirements.txt
and also a late requests. Packages are always installed to a temporary
Expand All @@ -34,15 +34,15 @@ def parse_script_args(args):
Arguments after `--` are passed to the Python interpreter. So to launch
`script.py`:
rwt -- script.py
pip-run -- script.py
If the `--` is ommitted or nothing is passed, the python interpreter
will be launched in interactive mode:
rwt
pip-run
>>>
For more examples and details, see https://pypi.org/project/rwt.
For more examples and details, see https://pypi.org/project/pip-run.
""").lstrip()


Expand Down
2 changes: 1 addition & 1 deletion rwt/deps.py → pip_run/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _installable(args):

@contextlib.contextmanager
def load(*args):
target = tempfile.mkdtemp(prefix='rwt-')
target = tempfile.mkdtemp(prefix='pip-run-')
cmd = (
sys.executable,
'-m', 'pip',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions rwt/tests/test_deps.py → pip_run/tests/test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pkg_resources

from rwt import deps
from pip_run import deps


def test_entry_points():
Expand All @@ -16,24 +16,24 @@ def test_entry_points():

class TestInstallCheck:
def test_installed(self):
assert deps.pkg_installed('rwt')
assert deps.pkg_installed('pip-run')

def test_not_installed(self):
assert not deps.pkg_installed('not_a_package')

def test_installed_version(self):
assert not deps.pkg_installed('rwt==0.0')
assert not deps.pkg_installed('pip-run==0.0')

def test_not_installed_args(self):
args = [
'-i', 'https://devpi.net',
'-r', 'requirements.txt',
'rwt',
'pip-run',
'not_a_package',
'rwt==0.0',
'pip-run==0.0',
]
expected = copy.copy(args)
expected.remove('rwt')
expected.remove('pip-run')
filtered = deps.not_installed(args)
assert list(filtered) == expected

Expand Down

0 comments on commit 3920a2b

Please sign in to comment.