install 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. _dname = os.path.dirname
  8. REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
  9. @contextmanager
  10. def cd(path):
  11. """Change directory while inside context manager."""
  12. cwd = os.getcwd()
  13. try:
  14. os.chdir(path)
  15. yield
  16. finally:
  17. os.chdir(cwd)
  18. def run(command):
  19. return check_call(command, shell=True)
  20. if __name__ == "__main__":
  21. parser = argparse.ArgumentParser()
  22. group = parser.add_mutually_exclusive_group()
  23. group.add_argument(
  24. '-e',
  25. '--extras',
  26. help='Install extras_require along with normal install',
  27. )
  28. args = parser.parse_args()
  29. with cd(REPO_ROOT):
  30. run("pip install -r requirements.txt")
  31. run('python scripts/ci/install-dev-deps')
  32. if os.path.isdir('dist') and os.listdir('dist'):
  33. shutil.rmtree('dist')
  34. run('python setup.py bdist_wheel')
  35. wheel_dist = os.listdir('dist')[0]
  36. package = os.path.join('dist', wheel_dist)
  37. if args.extras:
  38. package = f"'{package}[{args.extras}]'"
  39. run('pip install %s' % package)