Merge "Remove virtualenv activation"
This commit is contained in:
commit
2e6a7f949c
@ -12,58 +12,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
import diskimage_builder.paths
|
||||
|
||||
|
||||
# borrowed from pip:locations.py
|
||||
def running_under_virtualenv():
|
||||
"""Return True if we're running inside a virtualenv, False otherwise."""
|
||||
if hasattr(sys, 'real_prefix'):
|
||||
return True
|
||||
elif sys.prefix != getattr(sys, "base_prefix", sys.prefix):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def activate_venv():
|
||||
if running_under_virtualenv():
|
||||
activate_this = os.path.join(sys.prefix, "bin", "activate_this.py")
|
||||
try:
|
||||
globs = runpy.run_path(activate_this, globals())
|
||||
globals().update(globs)
|
||||
del globs
|
||||
# TODO(dtantsur): replace with FileNotFoundError when Python 2 is no
|
||||
# longer supported.
|
||||
except OSError:
|
||||
print("WARNING: A virtual environment was detected, but the "
|
||||
"activate_this.py script was not found. You may need to set "
|
||||
"PATH manually", file=sys.stderr)
|
||||
|
||||
|
||||
def main():
|
||||
# If we are called directly from a venv install
|
||||
# (/path/venv/bin/disk-image-create) then nothing has added the
|
||||
# virtualenv bin/ dir to $PATH. the exec'd script below will be
|
||||
# unable to find call other dib tools like dib-run-parts.
|
||||
#
|
||||
# One solution is to say that you should only ever run
|
||||
# disk-image-create in a shell that has already sourced
|
||||
# bin/activate.sh (all this really does is add /path/venv/bin to
|
||||
# $PATH). That's not a great interface as resulting errors will
|
||||
# be very non-obvious.
|
||||
#
|
||||
# We can detect if we are running in a virtualenv and use
|
||||
# virtualenv's "activate_this.py" script to activate it ourselves
|
||||
# before we call the script. This ensures we have the path setting
|
||||
activate_venv()
|
||||
|
||||
environ = os.environ
|
||||
|
||||
# pre-seed some paths for the shell script
|
||||
@ -74,7 +30,7 @@ def main():
|
||||
os.environ['DIB_PYTHON_EXEC'] = sys.executable
|
||||
|
||||
# we have to handle being called as "disk-image-create" or
|
||||
# "ramdisk-image-create". ramdisk-iamge-create is just a symlink
|
||||
# "ramdisk-image-create". ramdisk-image-create is just a symlink
|
||||
# to disk-image-create
|
||||
# XXX: we could simplify things by removing the symlink, and
|
||||
# just setting IS_RAMDISK in environ here depending on sys.argv[1]
|
||||
|
@ -1,7 +1,7 @@
|
||||
- hosts: all
|
||||
name: Run dib functional tests
|
||||
roles:
|
||||
- ensure-virtualenv
|
||||
- ensure-pip
|
||||
- bindep
|
||||
- dib-setup-gate-mirrors
|
||||
- dib-functests
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
This removes automatic detection and activation of virtualenv
|
||||
environments, which is no longer necessary. This fixes installation
|
||||
under Python 3's inbuilt ``venv`` module.
|
@ -1,5 +1,4 @@
|
||||
---
|
||||
dib_python: python3
|
||||
dib_virtualenv: "{{ ansible_user_dir }}/dib-venv"
|
||||
dib_functests: []
|
||||
# This is a bit of hack; it allows us to template out jobs where the
|
||||
|
@ -25,7 +25,7 @@
|
||||
pip:
|
||||
name: "file://{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
|
||||
virtualenv: "{{ dib_virtualenv }}"
|
||||
virtualenv_python: "{{ dib_python }}"
|
||||
virtualenv_command: "{{ ensure_pip_virtualenv_command }}"
|
||||
extra_args: "-c {{ upper_constraints }}"
|
||||
|
||||
- name: Setup log output
|
||||
|
Loading…
Reference in New Issue
Block a user