| 1 |
#!/usr/bin/env python |
| 2 |
import argparse |
| 3 |
import os |
| 4 |
import shutil |
| 5 |
from contextlib import contextmanager |
| 6 |
from subprocess import check_call |
| 7 |
|
| 8 |
_dname = os.path.dirname |
| 9 |
|
| 10 |
REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__)))) |
| 11 |
|
| 12 |
|
| 13 |
@contextmanager |
| 14 |
def cd(path): |
| 15 |
"""Change directory while inside context manager.""" |
| 16 |
cwd = os.getcwd() |
| 17 |
try: |
| 18 |
os.chdir(path) |
| 19 |
yield |
| 20 |
finally: |
| 21 |
os.chdir(cwd) |
| 22 |
|
| 23 |
|
| 24 |
def run(command): |
| 25 |
return check_call(command, shell=True) |
| 26 |
|
| 27 |
|
| 28 |
if __name__ == "__main__": |
| 29 |
parser = argparse.ArgumentParser() |
| 30 |
group = parser.add_mutually_exclusive_group() |
| 31 |
group.add_argument( |
| 32 |
'-e', |
| 33 |
'--extras', |
| 34 |
help='Install extras_require along with normal install', |
| 35 |
) |
| 36 |
args = parser.parse_args() |
| 37 |
with cd(REPO_ROOT): |
| 38 |
run("pip install -r requirements.txt") |
| 39 |
run('python scripts/ci/install-dev-deps') |
| 40 |
if os.path.isdir('dist') and os.listdir('dist'): |
| 41 |
shutil.rmtree('dist') |
| 42 |
run('python setup.py bdist_wheel') |
| 43 |
wheel_dist = os.listdir('dist')[0] |
| 44 |
package = os.path.join('dist', wheel_dist) |
| 45 |
if args.extras: |
| 46 |
package = f"'{package}[{args.extras}]'" |
| 47 |
run(f'pip install {package}') |