"Fossies" - the Fresh Open Source Software Archive 
Member "automake-1.16.3/t/python-virtualenv.sh" (19 Nov 2020, 5518 Bytes) of package /linux/misc/automake-1.16.3.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "python-virtualenv.sh":
1.16.2_vs_1.16.3.
1 #! /bin/sh
2 # Copyright (C) 2011-2020 Free Software Foundation, Inc.
3 #
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)
7 # any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 # Check that python support can work well with virtualenvs.
18 # This test also works as a mild stress-test on the python support.
19
20 required='cc python virtualenv'
21 . test-init.sh
22
23 # In case the user's config.site defines pythondir or pyexecdir.
24 CONFIG_SITE=/dev/null; export CONFIG_SITE
25
26 py_version_pre=$($PYTHON -V)
27
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"
31
32 # Activate the virtualenv.
33 . ./virtenv/bin/activate
34 # Sanity check.
35 if test -z "$VIRTUAL_ENV"; then
36 framework_failure_ "can't activate python virtual environment"
37 fi
38
39 py_version_post=$(python -V)
40
41 # Sanity check.
42 test "$py_version_pre" = "$py_version_post" \
43 || skip_ "virtualenv $py_version_post != $py_version_pre"
44
45 cwd=$(pwd) || fatal_ "getting current working directory"
46 py_version=$(python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))')
47 py_site=$VIRTUAL_ENV/lib/python$py_version/site-packages
48
49 # We need to do do this early, just to set some cache variables properly,
50 # since because we're going to unset $PYTHON next.
51 if python_has_pep3147; then
52 : PEP 3147 will be used in installation of ".pyc" files
53 fi
54 # We don't want our original python to be picked up by configure
55 # invocations.
56 unset PYTHON
57
58 # We need control over the package name.
59 cat > configure.ac << END
60 AC_INIT([am_virtenv], [1.0])
61 AM_INIT_AUTOMAKE
62 AC_CONFIG_FILES([Makefile])
63 AC_PROG_CC
64 AM_PROG_AR
65 AC_PROG_RANLIB
66 AM_PATH_PYTHON
67 AC_OUTPUT
68 END
69
70 cat > Makefile.am << 'END'
71 python_PYTHON = am_foo.py
72 pkgpython_PYTHON = __init__.py
73 pyexec_LIBRARIES = libquux.a
74 libquux_a_SOURCES = foo.c
75 pkgpyexec_LIBRARIES = libzardoz.a
76 libzardoz_a_SOURCES = foo.c
77
78 .PYTHON: debug test-run
79 debug:
80 @echo PYTHON: $(PYTHON)
81 @echo PYTHON_VERSION: $(PYTHON_VERSION)
82 @echo prefix: $(prefix)
83 @echo pythondir: $(pythondir)
84 @echo pkgpythondir: $(pkgpythondir)
85 @echo pyexecdir: $(pyexecdir)
86 @echo pkgpyexecdir: $(pkgpyexecdir)
87 test-run:
88 ## In a virtualenv, the default python must be the custom
89 ## virtualenv python.
90 @: \
91 && py1=`python -c 'import sys; print(sys.executable)'` \
92 && py2=`$(PYTHON) -c 'import sys; print(sys.executable)'` \
93 && echo "py1: $$py1" \
94 && echo "py2: $$py2" \
95 && test -n "$$py1" \
96 && test -n "$$py2" \
97 && test x"$$py1" = x"$$py2"
98 ## Check that modules installed in the virtualenv are readily
99 ## available.
100 python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
101 python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
102 all-local: debug
103 END
104
105 cat > am_foo.py << 'END'
106 def foo_func ():
107 return 12345
108 END
109
110 cat > __init__.py << 'END'
111 def old_am ():
112 return 'AutoMake'
113 END
114
115 cat > foo.c << 'END'
116 int foo (void)
117 {
118 return 0;
119 }
120 END
121
122 check_install ()
123 {
124 $MAKE install ${1+"$@"}
125
126 test -f "$py_site"/am_foo.py
127 py_installed "$py_site"/am_foo.pyc
128 py_installed "$py_site"/am_virtenv/__init__.py
129 py_installed "$py_site"/am_virtenv/__init__.pyc
130 test -f "$py_site"/libquux.a
131 test -f "$py_site"/am_virtenv/libzardoz.a
132 }
133
134 check_uninstall ()
135 {
136 $MAKE uninstall ${1+"$@"}
137
138 test ! -e "$py_site"/am_foo.py
139 py_installed --not "$py_site"/am_foo.pyc
140 test ! -e "$py_site"/am_virtenv/__init__.py
141 py_installed --not "$py_site"/am_virtenv/__init__.pyc
142 test ! -e "$py_site"/libquux.a
143 test ! -e "$py_site"/am_virtenv/libzardoz.a
144 }
145
146 $ACLOCAL
147 $AUTOCONF
148 $AUTOMAKE --add-missing
149
150 # Try a VPATH build.
151 mkdir build
152 cd build
153 ../configure --prefix="$VIRTUAL_ENV"
154 check_install
155 $MAKE test-run
156 check_uninstall
157 cd ..
158
159 # Try an in-tree build.
160 ./configure --prefix="$VIRTUAL_ENV"
161 check_install
162 $MAKE test-run
163 check_uninstall
164
165 $MAKE distclean
166
167 # Overriding pythondir and pyexecdir with cache variables should work.
168 ./configure am_cv_python_pythondir="$py_site" \
169 am_cv_python_pyexecdir="$py_site"
170 check_install
171 $MAKE test-run
172 check_uninstall
173
174 $MAKE distclean
175
176 # Overriding pythondir and pyexecdir at make time should be enough.
177 ./configure --prefix="$cwd/bad-prefix"
178 check_install pythondir="$py_site" pyexecdir="$py_site" \
179 AM_MAKEFLAGS="pythondir='$py_site' pyexecdir='$py_site'"
180 test ! -e bad-prefix
181 $MAKE test-run
182 check_uninstall pythondir="$py_site" pyexecdir="$py_site" \
183 AM_MAKEFLAGS="pythondir='$py_site' pyexecdir='$py_site'"
184
185 # Also check that the distribution is self-contained, for completeness.
186 $MAKE distcheck
187
188 # Finally, check that if we disable the virtualenv, we shouldn't be
189 # able to access to the installed modules anymore.
190 cd build
191 $MAKE install
192 python -c 'import am_foo; print(am_foo.__file__)'
193 python -c 'import am_virtenv; print(am_virtenv.__file__)'
194 deactivate "nondestructive"
195 python -c 'import am_foo' && exit 1
196 python -c 'import am_virtenv' && exit 1
197
198 :