Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 44a35c0

Browse files
jayvdbryanhiebert
authored andcommitted
Support PyPy3 v5.2 with setuptools hackery (#24)
PyPy has started releasing alpha releases of PyPy3 v5.2, and Travis now supports `python: pypy3.3-5.2-alpha1`. PyPy3 v5.2 depends on virtualenv>=15.0.2, whereas Travis installs 12.0.6. Only force the use of virtualenv>=15.0.2 on PyPy3 v5.2, so that existing users of tox-travis are not impacted. This is complicated by Travis providing setuptools 12.0.5, which does not support `platform_python_implementation=="PyPy"` as an environment marker. Prior to setuptools 20.10.0 there is patchy support for environment markers, and setup.py fails while parsing them. To avoid breakage if someone is installing tox-travis using an older setuptools, setup.py patches _markerlib and pkg_resources so they perform correct environment marker matching. However the typical Travis-CI usage is via `pip install tox-travis`. tox-travis provides a universal wheel, which supports environment markers, Travis pip 6.0.7 can install this universal wheel without using setuptools. Also, fiddle with tox internals so that it attempts to run `python` for the Travis versions `pypy3.3-5.2-*`.
1 parent 37ae5e2 commit 44a35c0

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

.travis.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ python:
88
- "3.4"
99
- "3.5"
1010
- "pypy"
11+
- "pypy3"
12+
- "pypy3.3-5.2-alpha1"
1113
- "nightly"
12-
install: pip install .
13-
script: tox
14-
branches:
15-
only:
16-
- master
17-
matrix:
18-
fast_finish: true
14+
15+
before_install:
16+
# Show the current setuptools version
17+
- ORIG_SETUPTOOLS_VERSION=`python -c "import setuptools; print('%s' % setuptools.__version__)"`
18+
- echo setuptools $ORIG_SETUPTOOLS_VERSION
19+
install:
20+
- pip install wheel
21+
- python setup.py install bdist_wheel
22+
- pip install ./dist/tox_travis-*.whl
23+
script:
24+
- tox
25+
- tox --installpkg ./dist/tox_travis-*.whl

setup.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
1-
from setuptools import setup
1+
import sys
2+
3+
from setuptools import setup, __version__ as setuptools_version
4+
from pkg_resources import parse_version
5+
6+
import pkg_resources
7+
8+
try:
9+
import _markerlib.markers
10+
except ImportError:
11+
_markerlib = None
12+
13+
14+
# _markerlib.default_environment() obtains its data from _VARS
15+
# and wraps it in another dict, but _markerlib_evaluate writes
16+
# to the dict while it is iterating the keys, causing an error
17+
# on Python 3 only.
18+
# Replace _markerlib.default_environment to return a custom dict
19+
# that has all the necessary markers, and ignores any writes.
20+
21+
class Python3MarkerDict(dict):
22+
23+
def __setitem__(self, key, value):
24+
pass
25+
26+
def pop(self, i=-1):
27+
return self[i]
28+
29+
30+
if _markerlib and sys.version_info[0] == 3:
31+
env = _markerlib.markers._VARS
32+
for key in list(env.keys()):
33+
new_key = key.replace('.', '_')
34+
if new_key != key:
35+
env[new_key] = env[key]
36+
37+
_markerlib.markers._VARS = Python3MarkerDict(env)
38+
39+
def default_environment():
40+
return _markerlib.markers._VARS
41+
42+
_markerlib.default_environment = default_environment
43+
44+
# Avoid the very buggy pkg_resources.parser, which doesnt consistently
45+
# recognise the markers needed by this setup.py
46+
# Change this to setuptools 20.10.0 to support all markers.
47+
if pkg_resources:
48+
if parse_version(setuptools_version) < parse_version('20.10.0'):
49+
MarkerEvaluation = pkg_resources.MarkerEvaluation
50+
51+
del pkg_resources.parser
52+
pkg_resources.evaluate_marker = MarkerEvaluation._markerlib_evaluate
53+
MarkerEvaluation.evaluate_marker = MarkerEvaluation._markerlib_evaluate
254

355

456
def fread(fn):
@@ -21,6 +73,7 @@ def fread(fn):
2173
install_requires=['tox>=2.0'],
2274
extras_require={
2375
':python_version=="3.2"': ['virtualenv<14'],
76+
':platform_python_implementation=="PyPy" and python_version=="3.3"': ['virtualenv>=15.0.2'],
2477
},
2578
classifiers=[
2679
'Programming Language :: Python',

src/tox_travis.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import tox
66

77
from tox.config import _split_env as split_env
8+
try:
9+
from tox.config import default_factors
10+
except ImportError:
11+
default_factors = None
812

913

1014
@tox.hookimpl
@@ -24,6 +28,14 @@ def tox_addoption(parser):
2428
matched = match_envs(declared_envs, desired_envs)
2529
os.environ.setdefault('TOXENV', ','.join(matched))
2630

31+
# Travis virtualenv do not provide `pypy3`, which tox tries to execute.
32+
# This doesnt affect Travis python version `pypy3`, as the pyenv pypy3
33+
# is in the PATH.
34+
# https://github.com/travis-ci/travis-ci/issues/6304
35+
# Force use of the virtualenv `python`.
36+
if version and default_factors and version.startswith('pypy3.3-5.2-'):
37+
default_factors['pypy3'] = 'python'
38+
2739

2840
def get_declared_envs(config):
2941
"""Get the full list of envs from the tox config.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26, py27, py32, py33, py34, pypy
2+
envlist = py26, py27, py32, py33, py34, pypy, pypy3
33

44
[testenv]
55
deps =

0 commit comments

Comments
 (0)