pip-run


Namepip-run JSON
Version 12.6.1 PyPI version JSON
download
home_pagehttps://github.com/jaraco/pip-run
Summaryinstall packages and run Python with them
upload_time2024-02-10 14:29:42
maintainer
docs_urlNone
authorJason R. Coombs
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://img.shields.io/pypi/v/pip-run.svg
   :target: https://pypi.org/project/pip-run

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

.. image:: https://github.com/jaraco/pip-run/actions/workflows/main.yml/badge.svg
   :target: https://github.com/jaraco/pip-run/actions?query=workflow%3A%22tests%22
   :alt: tests

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
    :target: https://github.com/astral-sh/ruff
    :alt: Ruff

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

.. image:: https://img.shields.io/badge/skeleton-2024-informational
   :target: https://blog.jaraco.com/skeleton

.. image:: https://tidelift.com/badges/package/pypi/pip-run
   :target: https://tidelift.com/subscription/pkg/pypi-pip-run?utm_source=pypi-pip-run&utm_medium=readme

``pip-run`` provides on-demand temporary package installation
for a single execution run.

It replaces this series of commands (or their Windows equivalent)::

    $ virtualenv --python pythonX.X --system-site-packages $temp/env
    $ $temp/env/bin/pip install pkg1 pkg2 -r reqs.txt
    $ $temp/env/bin/python ...
    $ rm -rf $temp/env

With this single-line command::

    $ py -X.X -m pip-run pkg1 pkg2 -r reqs.txt -- ...

.. note:: ``py`` is the Python Launcher for
   `Windows <https://docs.python.org/3/using/windows.html#launcher>`_
   or `Unix <https://python-launcher.app/>`_ and isn't required to use
   pip-run, but is used in this guide and recommended for anyone to get
   a portable, cruft-free Python invocation.

Features include

- 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.
- Leaves no trace of its invocation (except files in pip's cache).
- Supersedes installed packages when required.
- Relies on packages already satisfied [1]_.
- Re-uses the pip tool chain for package installation.

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

- trials and experiments
- build setup
- test runners
- just in time script running
- interactive development
- bug triage

``pip-run`` is a complement to Pip and Virtualenv, intended to more
readily address the on-demand needs.

.. [1] Except when a requirements file is used.

Installation
============

``pip-run`` is meant to be installed in the system site packages
alongside pip, though it can also be installed in a virtualenv.

Usage
=====

- as script launcher
- as runtime dependency context manager
- as interactive interpreter in dependency context
- as module launcher (akin to `python -m`)
- as a shell shebang (``#!/usr/bin/env pip-run``), to create single-file Python tools

Invoke ``pip-run`` from the command-line using the console entry
script (simply ``pip-run``) or using the module executable (
``python -m pip-run``). This latter usage is particularly convenient
for testing a command across various Python versions.

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 -v -r requirements.txt`` will verbosely
install all the requirements listed in a file called requirements.txt
(quiet is the default).
Any `environment variables honored by pip
<https://pip.pypa.io/en/stable/user_guide/#environment-variables>`_
are also honored.

Following the parameters to ``pip install``, one may optionally
include a ``--`` after which any parameters will be executed
by a Python interpreter in the context or directly if prefixed by
``!``.

See ``pip-run --help`` for more details.

Examples
========

The `examples folder in this project
<https://github.com/jaraco/pip-run/tree/master/examples>`_
includes some examples demonstrating
the power and usefulness of the project. Read the docs on those examples
for instructions.

Module Script Runner
--------------------

Perhaps the most powerful usage of ``pip-run`` is its ability to invoke
executable modules and packages via
`runpy <https://docs.python.org/3/library/runpy.html>`_ (aka
``python -m``)::

    $ pip-run cowsay -- -m cowsay "moove over, pip-run"

      -------------------
    < moove over, pip-run >
      -------------------
       \   ^__^
        \  (oo)\_______
           (__)\       )\/\
               ||----w |
               ||     ||

.. image:: docs/cowsay.svg
   :alt: cowsay example animation

Module Executable Runner
------------------------

Some package tools, like `ranger <https://github.com/ranger/ranger>`_, are
invoked with a unique executable instead of a module. ``pip-run`` can
run an executable from a package if it is prependend by a ``!``::

    $ pip-run ranger-fm -- '!ranger'

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 pip-run requests -- -c "import requests; print(requests.get('https://pypi.org/project/pip-run').status_code)"
    200

As long as ``pip-run`` is installed in each of Python environments
on the system, this command can be readily repeated on the other
python environments by specifying the relevant interpreter::

    $ py -3.7 -m pip-run ...

Script Runner
-------------

``pip-run`` can run a Python file with indicated dependencies. Because
arguments after ``--`` are passed directly to the Python interpreter
and because the Python interpreter will run any script, invoking a script
with dependencies is easy. Consider this script "myscript.py":

.. code-block:: python

    #!/usr/bin/env python

    import requests

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

To invoke it while making sure requests is present:

    $ pip-run requests -- myscript.py

``pip-run`` will make sure that requests is installed then invoke
the script in a Python interpreter configured with requests and its
dependencies.

For added convenience when running scripts, ``pip-run`` will infer
the beginning of Python parameters if it encounters a filename
of a Python script that exists, allowing for omission of the ``--``
for script invocation:

    $ pip-run requests myscript.py

Script-declared Dependencies
----------------------------

Building on Script Runner above, ``pip-run`` also allows
dependencies to be declared in the script itself so that
the user need not specify them at each invocation.

To declare dependencies in a script, add a ``__requires__``
variable or ``# Requirements:`` section to the script:

.. code-block:: python

    #!/usr/bin/env python

    __requires__ = ['requests']

    # or (PEP 723)

    # /// script
    # dependencies = ['requests']
    # ///

    import requests

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

With that declaration in place, one can now invoke ``pip-run`` without
declaring any parameters to pip::

    $ pip-run myscript.py
    200

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

Single-script Tools and Shebang Support
---------------------------------------

Combined with in-script dependencies, ``pip-run`` can be used as a shebang to
create fully self-contained scripts that install and run their own
dependencies, as long as ``pip-run`` is installed on the system ``PATH``.
Consider, for example, the ``pydragon`` script:

.. code-block:: shell

    #!/usr/bin/env pip-run
    __requires__ = ['requests', 'beautifulsoup4', 'cowsay']
    import requests
    from bs4 import BeautifulSoup as BS
    import cowsay
    res = requests.get('https://python.org')
    b = BS(res.text, 'html.parser')
    cowsay.dragon(b.find("div", class_="introduction").get_text())

This executable script is available in the repo as ``examples/pydragon`` (for
Unix) and ``examples/pydragon.py`` (for Windows [2]_). Executing this script is
equivalent to executing ``pip-run pydragon``.

By default, the script will assemble the dependencies on each invocation,
which may be inconvenient for a script. See `Environment Persistence
<#Environment-Persistence>`_ for a technique to persist the assembled
dependencies across invocations. One may inject ``PIP_RUN_MODE=persist``
in the shebang, but be aware that doing so breaks Windows portability.

.. [2] ``.PY`` must exist in the PATHEXT for Python scripts to be executable. See `this documentation <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#path-information>`_ for more background.

Other Script Directives
-----------------------

``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:

.. code-block:: python

    #!/usr/bin/env python

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

    import my_private_package
    ...

Extracting Requirements
-----------------------

After having used ``pip-run`` to run scripts, it may be desirable to extract the requirements from the ``__requires__`` variable or ``# Requirements:`` section of a
script to install those more permanently. pip-run provides a routine to facilitate
this case::

    $ py -m pip_run.read-deps examples/pydragon
    requests beautifulsoup4 cowsay

On Unix, it is possible to pipe this result directly to pip::

    $ pip install $(py -m pip_run.read-deps examples/pydragon)

To generate a requirements.txt file, specify a newline separator::

    $ py -m pip_run.read-deps --separator newline examples/pydragon > requirements.txt

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

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

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

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

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

Experiments and Testing
-----------------------

Because ``pip-run`` provides a single-command invocation, it
is great for experiments and rapid testing of various package
specifications.

Consider a scenario in which one wishes to create an environment
where two different versions of the same package are installed,
such as to replicate a broken real-world environment. Stack two
invocations of pip-run to get two different versions installed::

    $ pip-run keyring==21.8.0 -- -m pip-run keyring==22.0.0 -- -c "import importlib.metadata, pprint; pprint.pprint([dist._path for dist in importlib.metadata.distributions() if dist.metadata['name'] == 'keyring'])"
    [PosixPath('/var/folders/03/7l0ffypn50b83bp0bt07xcch00n8zm/T/pip-run-a3xvd267/keyring-22.0.0.dist-info'),
    PosixPath('/var/folders/03/7l0ffypn50b83bp0bt07xcch00n8zm/T/pip-run-1fdjsgfs/keyring-21.8.0.dist-info')]

.. todo: illustrate example here

IPython Inference
-----------------

If IPython is specified as one of the dependencies, the Python
interpreter will be launched via IPython (using ``-m IPython``)
for interactive mode. This behaviour may be toggled off by
setting the environment variable ``PIP_RUN_IPYTHON_MODE=ignore``.

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

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

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

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


Environment Persistence
=======================

``pip-run`` honors the ``PIP_RUN_RETENTION_STRATEGY`` variable. If unset or
set to ``destroy``, dependencies are installed to a temporary directory on
each invocation (and deleted after). Setting this variable to ``persist`` will
instead create or re-use a directory in the user's cache, only installing the
dependencies if the directory doesn't already exist. A separate cache is
maintained for each combination of requirements specified.

``persist`` strategy can greatly improve startup performance at the expense of
staleness and accumulated cruft.

Without ``PIP_RUN_RETENTION_STRATEGY=persist`` (or with ``=destroy``),
``pip-run`` will re-install dependencies every time a script runs, silently
adding to the startup time while dependencies are installed into an ephemeral
environment, depending on how many dependencies there are and whether the
dependencies have been previously downloaded to the local pip cache. Use
``pip-run -v ...`` to see the installation activity.

The location of the cache can be revealed with this command::

    py -c 'import importlib; print(importlib.import_module("pip_run.retention.persist").paths.user_cache_path)'


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

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

- ``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 ``pip-run``.

Comparison with pipx
====================

The `pipx project <https://pypi.org/project/pipx/>`_ is another mature
project with similar goals. Both projects expose a project and its
dependencies in ephemeral environments. The main difference is pipx
primarily exposes Python binaries (console scripts) from those
environments whereas pip-run exposes a Python context (including
runpy scripts).

.. list-table::
   :widths: 30 10 10
   :header-rows: 1

   * - Feature
     - pip-run
     - pipx
   * - user-mode operation
     - ✓
     - ✓
   * - invoke console scripts
     - ✓
     - ✓
   * - invoke runpy modules
     - ✓
     -
   * - run standalone scripts
     - ✓
     -
   * - interactive interpreter with deps
     - ✓
     -
   * - re-use existing environment
     - ✓
     -
   * - ephemeral environments
     - ✓
     - ✓
   * - persistent environments
     - ✓
     - ✓
   * - PEP 582 support
     -
     - ✓
   * - Specify optional dependencies
     - ✓
     -
   * - Python 2 support
     - ✓
     -

Comparison with virtualenvwrapper mktmpenv
==========================================

The `virtualenvwrapper project <https://pypi.org/project/virtualenvwrapper/>`_
attempts to address some of the use-cases that pip-run solves,
especially with the ``mktmpenv`` command, which destroys the
virtualenv after deactivation. The main difference is that ``pip-run``
is transient only for the invocation of a single command, while
``mktmpenv`` lasts for a session.

.. list-table::
   :widths: 40 10 10
   :header-rows: 1

   * - Feature
     - pip-run
     - mktmpenv
   * - create temporary package environment
     - ✓
     - ✓
   * - re-usable across python invocations
     - ✓
     - ✓
   * - portable
     - ✓
     -
   * - one-line invocation
     - ✓
     -
   * - multiple interpreters in session
     - ✓
     -
   * - run standalone scripts
     - ✓
     - ✓
   * - interactive interpreter with deps
     - ✓
     - ✓
   * - re-use existing environment
     - ✓
     -
   * - ephemeral environments
     - ✓
     - ✓
   * - persistent environments
     - ✓
     - ✓

Integration
===========

The author created this package with the intention of demonstrating
the capability before integrating it directly with pip in a command
such as ``pip run``. After proposing the change, the idea was largely
rejected in `pip 3971 <https://github.com/pypa/pip/issues/3971>`_.

If you would like to see this functionality made available in pip,
please upvote or comment in that ticket.

Versioning
==========

``pip-run`` 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``.

For Enterprise
==============

Available as part of the Tidelift Subscription.

This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

`Learn more <https://tidelift.com/subscription/pkg/pypi-pip-run?utm_source=pypi-pip-run&utm_medium=referral&utm_campaign=github>`_.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jaraco/pip-run",
    "name": "pip-run",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jason R. Coombs",
    "author_email": "jaraco@jaraco.com",
    "download_url": "https://files.pythonhosted.org/packages/be/80/d080e0e76275774b0b24124d3ffb1e06a0fd81d964f946244d1bb6a5f91c/pip-run-12.6.1.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/pip-run.svg\n   :target: https://pypi.org/project/pip-run\n\n.. image:: https://img.shields.io/pypi/pyversions/pip-run.svg\n\n.. image:: https://github.com/jaraco/pip-run/actions/workflows/main.yml/badge.svg\n   :target: https://github.com/jaraco/pip-run/actions?query=workflow%3A%22tests%22\n   :alt: tests\n\n.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\n    :target: https://github.com/astral-sh/ruff\n    :alt: Ruff\n\n.. image:: https://readthedocs.org/projects/pip-run/badge/?version=latest\n   :target: https://pip-run.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/badge/skeleton-2024-informational\n   :target: https://blog.jaraco.com/skeleton\n\n.. image:: https://tidelift.com/badges/package/pypi/pip-run\n   :target: https://tidelift.com/subscription/pkg/pypi-pip-run?utm_source=pypi-pip-run&utm_medium=readme\n\n``pip-run`` provides on-demand temporary package installation\nfor a single execution run.\n\nIt replaces this series of commands (or their Windows equivalent)::\n\n    $ virtualenv --python pythonX.X --system-site-packages $temp/env\n    $ $temp/env/bin/pip install pkg1 pkg2 -r reqs.txt\n    $ $temp/env/bin/python ...\n    $ rm -rf $temp/env\n\nWith this single-line command::\n\n    $ py -X.X -m pip-run pkg1 pkg2 -r reqs.txt -- ...\n\n.. note:: ``py`` is the Python Launcher for\n   `Windows <https://docs.python.org/3/using/windows.html#launcher>`_\n   or `Unix <https://python-launcher.app/>`_ and isn't required to use\n   pip-run, but is used in this guide and recommended for anyone to get\n   a portable, cruft-free Python invocation.\n\nFeatures include\n\n- Downloads missing dependencies and makes their packages available for import.\n- Installs packages to a special staging location such that they're not installed after the process exits.\n- Relies on pip to cache downloads of such packages for reuse.\n- Leaves no trace of its invocation (except files in pip's cache).\n- Supersedes installed packages when required.\n- Relies on packages already satisfied [1]_.\n- Re-uses the pip tool chain for package installation.\n\n``pip-run`` is not intended to solve production dependency management, but does aim to address the other, one-off scenarios around dependency management:\n\n- trials and experiments\n- build setup\n- test runners\n- just in time script running\n- interactive development\n- bug triage\n\n``pip-run`` is a complement to Pip and Virtualenv, intended to more\nreadily address the on-demand needs.\n\n.. [1] Except when a requirements file is used.\n\nInstallation\n============\n\n``pip-run`` is meant to be installed in the system site packages\nalongside pip, though it can also be installed in a virtualenv.\n\nUsage\n=====\n\n- as script launcher\n- as runtime dependency context manager\n- as interactive interpreter in dependency context\n- as module launcher (akin to `python -m`)\n- as a shell shebang (``#!/usr/bin/env pip-run``), to create single-file Python tools\n\nInvoke ``pip-run`` from the command-line using the console entry\nscript (simply ``pip-run``) or using the module executable (\n``python -m pip-run``). This latter usage is particularly convenient\nfor testing a command across various Python versions.\n\nParameters following pip-run are passed directly to ``pip install``,\nso ``pip-run numpy`` will install ``numpy`` (reporting any work done\nduring the install) and ``pip-run -v -r requirements.txt`` will verbosely\ninstall all the requirements listed in a file called requirements.txt\n(quiet is the default).\nAny `environment variables honored by pip\n<https://pip.pypa.io/en/stable/user_guide/#environment-variables>`_\nare also honored.\n\nFollowing the parameters to ``pip install``, one may optionally\ninclude a ``--`` after which any parameters will be executed\nby a Python interpreter in the context or directly if prefixed by\n``!``.\n\nSee ``pip-run --help`` for more details.\n\nExamples\n========\n\nThe `examples folder in this project\n<https://github.com/jaraco/pip-run/tree/master/examples>`_\nincludes some examples demonstrating\nthe power and usefulness of the project. Read the docs on those examples\nfor instructions.\n\nModule Script Runner\n--------------------\n\nPerhaps the most powerful usage of ``pip-run`` is its ability to invoke\nexecutable modules and packages via\n`runpy <https://docs.python.org/3/library/runpy.html>`_ (aka\n``python -m``)::\n\n    $ pip-run cowsay -- -m cowsay \"moove over, pip-run\"\n\n      -------------------\n    < moove over, pip-run >\n      -------------------\n       \\   ^__^\n        \\  (oo)\\_______\n           (__)\\       )\\/\\\n               ||----w |\n               ||     ||\n\n.. image:: docs/cowsay.svg\n   :alt: cowsay example animation\n\nModule Executable Runner\n------------------------\n\nSome package tools, like `ranger <https://github.com/ranger/ranger>`_, are\ninvoked with a unique executable instead of a module. ``pip-run`` can\nrun an executable from a package if it is prependend by a ``!``::\n\n    $ pip-run ranger-fm -- '!ranger'\n\nCommand Runner\n--------------\n\nNote that everything after the -- is passed to the python invocation,\nso it's possible to have a one-liner that runs under a dependency\ncontext::\n\n    $ python -m pip-run requests -- -c \"import requests; print(requests.get('https://pypi.org/project/pip-run').status_code)\"\n    200\n\nAs long as ``pip-run`` is installed in each of Python environments\non the system, this command can be readily repeated on the other\npython environments by specifying the relevant interpreter::\n\n    $ py -3.7 -m pip-run ...\n\nScript Runner\n-------------\n\n``pip-run`` can run a Python file with indicated dependencies. Because\narguments after ``--`` are passed directly to the Python interpreter\nand because the Python interpreter will run any script, invoking a script\nwith dependencies is easy. Consider this script \"myscript.py\":\n\n.. code-block:: python\n\n    #!/usr/bin/env python\n\n    import requests\n\n    req = requests.get('https://pypi.org/project/pip-run')\n    print(req.status_code)\n\nTo invoke it while making sure requests is present:\n\n    $ pip-run requests -- myscript.py\n\n``pip-run`` will make sure that requests is installed then invoke\nthe script in a Python interpreter configured with requests and its\ndependencies.\n\nFor added convenience when running scripts, ``pip-run`` will infer\nthe beginning of Python parameters if it encounters a filename\nof a Python script that exists, allowing for omission of the ``--``\nfor script invocation:\n\n    $ pip-run requests myscript.py\n\nScript-declared Dependencies\n----------------------------\n\nBuilding on Script Runner above, ``pip-run`` also allows\ndependencies to be declared in the script itself so that\nthe user need not specify them at each invocation.\n\nTo declare dependencies in a script, add a ``__requires__``\nvariable or ``# Requirements:`` section to the script:\n\n.. code-block:: python\n\n    #!/usr/bin/env python\n\n    __requires__ = ['requests']\n\n    # or (PEP 723)\n\n    # /// script\n    # dependencies = ['requests']\n    # ///\n\n    import requests\n\n    req = requests.get('https://pypi.org/project/pip-run')\n    print(req.status_code)\n\nWith that declaration in place, one can now invoke ``pip-run`` without\ndeclaring any parameters to pip::\n\n    $ pip-run myscript.py\n    200\n\nThe format for requirements must follow `PEP 508 <https://www.python.org/dev/peps/pep-0508/>`_.\n\nSingle-script Tools and Shebang Support\n---------------------------------------\n\nCombined with in-script dependencies, ``pip-run`` can be used as a shebang to\ncreate fully self-contained scripts that install and run their own\ndependencies, as long as ``pip-run`` is installed on the system ``PATH``.\nConsider, for example, the ``pydragon`` script:\n\n.. code-block:: shell\n\n    #!/usr/bin/env pip-run\n    __requires__ = ['requests', 'beautifulsoup4', 'cowsay']\n    import requests\n    from bs4 import BeautifulSoup as BS\n    import cowsay\n    res = requests.get('https://python.org')\n    b = BS(res.text, 'html.parser')\n    cowsay.dragon(b.find(\"div\", class_=\"introduction\").get_text())\n\nThis executable script is available in the repo as ``examples/pydragon`` (for\nUnix) and ``examples/pydragon.py`` (for Windows [2]_). Executing this script is\nequivalent to executing ``pip-run pydragon``.\n\nBy default, the script will assemble the dependencies on each invocation,\nwhich may be inconvenient for a script. See `Environment Persistence\n<#Environment-Persistence>`_ for a technique to persist the assembled\ndependencies across invocations. One may inject ``PIP_RUN_MODE=persist``\nin the shebang, but be aware that doing so breaks Windows portability.\n\n.. [2] ``.PY`` must exist in the PATHEXT for Python scripts to be executable. See `this documentation <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#path-information>`_ for more background.\n\nOther Script Directives\n-----------------------\n\n``pip-run`` also recognizes a global ``__index_url__`` attribute. If present,\nthis value will supply ``--index-url`` to pip with the attribute value,\nallowing a script to specify a custom package index:\n\n.. code-block:: python\n\n    #!/usr/bin/env python\n\n    __requires__ = ['my_private_package']\n    __index_url__ = 'https://my.private.index/'\n\n    import my_private_package\n    ...\n\nExtracting Requirements\n-----------------------\n\nAfter having used ``pip-run`` to run scripts, it may be desirable to extract the requirements from the ``__requires__`` variable or ``# Requirements:`` section of a\nscript to install those more permanently. pip-run provides a routine to facilitate\nthis case::\n\n    $ py -m pip_run.read-deps examples/pydragon\n    requests beautifulsoup4 cowsay\n\nOn Unix, it is possible to pipe this result directly to pip::\n\n    $ pip install $(py -m pip_run.read-deps examples/pydragon)\n\nTo generate a requirements.txt file, specify a newline separator::\n\n    $ py -m pip_run.read-deps --separator newline examples/pydragon > requirements.txt\n\nAnd since `pipenv <https://docs.pipenv.org/>`_ uses the same syntax,\nthe same technique works for pipenv::\n\n    $ pipenv install $(python -m pip_run.read-deps script.py)\n\nInteractive Interpreter\n-----------------------\n\n``pip-run`` also offers a painless way to run a Python interactive\ninterpreter in the context of certain dependencies::\n\n    $ /clean-install/python -m pip-run boto\n    >>> import boto\n    >>>\n\nExperiments and Testing\n-----------------------\n\nBecause ``pip-run`` provides a single-command invocation, it\nis great for experiments and rapid testing of various package\nspecifications.\n\nConsider a scenario in which one wishes to create an environment\nwhere two different versions of the same package are installed,\nsuch as to replicate a broken real-world environment. Stack two\ninvocations of pip-run to get two different versions installed::\n\n    $ pip-run keyring==21.8.0 -- -m pip-run keyring==22.0.0 -- -c \"import importlib.metadata, pprint; pprint.pprint([dist._path for dist in importlib.metadata.distributions() if dist.metadata['name'] == 'keyring'])\"\n    [PosixPath('/var/folders/03/7l0ffypn50b83bp0bt07xcch00n8zm/T/pip-run-a3xvd267/keyring-22.0.0.dist-info'),\n    PosixPath('/var/folders/03/7l0ffypn50b83bp0bt07xcch00n8zm/T/pip-run-1fdjsgfs/keyring-21.8.0.dist-info')]\n\n.. todo: illustrate example here\n\nIPython Inference\n-----------------\n\nIf IPython is specified as one of the dependencies, the Python\ninterpreter will be launched via IPython (using ``-m IPython``)\nfor interactive mode. This behaviour may be toggled off by\nsetting the environment variable ``PIP_RUN_IPYTHON_MODE=ignore``.\n\nHow Does It Work\n================\n\n``pip-run`` effectively does the following:\n\n- ``pip install -t $TMPDIR``\n- ``PYTHONPATH=$TMPDIR python``\n- cleanup\n\nFor specifics, see `pip_run.run()\n<https://github.com/jaraco/pip-run/blob/master/pip_run/__init__.py#L9-L16>`_.\n\n\nEnvironment Persistence\n=======================\n\n``pip-run`` honors the ``PIP_RUN_RETENTION_STRATEGY`` variable. If unset or\nset to ``destroy``, dependencies are installed to a temporary directory on\neach invocation (and deleted after). Setting this variable to ``persist`` will\ninstead create or re-use a directory in the user's cache, only installing the\ndependencies if the directory doesn't already exist. A separate cache is\nmaintained for each combination of requirements specified.\n\n``persist`` strategy can greatly improve startup performance at the expense of\nstaleness and accumulated cruft.\n\nWithout ``PIP_RUN_RETENTION_STRATEGY=persist`` (or with ``=destroy``),\n``pip-run`` will re-install dependencies every time a script runs, silently\nadding to the startup time while dependencies are installed into an ephemeral\nenvironment, depending on how many dependencies there are and whether the\ndependencies have been previously downloaded to the local pip cache. Use\n``pip-run -v ...`` to see the installation activity.\n\nThe location of the cache can be revealed with this command::\n\n    py -c 'import importlib; print(importlib.import_module(\"pip_run.retention.persist\").paths.user_cache_path)'\n\n\nLimitations\n===========\n\n- Due to limitations with ``pip``, ``pip-run`` cannot run with \"editable\"\n  (``-e``) requirements.\n\n- ``pip-run`` uses a ``sitecustomize`` module to ensure that ``.pth`` files\n  in the requirements are installed. As a result, any environment\n  that has a ``sitecustomize`` module will find that module masked\n  when running under ``pip-run``.\n\nComparison with pipx\n====================\n\nThe `pipx project <https://pypi.org/project/pipx/>`_ is another mature\nproject with similar goals. Both projects expose a project and its\ndependencies in ephemeral environments. The main difference is pipx\nprimarily exposes Python binaries (console scripts) from those\nenvironments whereas pip-run exposes a Python context (including\nrunpy scripts).\n\n.. list-table::\n   :widths: 30 10 10\n   :header-rows: 1\n\n   * - Feature\n     - pip-run\n     - pipx\n   * - user-mode operation\n     - \u2713\n     - \u2713\n   * - invoke console scripts\n     - \u2713\n     - \u2713\n   * - invoke runpy modules\n     - \u2713\n     -\n   * - run standalone scripts\n     - \u2713\n     -\n   * - interactive interpreter with deps\n     - \u2713\n     -\n   * - re-use existing environment\n     - \u2713\n     -\n   * - ephemeral environments\n     - \u2713\n     - \u2713\n   * - persistent environments\n     - \u2713\n     - \u2713\n   * - PEP 582 support\n     -\n     - \u2713\n   * - Specify optional dependencies\n     - \u2713\n     -\n   * - Python 2 support\n     - \u2713\n     -\n\nComparison with virtualenvwrapper mktmpenv\n==========================================\n\nThe `virtualenvwrapper project <https://pypi.org/project/virtualenvwrapper/>`_\nattempts to address some of the use-cases that pip-run solves,\nespecially with the ``mktmpenv`` command, which destroys the\nvirtualenv after deactivation. The main difference is that ``pip-run``\nis transient only for the invocation of a single command, while\n``mktmpenv`` lasts for a session.\n\n.. list-table::\n   :widths: 40 10 10\n   :header-rows: 1\n\n   * - Feature\n     - pip-run\n     - mktmpenv\n   * - create temporary package environment\n     - \u2713\n     - \u2713\n   * - re-usable across python invocations\n     - \u2713\n     - \u2713\n   * - portable\n     - \u2713\n     -\n   * - one-line invocation\n     - \u2713\n     -\n   * - multiple interpreters in session\n     - \u2713\n     -\n   * - run standalone scripts\n     - \u2713\n     - \u2713\n   * - interactive interpreter with deps\n     - \u2713\n     - \u2713\n   * - re-use existing environment\n     - \u2713\n     -\n   * - ephemeral environments\n     - \u2713\n     - \u2713\n   * - persistent environments\n     - \u2713\n     - \u2713\n\nIntegration\n===========\n\nThe author created this package with the intention of demonstrating\nthe capability before integrating it directly with pip in a command\nsuch as ``pip run``. After proposing the change, the idea was largely\nrejected in `pip 3971 <https://github.com/pypa/pip/issues/3971>`_.\n\nIf you would like to see this functionality made available in pip,\nplease upvote or comment in that ticket.\n\nVersioning\n==========\n\n``pip-run`` uses semver, so you can use this library with\nconfidence about the stability of the interface, even\nduring periods of great flux.\n\nTesting\n=======\n\nInvoke tests with ``tox``.\n\nFor Enterprise\n==============\n\nAvailable as part of the Tidelift Subscription.\n\nThis project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.\n\n`Learn more <https://tidelift.com/subscription/pkg/pypi-pip-run?utm_source=pypi-pip-run&utm_medium=referral&utm_campaign=github>`_.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "install packages and run Python with them",
    "version": "12.6.1",
    "project_urls": {
        "Homepage": "https://github.com/jaraco/pip-run"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a083212439da1b8c3380a55e84af8f3d138cd5eb3ace1b897d7416e3349ce586",
                "md5": "8e80f480fd01171ac465372fadc80ae0",
                "sha256": "76469a8088b0aef52f2ad7875232d6bb67f6dedb9e94562369a61e64d8b08638"
            },
            "downloads": -1,
            "filename": "pip_run-12.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8e80f480fd01171ac465372fadc80ae0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18761,
            "upload_time": "2024-02-10T14:29:40",
            "upload_time_iso_8601": "2024-02-10T14:29:40.133902Z",
            "url": "https://files.pythonhosted.org/packages/a0/83/212439da1b8c3380a55e84af8f3d138cd5eb3ace1b897d7416e3349ce586/pip_run-12.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be80d080e0e76275774b0b24124d3ffb1e06a0fd81d964f946244d1bb6a5f91c",
                "md5": "9267fb7754142ff518b3669c39901a62",
                "sha256": "227914cba705e9d90ce823e7163111a8a5b614c2e37fea003d506291763dafb1"
            },
            "downloads": -1,
            "filename": "pip-run-12.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9267fb7754142ff518b3669c39901a62",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 38868,
            "upload_time": "2024-02-10T14:29:42",
            "upload_time_iso_8601": "2024-02-10T14:29:42.878358Z",
            "url": "https://files.pythonhosted.org/packages/be/80/d080e0e76275774b0b24124d3ffb1e06a0fd81d964f946244d1bb6a5f91c/pip-run-12.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-10 14:29:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jaraco",
    "github_project": "pip-run",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "pip-run"
}
        
Elapsed time: 0.19124s