summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel <g2p.code@gmail.com>2012-11-30 18:45:16 +0100
committerGabriel <g2p.code@gmail.com>2012-11-30 18:45:16 +0100
commit9ab2c784843f2764ee7b7fd19c496991beaa1332 (patch)
tree049ad2476d17dfd5a7b6a50895bb9835bbd70d55
parent352bdda1afb6d326b0e417a8ce40f012fe76cbec (diff)
downloadtox-9ab2c784843f2764ee7b7fd19c496991beaa1332.tar.gz
Add {envsitepackagesdir} substitution. Closes #72.
-rwxr-xr-xCHANGELOG2
-rw-r--r--doc/config.txt3
-rw-r--r--tests/test_z_cmdline.py8
-rw-r--r--tox/_config.py52
-rw-r--r--tox/_venv.py17
5 files changed, 65 insertions, 17 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 16f3431..278876e 100755
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
1.4.3.dev
-----------------
+- substitute {envsitepackagesdir} with the package installation directory (closes #72)
+
- issue #70 remove PYTHONDONTWRITEBYTECODE workaround now that
virtualenv behaves properly (thanks g2p)
diff --git a/doc/config.txt b/doc/config.txt
index 8cdcfcd..8829d1b 100644
--- a/doc/config.txt
+++ b/doc/config.txt
@@ -199,6 +199,9 @@ substitutions for virtualenv-related sections
directory of the virtualenv hierarchy
``{envbindir}``
directory where executables are located
+``{envsitepackagesdir}``
+ directory where packages are installed.
+ Note that architecture-specific files may appear in a different directory.
``{envtmpdir}``
the environment temporary directory
``{envlogdir}``
diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py
index 1b397c7..fcded04 100644
--- a/tests/test_z_cmdline.py
+++ b/tests/test_z_cmdline.py
@@ -438,3 +438,11 @@ def test_sdist_latest(tmpdir, newconfig):
session = Session(config)
sdist_path = session.sdist()
assert sdist_path == p
+
+def test_envsitepackagesdir(cmd, initproj):
+ initproj("pkg512-0.0.5", filedefs={
+ 'tox.ini': """
+ commands=
+ grep '__version__.*=.*0\.0\.5' {envsitepackagesdir}/pkg512/__init__.py
+ """})
+ result = cmd.run("tox")
diff --git a/tox/_config.py b/tox/_config.py
index e02e25e..7a9a090 100644
--- a/tox/_config.py
+++ b/tox/_config.py
@@ -1,9 +1,12 @@
import argparse
+import distutils.sysconfig
import os
import sys
import re
import shlex
import string
+import subprocess
+import textwrap
import py
@@ -34,7 +37,12 @@ def parseconfig(args=None, pkg=None):
break
else:
feedback("toxini file %r not found" %(basename), sysexit=True)
- parseini(config, inipath)
+ try:
+ parseini(config, inipath)
+ except tox.exception.InterpreterNotFound:
+ exn = sys.exc_info()[1]
+ # Use stdout to match test expectations
+ py.builtin.print_("ERROR: " + str(exn))
return config
def feedback(msg, sysexit=False):
@@ -114,6 +122,45 @@ class VenvConfig:
name = "python"
return self.envbindir.join(name)
+ @property
+ def envsitepackagesdir(self):
+ print_envsitepackagesdir = textwrap.dedent("""
+ import sys
+ from distutils.sysconfig import get_python_lib
+ sys.stdout.write(get_python_lib(prefix=sys.argv[1]))
+ """)
+
+ exe = self.getsupportedinterpreter()
+ # can't use check_output until py27
+ proc = subprocess.Popen(
+ [str(exe), '-c', print_envsitepackagesdir, str(self.envdir)],
+ stdout=subprocess.PIPE)
+ odata, edata = proc.communicate()
+ if proc.returncode:
+ raise tox.exception.UnsupportedInterpreter(
+ "Error getting site-packages from %s" % self.basepython)
+ return odata
+
+ def getconfigexecutable(self):
+ from tox._venv import find_executable
+
+ python = self.basepython
+ if not python:
+ python = sys.executable
+ x = find_executable(str(python))
+ if x:
+ x = x.realpath()
+ return x
+
+ def getsupportedinterpreter(self):
+ if sys.platform == "win32" and self.basepython and \
+ "jython" in self.basepython:
+ raise tox.exception.UnsupportedInterpreter(
+ "Jython/Windows does not support installing scripts")
+ config_executable = self.getconfigexecutable()
+ if not config_executable:
+ raise tox.exception.InterpreterNotFound(self.basepython)
+ return config_executable
testenvprefix = "testenv:"
class parseini:
@@ -205,7 +252,8 @@ class parseini:
bp = sys.executable
vc.basepython = reader.getdefault(section, "basepython", bp)
reader.addsubstitions(envdir=vc.envdir, envname=vc.envname,
- envbindir=vc.envbindir, envpython=vc.envpython)
+ envbindir=vc.envbindir, envpython=vc.envpython,
+ envsitepackagesdir=vc.envsitepackagesdir)
vc.envtmpdir = reader.getpath(section, "tmpdir", "{envdir}/tmp")
vc.envlogdir = reader.getpath(section, "envlogdir", "{envdir}/log")
reader.addsubstitions(envlogdir=vc.envlogdir, envtmpdir=vc.envtmpdir)
diff --git a/tox/_venv.py b/tox/_venv.py
index 40047f3..2faa087 100644
--- a/tox/_venv.py
+++ b/tox/_venv.py
@@ -146,23 +146,10 @@ class VirtualEnv(object):
return l
def getconfigexecutable(self):
- python = self.envconfig.basepython
- if not python:
- python = sys.executable
- x = find_executable(str(python))
- if x:
- x = x.realpath()
- return x
+ return self.envconfig.getconfigexecutable()
def getsupportedinterpreter(self):
- if sys.platform == "win32" and self.envconfig.basepython and \
- "jython" in self.envconfig.basepython:
- raise tox.exception.UnsupportedInterpreter(
- "Jython/Windows does not support installing scripts")
- config_executable = self.getconfigexecutable()
- if not config_executable:
- raise tox.exception.InterpreterNotFound(self.envconfig.basepython)
- return config_executable
+ return self.envconfig.getsupportedinterpreter()
def create(self, action=None):
#if self.getcommandpath("activate").dirpath().check():