Skip to content

Commit

Permalink
Allow LaMachine to build against a custom Python 3, by setting python…
Browse files Browse the repository at this point in the history
…_bin and pip_bin (building the custom Python is not included in LaMachine) #159
  • Loading branch information
proycon committed Nov 15, 2019
1 parent d26904f commit 6793908
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ if [ $NOSYSUPDATE -ne 0 ]; then
echo "nosysupdate: $NOSYSUPDATE #Skips updating the global packages provided by the distribution" >> $STAGEDCONFIG
fi
if [[ $FLAVOUR == "local" ]] || [[ "$OS" == "mac" ]]; then
echo "python_bin: python3 #The Python interpreter to use to set up the virtual environment, may be an absolute path" >> $STAGEDCONFIG
echo "pip_bin: pip3 #The pip tool belonging to the above interpreter, may be an absolute path" >> $STAGEDCONFIG
echo "web_user: \"$USERNAME\"" >> $STAGEDCONFIG
echo "web_group: \"$GROUP\"" >> $STAGEDCONFIG
else
Expand Down
2 changes: 2 additions & 0 deletions roles/lamachine-core/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ global_prefix: "/usr/local" #where global packages are installed
data_path: "/data"
locality: "global" #Install everything globally
localenv_type: "virtualenv" #Local environment type, can be conda or virtualenv
python_bin: "python3" #path to the global python3 interpreter, may be an absolute path
pip_bin: "pip3" #must correspond to the one belonging to the above python interpreter
webserver: false
webservertype: "nginx"
unix_group: "{{unix_user}}"
Expand Down
14 changes: 8 additions & 6 deletions roles/lamachine-core/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
when: ansible_distribution|lower == "centos" or ansible_distribution|lower == "rhel"

- block:
- name: Obtaining Python version
- name: Obtaining local environment's Python version
shell: python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'
register: python_version
environment: "{{lm_env}}"
Expand All @@ -488,7 +488,9 @@
- name: Obtaining global Python version
shell: |
#!/bin/bash
[[ -f /usr/bin/python3 ]] && /usr/bin/python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'
if which "{{ python_bin }}"; then
{{python_bin}} -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'
fi
args:
executable: /bin/bash
register: global_python_version
Expand Down Expand Up @@ -558,21 +560,21 @@
- name: Upgrade pip #we need at least pip10, this is not always the case in distro-supplied packages
become: "{{lm_become}}"
become_user: root
shell: pip3 install --upgrade pip {% if locality == 'global' %}--prefix "{{ lm_prefix }}"{% endif %}
shell: pip install --upgrade pip {% if locality == 'global' %}--prefix "{{ lm_prefix }}"{% endif %}
environment: "{{lm_env}}"
tags: fullrunonly

- name: "Finding global pip3"
shell: hash -r pip3 && which pip3
shell: hash -r {{pip_bin}} && which {{pip_bin}}
register: pip
environment: "{{lm_env}}"
when: locality == "global"

- name: "Testing global pip3"
shell: |
#!/bin/bash
python3 -c "import pip; print(pip.__path__[0])"
pip3 list
{{python_bin}} -c "import pip; print(pip.__path__[0])"
{{pip_bin}} list
environment: "{{lm_env}}"
args:
executable: /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion roles/lamachine-core/tasks/virtualenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- when: virtualenv.stat.isdir is not defined or not virtualenv.stat.isdir
block:
- name: Creating bare virtualenv environment for LaMachine
shell: "virtualenv --python=python3 {{ local_prefix }}"
shell: "virtualenv --always-copy --python={{ python_bin }} {{ local_prefix }}"

- name: Adapting activation script for virtualenv
blockinfile:
Expand Down

0 comments on commit 6793908

Please sign in to comment.