Skip to content

Commit e3add92

Browse files
committed
extend this work to Python 2.7 and let user choose between either Python 2 or Python 3
1 parent f19fa78 commit e3add92

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

ansible/roles/aws_polly/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pip:
55
name: "{{ item }}"
66
state: latest
7-
executable: pip3
7+
executable: "{{ pip_version }}"
88
extra_args: --user
99
with_items:
1010
- boto3

ansible/roles/local_load_config/tasks/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@
1010
- name: Overwrite Configuration file from user-specific local configuration file
1111
include_vars: ../config/config.local.yml
1212
when: config_st.stat.exists == True
13+
14+
- name: Assert Python version properly set
15+
assert:
16+
that:
17+
- "python_version == 2 or python_version == 3"
18+
msg: "python_version must be set to either 2 or 3 in config/config.local.yml"
19+
20+
- name: Set variables according to Python version set to {{ python_version }}
21+
set_fact:
22+
pip_version: "{{ 'pip2' if python_version == 2 else 'pip3' }}"
23+
python_name: "{{ 'python' if python_version == 2 else 'python3' }}"

ansible/roles/opencv/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
-D WITH_OPENGL=ON
125125
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
126126
-D WITH_IPP=ON
127-
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3)
127+
-D PYTHON_DEFAULT_EXECUTABLE=$(which {{ python_name }})
128128
-D INSTALL_PYTHON_EXAMPLES=ON
129129
-D BUILD_PERF_TESTS=OFF
130130
-D BUILD_TESTS=OFF

ansible/roles/tensorflow/tasks/main.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
become: yes
66

77
- name: Install common packages (mostly python and pip)
8-
apt: name={{item}} state=latest
8+
apt: name={{ item }} state=latest
99
with_items:
1010
- aptitude
1111
- colordiff
@@ -14,9 +14,9 @@
1414
- python3-dev
1515
- python-pip
1616
- python3-pip
17-
- python3-numpy
18-
- python3-wheel
19-
- python3-tk
17+
- "{{ python_name }}-numpy"
18+
- "{{ python_name }}-wheel"
19+
- "{{ python_name }}-tk"
2020
- unzip
2121
- debconf
2222
- debconf-utils
@@ -36,19 +36,19 @@
3636
- include_tasks: tf_gpu_req.yml
3737
when: tf_enable_gpu
3838

39-
- name: Install latest tensorflow with native pip3 (no GPU support)
39+
- name: Install latest tensorflow with native {{ pip_version }} package (no GPU support)
4040
pip:
4141
name: tensorflow
4242
state: latest
43-
executable: pip3
43+
executable: "{{ pip_version }}"
4444
become: yes
4545
when: not tf_build_from_source and not tf_enable_gpu
4646

47-
- name: Install latest tensorflow with native pip3 (with GPU support)
47+
- name: Install latest tensorflow with native {{ pip_version }} package (with GPU support)
4848
pip:
4949
name: tensorflow-gpu
5050
state: latest
51-
executable: pip3
51+
executable: "{{ pip_version }}"
5252
become: yes
5353
when: not tf_build_from_source and tf_enable_gpu
5454

ansible/roles/tf_object_detection/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
- protobuf-compiler
1111
become: yes
1212

13-
- name: Install dependencies through pip
13+
- name: Install dependencies through {{ pip_version }}
1414
pip:
1515
name: "{{ item }}"
1616
state: latest
17-
executable: pip3
17+
executable: "{{ pip_version }}"
1818
with_items:
1919
- pillow
2020
- lxml
@@ -32,7 +32,7 @@
3232
- name: Install xlib required for screen capturing
3333
apt: name={{ item }} state=latest
3434
with_items:
35-
- python3-xlib
35+
- "{{ python_name }}-xlib"
3636
- libx11-dev
3737
become: yes
3838

config/config.local.sample.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## ATTENTION: Do not modify 'config.local.sample.yml' !! You should create a copy named 'config.local.yml' and modify that one !!
44

55

6-
## Tensorflow
6+
## TensorFlow
77

88
tf_enable_gpu: false
99

@@ -15,6 +15,7 @@ tf_models_repo_name: tensorflow_models
1515
tf_models_repo_url: tensorflow/models
1616
tf_models_repo_branch: master
1717

18+
1819
## OpenCV
1920

2021
opencv_version: 3.3.1
@@ -23,3 +24,10 @@ opencv_contrib_repo_branch: 3.3.1
2324
opencv_extra_repo_branch: 3.3.1
2425
opencv_build_examples: OFF
2526
opencv_force_rebuild: false
27+
28+
29+
## Python
30+
31+
# put either 2 for Python 2.7 or 3 for Python 3.5
32+
# Note: When switching between versions, force rebuild of OpenCV and TensorFlow once (i.e., set opencv_force_rebuild to true)
33+
python_version: 3

stuff/__init__.py

Whitespace-only changes.

stuff/speech_synthesis.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from contextlib import closing
99
import os
1010
import sys
11-
from contextlib import suppress
1211
from threading import Thread
13-
from queue import LifoQueue, Empty
12+
if sys.version_info.major < 3:
13+
from Queue import LifoQueue, Empty
14+
else:
15+
from queue import LifoQueue, Empty
1416
from time import sleep
1517
from tempfile import gettempdir
1618

@@ -30,8 +32,11 @@ def __init__(self):
3032

3133
def request(self, text):
3234
"""Clear queue (ignore it being empty) and add text, both non-blocking"""
33-
with suppress(Empty):
35+
# for Python 3.4+ this could be written as: with suppress(Empty): ... assuming: from contextlib import suppress
36+
try:
3437
self._speak_queue.get_nowait()
38+
except Empty:
39+
pass
3540
self._speak_queue.put_nowait(text)
3641

3742
def run(self):

0 commit comments

Comments
 (0)