-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_venv.py
79 lines (58 loc) · 2.69 KB
/
test_venv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright (c) 2012-2024 Esri R&D Center Zurich
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A copy of the license is available in the repository's LICENSE file.
import os
import sys
import tempfile
import platform
import venv
import argparse
def get_python_cmd(venv_dir):
bin_segment = "Scripts" if platform.system() == "Windows" else "bin"
py_cmd = os.path.join(venv_dir, bin_segment, 'python')
return py_cmd
def setup_venv_from_requirements(venv_dir, env_py):
venv.create(venv_dir, with_pip=True)
py_cmd = get_python_cmd(venv_dir)
os.system(f"{py_cmd} -m pip install --upgrade pip")
os.system(f"{py_cmd} -m pip install --upgrade wheel")
env_os = "windows" if platform.system() == "Windows" else "linux"
os.system(f"{py_cmd} -m pip install -r envs/{env_os}/requirements-{env_py}.txt")
def add_custom_pyprt_wheel(venv_dir, pyprt_wheel_path):
py_cmd = get_python_cmd(venv_dir)
os.system(f"{py_cmd} -m pip install --trusted-host zrh-code.esri.com --upgrade {pyprt_wheel_path}")
def run_examples(venv_dir):
py_cmd = get_python_cmd(venv_dir)
os.system(f'{py_cmd} -c "import pyprt; print(pyprt.get_api_version())"')
os.system(f"{py_cmd} ex1_python_encoder.py")
os.system(f"{py_cmd} ex2_obj_initial_shape.py")
os.system(f"{py_cmd} ex3_format_exporter.py")
os.system(f"{py_cmd} ex4_multi_generations.py")
def main():
env_py = f"py{sys.version_info[0]}{sys.version_info[1]}"
parser = argparse.ArgumentParser(description='PyPRT venv tests for examples')
parser.add_argument(
'--pyprt_wheel', help='custom pyprt build to use in venv test', type=str, required=False)
parser.add_argument('--venv_path', help='use specific venv location and keep it around', type=str, required=False)
args = parser.parse_args()
venv_temp_dir = None
venv_dir = None
if args.venv_path:
venv_dir = args.venv_path
else:
venv_temp_dir = tempfile.TemporaryDirectory(prefix=f'pyprt-venv-test-py{env_py}')
venv_dir = venv_temp_dir.name
setup_venv_from_requirements(venv_dir, env_py)
if args.pyprt_wheel:
add_custom_pyprt_wheel(venv_dir, args.pyprt_wheel)
run_examples(venv_dir)
if __name__ == '__main__':
main()