blob: 11055b0b388dae667fa17f24cf69072c0fab92c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
#! /bin/sh
# Copyright (C) 2011 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Check that python support can work well with virtualenvs.
# This test also works as a mild stress-test on the python support.
required='python virtualenv'
. ./defs || Exit 1
# In case the user's config.site defines pythondir or pyexecdir.
CONFIG_SITE=/dev/null; export CONFIG_SITE
# Skip the test if a proper virtualenv cannot be created.
virtualenv --verbose virtenv || Exit 77
test -f virtenv/bin/activate || Exit 77
# Activate the virtualenv.
. ./virtenv/bin/activate
# Sanity check.
test -n "$VIRTUAL_ENV" || Exit 99
cwd=`pwd`
py_version=`python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))'`
py_site=$VIRTUAL_ENV/lib/python$py_version/site-packages
# We need control over the package name.
cat > configure.in << END
AC_INIT([am_virtenv], [1.0])
AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
AC_SUBST([MY_VIRTENV], ['$cwd/virtenv'])
AC_PROG_CC
AC_PROG_RANLIB
AM_PATH_PYTHON
AC_OUTPUT
END
cat > Makefile.am << 'END'
python_PYTHON = am_foo.py
pkgpython_PYTHON = __init__.py
pyexec_LIBRARIES = libquux.a
libquux_a_SOURCES = foo.c
pkgpyexec_LIBRARIES = libzardoz.a
libzardoz_a_SOURCES = foo.c
py_site = $(MY_VIRTENV)/lib/python$(PYTHON_VERSION)/site-packages
.PYTHON: debug test-run test-install test-uninstall
debug:
@echo PYTHON: $(PYTHON)
@echo PYTHON_VERSION: $(PYTHON_VERSION)
@echo prefix: $(prefix)
@echo pythondir: $(pythondir)
@echo pkgpythondir: $(pkgpythondir)
@echo pyexecdir: $(pyexecdir)
@echo pkgpyexecdir: $(pkgpyexecdir)
test-run:
## In a virtualenv, the default python must be the custom
## virtualenv python.
@: \
&& py1=`python -c 'import sys; print(sys.executable)'` \
&& py2=`$(PYTHON) -c 'import sys; print(sys.executable)'` \
&& echo "py1: $$py1" \
&& echo "py2: $$py2" \
&& test -n "$$py1" \
&& test -n "$$py2" \
&& test x"$$py1" = x"$$py2"
## Check that modules installed in the virtualenv are readily
## available.
python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
test-install:
test -f $(py_site)/am_foo.py
test -f $(py_site)/am_foo.pyc
test -f $(py_site)/am_foo.pyo
test -f $(py_site)/am_virtenv/__init__.py
test -f $(py_site)/am_virtenv/__init__.pyc
test -f $(py_site)/am_virtenv/__init__.pyo
test -f $(py_site)/libquux.a
test -f $(py_site)/am_virtenv/libzardoz.a
test-uninstall:
test ! -f $(py_site)/am_foo.py
test ! -f $(py_site)/am_foo.pyc
test ! -f $(py_site)/am_foo.pyo
test ! -f $(py_site)/am_virtenv/__init__.py
test ! -f $(py_site)/am_virtenv/__init__.pyc
test ! -f $(py_site)/am_virtenv/__init__.pyo
test ! -f $(py_site)/libquux.a
test ! -f $(py_site)/am_virtenv/libzardoz.a
all-local: debug
END
cat > am_foo.py << 'END'
def foo_func ():
return 12345
END
cat > __init__.py << 'END'
def old_am ():
return 'AutoMake'
END
cat > foo.c << 'END'
int foo (void)
{
return 0;
}
END
$ACLOCAL
$AUTOCONF
$AUTOMAKE --add-missing
# Try a VPATH build.
mkdir build
cd build
../configure --prefix="$VIRTUAL_ENV"
$MAKE install
$MAKE test-install
$MAKE test-run
$MAKE uninstall
$MAKE test-uninstall
cd ..
# Try an in-tree build.
./configure --prefix="$VIRTUAL_ENV"
$MAKE install
$MAKE test-install
$MAKE test-run
$MAKE uninstall
$MAKE test-uninstall
$MAKE distclean
# Overriding pythondir and pyexecdir with cache variables should work.
./configure am_cv_python_pythondir="$py_site" \
am_cv_python_pyexecdir="$py_site"
$MAKE install
$MAKE test-install
$MAKE test-run
$MAKE uninstall
$MAKE test-uninstall
$MAKE distclean
# Overriding pythondir and pyexecdir at make time should be enough.
./configure --prefix="$cwd/bad-prefix"
pythondir=$py_site pyexecdir=$py_site
export pythondir pyexecdir
$MAKE -e install
test ! -d bad-prefix
$MAKE -e test-install
$MAKE test-run
$MAKE -e uninstall
$MAKE -e test-uninstall
unset pythondir pyexecdir
# Also check that the distribution is self-contained, for completeness.
$MAKE distcheck
# Finally, check that if we disable the virtualenv, we shouldn't be
# able to access to the installed modules anymore.
cd build
$MAKE install
python -c 'import am_foo; print(am_foo.__file__)'
python -c 'import am_virtenv; print(am_virtenv.__file__)'
deactivate "nondestructive"
python -c 'import am_foo' && Exit 1
python -c 'import am_virtenv' && Exit 1
:
|