Skip to content

Commit 8b7bb05

Browse files
committed
Add requirements.txt support. Mint 1.0.0.dev0.
Adds requirements.txt support, fixing pex-tool#5. This introduces backwards incompatible changes with pre-1.0 versions.
1 parent 8f60174 commit 8b7bb05

33 files changed

+1414
-420
lines changed

CHANGES.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
CHANGES
33
=======
44

5+
----------
6+
1.0.0.dev0
7+
----------
8+
9+
* Adds a number of flag aliases to be more compatible with pip command lines: ``--no-index``,
10+
``-f``, ``--find-links``, ``--index-url``, ``--no-use-wheel``. Removes ``-p`` in favor of
11+
``-o`` exclusively.
12+
13+
* BREAKING CHANGE: ``pex -r`` now takes requirements.txt filenames and *not* requirement
14+
specs. Requirement specs are now passed as arguments to the pex tool. Use ``--`` to escape
15+
command line arguments passed to interpreters spawned by pex. Implements
16+
`#5 <https://github.com/pantsbuild/pex/issues/5>`_.
17+
518
-----
619
0.9.0
720
-----

README.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,38 @@ Launch an interpreter with ``requests`` and ``flask`` in the environment:
4949

5050
.. code-block:: bash
5151
52-
$ pex -r requests -r flask
52+
$ pex requests flask
53+
54+
Or instead launch an interpreter with the requirements from requirements.txt:
55+
56+
.. code-block:: bash
57+
58+
$ pex -r requirements.txt
5359
5460
Run webserver.py in an environment containing ``flask`` and the setup.py package in
5561
the current working directory:
5662

5763
.. code-block::
5864
59-
$ pex -r flask -s . -- webserver.py
65+
$ pex flask -s . -- webserver.py
6066
6167
Launch Sphinx in an ephemeral pex environment using the Sphinx entry point ``sphinx:main``:
6268

6369
.. code-block:: bash
6470
65-
$ pex -r sphinx -e sphinx:main -- --help
71+
$ pex sphinx -e sphinx:main -- --help
6672
6773
Build a standalone pex binary into ``pex.pex``:
6874

6975
.. code-block::
7076
71-
$ pex -r pex -e pex.bin.pex:main -o pex.pex
77+
$ pex pex -e pex.bin.pex:main -o pex.pex
7278
7379
Build a standalone pex binary but invoked using a specific Python version:
7480

7581
.. code-block::
7682
77-
$ pex -r pex -e pex.bin.pex:main --python=pypy -o pypy-pex.pex
83+
$ pex pex -e pex.bin.pex:main --python=pypy -o pypy-pex.pex
7884
7985
Most pex options compose well with one another, so the above commands can be
8086
mixed and matched.

docs/buildingpex.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ Specifying requirements
4444
-----------------------
4545

4646
Requirements are specified using the same form as expected by ``setuptools``, e.g. ``flask``, ``setuptools==2.1.2``,
47-
``Django>=1.4,<1.6``. These are specified using the ``-r`` option and may be specified multiple times. For example,
48-
to start an environment with ``flask`` and ``psutil>1``::
47+
``Django>=1.4,<1.6``. These are specified as arguments to pex and any number (including 0) may be specified.
48+
For example, to start an environment with ``flask`` and ``psutil>1``::
4949

50-
$ pex -r flask -r 'psutil>1'
50+
$ pex flask 'psutil>1'
5151
Python 2.6.9 (unknown, Jan 2 2014, 14:52:48)
5252
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
5353
Type "help", "copyright", "credits" or "license" for more information.
@@ -72,7 +72,7 @@ Entry points define how the environment is executed and may be specified using t
7272
As mentioned above, if no entry points are specified, the default behavior is to emulate an
7373
interpreter::
7474

75-
$ pex -r flask
75+
$ pex flask
7676
Python 2.6.9 (unknown, Jan 2 2014, 14:52:48)
7777
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
7878
Type "help", "copyright", "credits" or "license" for more information.
@@ -92,7 +92,7 @@ Like an interpreter, if a source file is specified, it is invoked::
9292
> app.run()
9393
> EOF
9494

95-
$ pex -r flask -- ./flask_hello_world.py
95+
$ pex flask -- ./flask_hello_world.py
9696
* Running on http://127.0.0.1:5000/
9797

9898
As an example of using a non-empty entry point, consider the Python ``pydoc``
@@ -121,7 +121,7 @@ This can be emulated using the ``pex`` tool using ``-e pydoc``::
121121
Arguments will be passed unescaped following ``--`` on the command line. So in order to
122122
get pydoc help on the ``flask.app`` package in Flask::
123123

124-
$ pex -r flask -e pydoc -- flask.app
124+
$ pex flask -e pydoc -- flask.app
125125
Help on module flask.app in flask:
126126

127127
NAME
@@ -142,7 +142,7 @@ and Fabric respectively. This is roughly equivalent to running a script that do
142142
This can be a powerful way to invoke Python applications without ever having to ``pip install``
143143
anything, for example a one-off invocation of Sphinx with the readthedocs theme available::
144144

145-
$ pex -r sphinx -r sphinx_rtd_theme -e sphinx:main -- --help
145+
$ pex sphinx sphinx_rtd_theme -e sphinx:main -- --help
146146
Sphinx v1.2.2
147147
Usage: /var/folders/4d/9tz0cd5n2n7947xs21gspsxc0000gp/T/tmpLr8ibZ [options] sourcedir outdir [filenames...]
148148

@@ -163,7 +163,7 @@ exist for the duration of the pex command lifetime and immediately garbage colle
163163
If the ``-o PATH`` option is specified, a PEX file of the environment is saved to disk at ``PATH``. For example
164164
we can package a standalone Sphinx as above::
165165

166-
$ pex -r sphinx -r sphinx_rtd_theme -e sphinx:main -o sphinx.pex
166+
$ pex sphinx sphinx_rtd_theme -e sphinx:main -o sphinx.pex
167167

168168
Instead of executing the environment, it is saved to disk::
169169

@@ -188,7 +188,7 @@ As before, entry points are not required, and if not specified the PEX will defa
188188
an interpreter. If an alternate interpreter is specified with ``--python``, e.g. pypy, it will be the
189189
default hashbang in the PEX file::
190190

191-
$ pex --python=pypy -r flask -o flask-pypy.pex
191+
$ pex --python=pypy flask -o flask-pypy.pex
192192

193193
The hashbang of the PEX file specifies PyPy::
194194

@@ -208,17 +208,16 @@ and when invoked uses the environment PyPy::
208208
Tailoring requirement resolution
209209
--------------------------------
210210

211-
By default, ``pex`` fetches artifacts from PyPI. This can be disabled with ``--no-pypi`` and
212-
explicitly enabled with ``--pypi``.
211+
By default, ``pex`` fetches artifacts from PyPI. This can be disabled with ``--no-index``.
213212

214-
If PyPI fetching is disabled, you will need to specify a search repository via ``--repo``. This
213+
If PyPI fetching is disabled, you will need to specify a search repository via ``-f/--find-links``. This
215214
may be a directory on disk or a remote simple http server.
216215

217216
For example, you can delegate artifact fetching and resolution to ``pip wheel`` for whatever
218217
reason -- perhaps you're running a firewalled mirror -- but continue to package with pex::
219218

220219
$ pip wheel sphinx sphinx_rtd_theme
221-
$ pex -r sphinx -r sphinx_rtd_theme -e sphinx:main --no-pypi --repo=wheelhouse -o sphinx.pex
220+
$ pex sphinx sphinx_rtd_theme -e sphinx:main --no-index --find-links=wheelhouse -o sphinx.pex
222221

223222

224223
Tailoring PEX execution

pex/archiver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
2+
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3+
14
import contextlib
25
import os
36
import tarfile

pex/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def maybe_requirement_list(reqs):
3838

3939

4040
def requirement_is_exact(req):
41-
return req.specs and len(req.specs) == 1 and req.specs[0][0] == '=='
41+
return bool(req.specs and len(req.specs) == 1 and req.specs[0][0] == '==')

0 commit comments

Comments
 (0)