Welcome to pip-run documentation!#

For Enterprise

Professional support for pip-run is available as part of the Tidelift Subscription. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

Learn more Request a Demo

pip_run.commands.infer_ipython(sep_args)#

Check for the presence of the argument ‘ipython’ in pip_args.

If present and py_args is empty, return arguments for pip and Python that when run will start an ipython interpreter.

>>> infer_ipython((['ipython', 'foo'], []))
(['ipython', 'foo'], ['-m', 'IPython'])
>>> infer_ipython((['ipython', 'foo'], ['bar']))
(['ipython', 'foo'], ['bar'])
>>> infer_ipython((['foo'], ['bar']))
(['foo'], ['bar'])
>>> getfixture('monkeypatch').setenv('PIP_RUN_IPYTHON_MODE', 'ignore')
>>> infer_ipython((['ipython', 'foo'], []))
(['ipython', 'foo'], [])
>>> getfixture('monkeypatch').setenv('PIP_RUN_IPYTHON_MODE', 'infer')
>>> infer_ipython((['ipython', 'foo'], []))
(['ipython', 'foo'], ['-m', 'IPython'])
pip_run.commands.intercept(args)#

Detect certain args and intercept them.

pip_run.commands.separate(args)#

Separate the command line arguments into arguments for pip and arguments to Python.

>>> separate(['foo', '--', 'bar'])
(['foo'], ['bar'])
>>> separate(['foo', 'bar'])
(['foo', 'bar'], [])
class pip_run.deps.Install#

Bases: SimpleNamespace

classmethod parse(args)#
parser = ArgumentParser(prog='__main__.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)#
pip_run.deps.contents(path)#
pip_run.deps.empty(path)#
>>> target = getfixture('tmp_path')
>>> empty(target)
True
>>> _ = target.joinpath('file.txt').write_text('contents', encoding='utf-8')
>>> empty(target)
False

A non-existent path is considered empty.

>>> empty(target / 'missing')
True
pip_run.deps.load(*args)#
pip_run.deps.pkg_installed(spec)#
pip_run.deps.retention_strategy()#
pip_run.deps.with_prereleases(spec)#

Allow prereleases to satisfy the spec.

pip_run.launch.infer_cmd(params)#

From params, infer command args for a subprocess.

If the first parameter starts with a !, it’s a literal subcommand. Otherwise, it’s parameters to a Python subprocess.

>>> infer_cmd(['a.py', 'param1'])
['...', 'a.py', 'param1']
>>> infer_cmd(['!an-exe', 'param1'])
['an-exe', 'param1']
>>> infer_cmd([]) == [sys.executable]
True
pip_run.launch.inject_sitecustomize(target: Path)#

Create a sitecustomize file in the target that will install the target as a sitedir.

>>> tmp_path = getfixture('tmp_path')
>>> inject_sitecustomize(tmp_path)
>>> sc = tmp_path / 'sitecustomize.py'
>>> 'Path' not in sc.read_text(encoding='utf-8')
True
pip_run.launch.with_path(target: Path, cmd)#

Launch cmd with target on the path

class pip_run.scripts.Dependencies(iterable=(), /)#

Bases: list

index_url = None#
classmethod load(items)#

Construct self from items, validated as requirements.

params()#
class pip_run.scripts.DepsReader(script)#

Bases: object

Given a Python script, read the dependencies it declares. Does not execute the script, so expects __requires__ to be assigned a static list of strings.

abstract classmethod load(script: Path)#

Construct a DepsReader from the script path.

read()#
read_comments()#
>>> DepsReader("# Requirements:\n# foo\n\n# baz").read()
['foo']
>>> DepsReader("# foo\n# bar").read_comments()
[]
>>> DepsReader("# Requirements:\n# foo\n# bar").read()
['foo', 'bar']
read_python()#
>>> DepsReader("__requires__=['foo']").read()
['foo']
>>> DepsReader(r"__requires__='foo\nbar\n#baz'").read()
['foo', 'bar']
read_toml()#
>>> DepsReader('# /// script\n# dependencies = ["foo", "bar"]\n# ///\n').read()
['foo', 'bar']
>>> DepsReader('# /// pyproject\n# dependencies = ["foo", "bar"]\n# ///\n').read_toml()
[]
>>> DepsReader('# /// pyproject\n#dependencies = ["foo", "bar"]\n# ///\n').read_toml()
[]
>>> DepsReader('# /// script\n# dependencies = ["foo", "bar"]\n').read_toml()
[]
>>> DepsReader('# /// script\n# ///\n\n# /// script\n# ///').read_toml()
Traceback (most recent call last):
...
ValueError: Multiple script blocks found
classmethod search(params)#

Given a (possibly-empty) series of parameters to a Python interpreter, return any dependencies discovered in a script indicated in the parameters. Only honor the first file found.

classmethod try_read(script_path: Path)#
class pip_run.scripts.NotebookDepsReader(script)#

Bases: DepsReader

classmethod load(script: Path)#

Construct a DepsReader from the script path.

class pip_run.scripts.SourceDepsReader(script)#

Bases: DepsReader

classmethod load(script: Path)#

Construct a DepsReader from the script path.

Indices and tables#