2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Check that python support can work well with virtualenvs.
18 # This test also works as a mild stress-test on the python support.
20 required='cc python virtualenv'
23 # In case the user's config.site defines pythondir or pyexecdir.
24 CONFIG_SITE=/dev/null; export CONFIG_SITE
26 py_version_pre=$($PYTHON -V)
28 # Skip the test if a proper virtualenv cannot be created.
29 virtualenv -p"$PYTHON" --verbose virtenv && py_installed virtenv/bin/activate \
30 || skip_ "couldn't create python virtual environment"
32 # Activate the virtualenv.
33 . ./virtenv/bin/activate
35 if test -z "$VIRTUAL_ENV"; then
36 framework_failure_ "can't activate python virtual environment"
39 py_version_post=$(python -V)
42 test "$py_version_pre" = "$py_version_post"
44 cwd=$(pwd) || fatal_ "getting current working directory"
45 py_version=$(python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))')
46 py_site=$VIRTUAL_ENV/lib/python$py_version/site-packages
48 # We need to do do this early, just to set some cache variables properly,
49 # since because we're going to unset $PYTHON next.
50 if python_has_pep3147; then
51 : PEP 3147 will be used in installation of ".pyc" files
53 # We don't want our original python to be picked up by configure
57 # We need control over the package name.
58 cat > configure.ac << END
59 AC_INIT([am_virtenv], [1.0])
61 AC_CONFIG_FILES([Makefile])
69 cat > Makefile.am << 'END'
70 python_PYTHON = am_foo.py
71 pkgpython_PYTHON = __init__.py
72 pyexec_LIBRARIES = libquux.a
73 libquux_a_SOURCES = foo.c
74 pkgpyexec_LIBRARIES = libzardoz.a
75 libzardoz_a_SOURCES = foo.c
77 .PYTHON: debug test-run
79 @echo PYTHON: $(PYTHON)
80 @echo PYTHON_VERSION: $(PYTHON_VERSION)
81 @echo prefix: $(prefix)
82 @echo pythondir: $(pythondir)
83 @echo pkgpythondir: $(pkgpythondir)
84 @echo pyexecdir: $(pyexecdir)
85 @echo pkgpyexecdir: $(pkgpyexecdir)
87 ## In a virtualenv, the default python must be the custom
90 && py1=`python -c 'import sys; print(sys.executable)'` \
91 && py2=`$(PYTHON) -c 'import sys; print(sys.executable)'` \
92 && echo "py1: $$py1" \
93 && echo "py2: $$py2" \
96 && test x"$$py1" = x"$$py2"
97 ## Check that modules installed in the virtualenv are readily
99 python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
100 python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
104 cat > am_foo.py << 'END'
109 cat > __init__.py << 'END'
123 $MAKE install ${1+"$@"}
125 test -f "$py_site"/am_foo.py
126 py_installed "$py_site"/am_foo.pyc
127 py_installed "$py_site"/am_foo.pyo
128 py_installed "$py_site"/am_virtenv/__init__.py
129 py_installed "$py_site"/am_virtenv/__init__.pyc
130 py_installed "$py_site"/am_virtenv/__init__.pyo
131 test -f "$py_site"/libquux.a
132 test -f "$py_site"/am_virtenv/libzardoz.a
137 $MAKE uninstall ${1+"$@"}
139 test ! -e "$py_site"/am_foo.py
140 py_installed --not "$py_site"/am_foo.pyc
141 py_installed --not "$py_site"/am_foo.pyo
142 test ! -e "$py_site"/am_virtenv/__init__.py
143 py_installed --not "$py_site"/am_virtenv/__init__.pyc
144 py_installed --not "$py_site"/am_virtenv/__init__.pyo
145 test ! -e "$py_site"/libquux.a
146 test ! -e "$py_site"/am_virtenv/libzardoz.a
151 $AUTOMAKE --add-missing
156 ../configure --prefix="$VIRTUAL_ENV"
162 # Try an in-tree build.
163 ./configure --prefix="$VIRTUAL_ENV"
170 # Overriding pythondir and pyexecdir with cache variables should work.
171 ./configure am_cv_python_pythondir="$py_site" \
172 am_cv_python_pyexecdir="$py_site"
179 # Overriding pythondir and pyexecdir at make time should be enough.
180 ./configure --prefix="$cwd/bad-prefix"
181 pythondir=$py_site pyexecdir=$py_site
182 export pythondir pyexecdir
187 unset pythondir pyexecdir
189 # Also check that the distribution is self-contained, for completeness.
192 # Finally, check that if we disable the virtualenv, we shouldn't be
193 # able to access to the installed modules anymore.
196 python -c 'import am_foo; print(am_foo.__file__)'
197 python -c 'import am_virtenv; print(am_virtenv.__file__)'
198 deactivate "nondestructive"
199 python -c 'import am_foo' && exit 1
200 python -c 'import am_virtenv' && exit 1