-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedm_driver.py
114 lines (95 loc) · 3.39 KB
/
edm_driver.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#
# Copyright (c) 2017, Enthought, Inc.
# Copyright (c) 2019-2021 John Wiggins
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
#
import os
import subprocess
import sys
import click
DEPENDENCIES = {
'cython',
'numpy',
}
CONFIG_FILE = os.path.abspath(
os.path.join(os.path.dirname(__file__), '.edm.yaml')
)
@click.group()
def cli():
pass
@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
def install(runtime, environment):
""" Install project and dependencies into a clean EDM environment.
"""
parameters = get_parameters(runtime, environment)
parameters['packages'] = ' '.join(DEPENDENCIES)
# edm commands to setup the development environment
commands = [
"{edm} environments create {environment} --force --version={runtime}",
"{edm} install -y -e {environment} {packages}",
"edm run -e {environment} -- pip install cmake",
"edm run -e {environment} -- pip install -e .",
]
click.echo("Creating environment '{environment}'".format(**parameters))
execute(commands, parameters)
click.echo('Done install')
@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
def test(runtime, environment):
""" Run the test suite in a given environment with the specified toolkit.
"""
parameters = get_parameters(runtime, environment)
environ = {'PYTHONUNBUFFERED': '1'}
commands = [
"edm run -e {environment} -- python -m unittest discover blend2d"
]
click.echo("Running tests in '{environment}'".format(**parameters))
os.environ.update(environ)
execute(commands, parameters)
click.echo('Done test')
@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
def cleanup(runtime, environment):
""" Remove a development environment.
"""
parameters = get_parameters(runtime, environment)
commands = [
"edm run -e {environment} -- python setup.py clean",
"edm environments remove {environment} --purge -y",
]
click.echo("Cleaning up environment '{environment}'".format(**parameters))
execute(commands, parameters)
click.echo('Done cleanup')
# ----------------------------------------------------------------------------
# Utility routines
# ----------------------------------------------------------------------------
def get_parameters(runtime, environment):
""" Set up parameters dictionary for format() substitution """
parameters = {
'runtime': runtime,
'environment': environment,
'edm': 'edm --config {}'.format(CONFIG_FILE),
}
if environment is None:
parameters['environment'] = 'blend2d-{runtime}'.format(**parameters)
return parameters
def execute(commands, parameters):
for command in commands:
click.echo("[EXECUTING]" + command.format(**parameters))
try:
subprocess.check_call(command.format(**parameters).split())
except subprocess.CalledProcessError:
sys.exit(1)
if __name__ == '__main__':
cli()