pip: combine chdir and env only when env is set (#40793)

* pip: combine chdir and env only when env is set

This fixes an AttributeError when chdir without virtualenv is specified:

 File "/tmp/ansible_2UAFsZ/ansible_module_pip.py", line 387, in main
    env = os.path.join(chdir, env)
 File "/usr/lib64/python2.7/posixpath.py", line 75, in join
    if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

* Add test for pip with chdir

Signed-off-by: Till Maas <opensource@till.name>
pull/44089/merge
Till Maas 6 years ago committed by René Moser
parent fd4e774cec
commit bb85bbceeb

@ -457,7 +457,7 @@ def main():
env = module.params['virtualenv'] env = module.params['virtualenv']
venv_created = False venv_created = False
if chdir: if env and chdir:
env = os.path.join(chdir, env) env = os.path.join(chdir, env)
if umask and not isinstance(umask, int): if umask and not isinstance(umask, int):

@ -0,0 +1,14 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
name="ansible_test_pip_chdir",
version="0",
packages=find_packages(),
entry_points={
'console_scripts': [
'ansible_test_pip_chdir = ansible_test_pip_chdir:main'
]
}
)

@ -230,6 +230,48 @@
that: that:
- "pip_install_venv is changed" - "pip_install_venv is changed"
# https://github.com/ansible/ansible/issues/37912
# support chdir without virtualenv
- name: create chdir test directories
file:
state: directory
name: "{{ output_dir }}/{{ item }}"
loop:
- pip_module
- pip_root
- pip_module/ansible_test_pip_chdir
- name: copy test module
copy:
src: "{{ item }}"
dest: "{{ output_dir }}/pip_module/{{ item }}"
loop:
- setup.py
- ansible_test_pip_chdir/__init__.py
- name: install test module
pip:
name: .
chdir: "{{ output_dir }}/pip_module"
extra_args: --user --upgrade --root {{ output_dir }}/pip_root
- name: register python_site_lib
command: 'python -c "import site; print(site.USER_SITE)"'
register: pip_python_site_lib
- name: register python_user_base
command: 'python -c "import site; print(site.USER_BASE)"'
register: pip_python_user_base
- name: run test module
shell: "PYTHONPATH=$(echo {{ output_dir }}/pip_root{{ pip_python_site_lib.stdout }}) {{ output_dir }}/pip_root{{ pip_python_user_base.stdout }}/bin/ansible_test_pip_chdir"
register: pip_chdir_command
- name: make sure command ran
assert:
that:
- pip_chdir_command.stdout == "success"
# https://github.com/ansible/ansible/issues/25122 # https://github.com/ansible/ansible/issues/25122
- name: ensure is a fresh virtualenv - name: ensure is a fresh virtualenv
file: file:

Loading…
Cancel
Save