Skip to content

Commit

Permalink
Merged in carljm/tox (pull request gevent#123)
Browse files Browse the repository at this point in the history
Add --pre and testenv pip_pre options, no --pre by default.
  • Loading branch information
hpk42 committed Oct 21, 2014
2 parents 0384af8 + 5ace5b1 commit 6e4595e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
@@ -1,3 +1,12 @@
1.9.0.dev
-----------

- fix issue193: Remove ``--pre`` from the default ``install_command``; by
default tox will now only install final releases from PyPI for unpinned
dependencies. Use ``pip_pre = true`` in a testenv or the ``--pre``
command-line option to restore the previous behavior.


1.8.1.dev
-----------

Expand Down
17 changes: 16 additions & 1 deletion doc/config.txt
Expand Up @@ -106,7 +106,22 @@ Complete list of settings that you can put into ``testenv*`` sections:

**default**::

pip install --pre {opts} {packages}
pip install {opts} {packages}

.. confval:: pip_pre=True|False(default)

.. versionadded:: 1.9

If ``True``, adds ``--pre`` to the ``opts`` passed to
:confval:`install_command`. If :confval:`install_command` uses pip, this
will cause it to install the latest available pre-release of any
dependencies without a specified version. If ``False`` (the default), pip
will only install final releases of unpinned dependencies.

Passing the ``--pre`` command-line option to tox will force this to
``True`` for all testenvs.

Don't set this option if your :confval:`install_command` does not use pip.

.. confval:: whitelist_externals=MULTI-LINE-LIST

Expand Down
19 changes: 19 additions & 0 deletions tests/test_config.py
Expand Up @@ -106,6 +106,7 @@ def test_defaults(self, tmpdir, newconfig):
envconfig = config.envconfigs['python']
assert envconfig.args_are_paths
assert not envconfig.recreate
assert not envconfig.pip_pre

def test_defaults_distshare(self, tmpdir, newconfig):
config = newconfig([], "")
Expand Down Expand Up @@ -620,6 +621,24 @@ def test_install_command_substitutions(self, newconfig):
'some_install', '--arg=%s/foo' % config.toxinidir, 'python',
'{opts}', '{packages}']

def test_pip_pre(self, newconfig):
config = newconfig("""
[testenv]
pip_pre=true
""")
envconfig = config.envconfigs['python']
assert envconfig.pip_pre

def test_pip_pre_cmdline_override(self, newconfig):
config = newconfig(
['--pre'],
"""
[testenv]
pip_pre=false
""")
envconfig = config.envconfigs['python']
assert envconfig.pip_pre

def test_downloadcache(self, newconfig, monkeypatch):
monkeypatch.delenv("PIP_DOWNLOAD_CACHE", raising=False)
config = newconfig("""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_venv.py
Expand Up @@ -211,6 +211,25 @@ def test_install_deps_indexserver(newmocksession):
assert "-i ABC" in args
assert "dep3" in args

def test_install_deps_pre(newmocksession):
mocksession = newmocksession([], """
[testenv]
pip_pre=true
deps=
dep1
""")
venv = mocksession.getenv('python')
venv.create()
l = mocksession._pcalls
assert len(l) == 1
l[:] = []

venv.install_deps()
assert len(l) == 1
args = " ".join(l[0].args)
assert "--pre " in args
assert "dep1" in args

def test_installpkg_indexserver(newmocksession, tmpdir):
mocksession = newmocksession([], """
[tox]
Expand Down
9 changes: 7 additions & 2 deletions tox/_config.py
Expand Up @@ -105,6 +105,9 @@ def prepare_parse(pkgname):
dest="indexurl", metavar="URL",
help="set indexserver url (if URL is of form name=url set the "
"url for the 'name' indexserver, specifically)")
parser.add_argument("--pre", action="store_true", dest="pre",
help="install pre-releases and development versions of dependencies. "
"This will pass the --pre option to install_command (pip by default).")
parser.add_argument("-r", "--recreate", action="store_true",
dest="recreate",
help="force recreation of virtual environments")
Expand Down Expand Up @@ -381,15 +384,17 @@ def _makeenvconfig(self, name, section, subs, config):
downloadcache = os.environ.get("PIP_DOWNLOAD_CACHE", downloadcache)
vc.downloadcache = py.path.local(downloadcache)

pip_default_opts = ["--pre", "{opts}", "{packages}"]
vc.install_command = reader.getargv(
section,
"install_command",
"pip install " + " ".join(pip_default_opts),
"pip install {opts} {packages}",
)
if '{packages}' not in vc.install_command:
raise tox.exception.ConfigError(
"'install_command' must contain '{packages}' substitution")
vc.pip_pre = config.option.pre or reader.getbool(
section, "pip_pre", False)

return vc

def _getenvdata(self, reader, toxsection):
Expand Down
2 changes: 2 additions & 0 deletions tox/_venv.py
Expand Up @@ -260,6 +260,8 @@ def _installopts(self, indexserver):
if self.envconfig.downloadcache:
self.envconfig.downloadcache.ensure(dir=1)
l.append("--download-cache=%s" % self.envconfig.downloadcache)
if self.envconfig.pip_pre:
l.append("--pre")
return l

def run_install_command(self, packages, options=(),
Expand Down

0 comments on commit 6e4595e

Please sign in to comment.