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 # Skip the test if a proper virtualenv cannot be created.
27 virtualenv --verbose virtenv && test -f virtenv/bin/activate \
28 || skip_ "coulnd't create python virtual environment"
30 # Activate the virtualenv.
31 . ./virtenv/bin/activate
33 if test -z "$VIRTUAL_ENV"; then
34 framework_failure_ "can't activate python virtual environment"
37 cwd=$(pwd) || fatal_ "getting current working directory"
38 py_version=$(python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))')
39 py_site=$VIRTUAL_ENV/lib/python$py_version/site-packages
41 # We need control over the package name.
42 cat > configure.ac << END
43 AC_INIT([am_virtenv], [1.0])
45 AC_CONFIG_FILES([Makefile])
46 AC_SUBST([MY_VIRTENV], ['$cwd/virtenv'])
54 cat > Makefile.am << 'END'
55 python_PYTHON = am_foo.py
56 pkgpython_PYTHON = __init__.py
57 pyexec_LIBRARIES = libquux.a
58 libquux_a_SOURCES = foo.c
59 pkgpyexec_LIBRARIES = libzardoz.a
60 libzardoz_a_SOURCES = foo.c
62 py_site = $(MY_VIRTENV)/lib/python$(PYTHON_VERSION)/site-packages
64 .PYTHON: debug test-run test-install test-uninstall
66 @echo PYTHON: $(PYTHON)
67 @echo PYTHON_VERSION: $(PYTHON_VERSION)
68 @echo prefix: $(prefix)
69 @echo pythondir: $(pythondir)
70 @echo pkgpythondir: $(pkgpythondir)
71 @echo pyexecdir: $(pyexecdir)
72 @echo pkgpyexecdir: $(pkgpyexecdir)
74 ## In a virtualenv, the default python must be the custom
77 && py1=`python -c 'import sys; print(sys.executable)'` \
78 && py2=`$(PYTHON) -c 'import sys; print(sys.executable)'` \
79 && echo "py1: $$py1" \
80 && echo "py2: $$py2" \
83 && test x"$$py1" = x"$$py2"
84 ## Check that modules installed in the virtualenv are readily
86 python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
87 python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
89 test -f $(py_site)/am_foo.py
90 test -f $(py_site)/am_foo.pyc
91 test -f $(py_site)/am_foo.pyo
92 test -f $(py_site)/am_virtenv/__init__.py
93 test -f $(py_site)/am_virtenv/__init__.pyc
94 test -f $(py_site)/am_virtenv/__init__.pyo
95 test -f $(py_site)/libquux.a
96 test -f $(py_site)/am_virtenv/libzardoz.a
98 test ! -f $(py_site)/am_foo.py
99 test ! -f $(py_site)/am_foo.pyc
100 test ! -f $(py_site)/am_foo.pyo
101 test ! -f $(py_site)/am_virtenv/__init__.py
102 test ! -f $(py_site)/am_virtenv/__init__.pyc
103 test ! -f $(py_site)/am_virtenv/__init__.pyo
104 test ! -f $(py_site)/libquux.a
105 test ! -f $(py_site)/am_virtenv/libzardoz.a
109 cat > am_foo.py << 'END'
114 cat > __init__.py << 'END'
128 $AUTOMAKE --add-missing
133 ../configure --prefix="$VIRTUAL_ENV"
141 # Try an in-tree build.
142 ./configure --prefix="$VIRTUAL_ENV"
151 # Overriding pythondir and pyexecdir with cache variables should work.
152 ./configure am_cv_python_pythondir="$py_site" \
153 am_cv_python_pyexecdir="$py_site"
162 # Overriding pythondir and pyexecdir at make time should be enough.
163 ./configure --prefix="$cwd/bad-prefix"
164 pythondir=$py_site pyexecdir=$py_site
165 export pythondir pyexecdir
168 $MAKE -e test-install
171 $MAKE -e test-uninstall
172 unset pythondir pyexecdir
174 # Also check that the distribution is self-contained, for completeness.
177 # Finally, check that if we disable the virtualenv, we shouldn't be
178 # able to access to the installed modules anymore.
181 python -c 'import am_foo; print(am_foo.__file__)'
182 python -c 'import am_virtenv; print(am_virtenv.__file__)'
183 deactivate "nondestructive"
184 python -c 'import am_foo' && exit 1
185 python -c 'import am_virtenv' && exit 1