Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dev mode to install_from_src.py #1856

Merged
merged 12 commits into from
Sep 29, 2022
Merged
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ Ensure that you have `python3` installed, and the user has access to the site-pa

Run the following script from the top of the source directory.

NOTE: This script uninstalls existing `torchserve`, `torch-model-archiver` and `torch-workflow-archiver` installations
NOTE: This script force reinstalls `torchserve`, `torch-model-archiver` and `torch-workflow-archiver` if existing installations are found

#### For Debian Based Systems/ MacOS

```
python ./ts_scripts/install_dependencies.py --environment=dev
python ./ts_scripts/install_from_src.py
python ./ts_scripts/install_from_src.py --environment=dev
```

Use `--cuda` flag with `install_dependencies.py` for installing cuda version specific dependencies. Possible values are `cu111`, `cu102`, `cu101`, `cu92`
Expand Down
83 changes: 24 additions & 59 deletions ts_scripts/install_from_src.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,38 @@
import argparse
import os
import sys
import time
import shutil


# To help discover local modules
REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
sys.path.append(REPO_ROOT)

from ts_scripts import print_env_info as build_hdr_printer
from ts_scripts.utils import check_python_version
from ts_scripts.utils import is_conda_env


def clean_slate():
print("## Uninstall existing torchserve and model archiver")
if is_conda_env():
cmd = "conda uninstall -y torchserve torch-model-archiver workflow-model-archiver"
else:
cmd = "pip uninstall -y torchserve torch-model-archiver workflow-model-archiver"
print(f"## In directory: {os.getcwd()} | Executing command: {cmd}")
os.system(cmd)
time.sleep(5)


def install_torchserve():
print("## Install torchserve from source")
cmd = "pip install ."
print(f"## In directory: {os.getcwd()} | Executing command: {cmd}")
os.system(cmd)


def install_torch_model_archiver():
print("## Install torch-model-archiver from source")
cmd = "pip install model-archiver/."
print(f"## In directory: {os.getcwd()} | Executing command: {cmd}")
os.system(cmd)


def install_torch_workflow_archiver():
print("## Install torch-workflow-archiver from source")
cmd = "pip install workflow-archiver/."
print(f"## In directory: {os.getcwd()} | Executing command: {cmd}")
os.system(cmd)


def clean_up_build_residuals():
print("## Cleaning build residuals (__pycache__)")
try:
for (dirpath, dirnames, filenames) in os.walk(os.getcwd()):
if "__pycache__" in dirnames:
cache_dir = os.path.join(dirpath, "__pycache__")
print(f"## Removing - {cache_dir}")
shutil.rmtree(cache_dir)
except Exception as e:
print(f"#Error while cleaning cache file. Details - {str(e)}")


def install_from_src():
clean_slate()
install_torch_model_archiver()
install_torch_workflow_archiver()
install_torchserve()
clean_up_build_residuals()


if __name__ == '__main__':
def install_from_src(dev=False):
for binary in [".", "model-archiver/.", "workflow-archiver/."]:
cmd = (
f"pip install --force-reinstall -e {binary}"
if dev
else f"pip install --force-reinstall {binary}"
)
print(f"## In directory {os.getcwd()} | Executing command {cmd}")
os.system(cmd)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--environment",
type=str,
default="production",
help="options: dev|prod",
)
args = parser.parse_args()
check_python_version()
from pygit2 import Repository
git_branch = Repository('.').head.shorthand

git_branch = Repository(".").head.shorthand
build_hdr_printer.main(git_branch)
install_from_src()
install_from_src(args.environment == "dev")
2 changes: 1 addition & 1 deletion ts_scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def is_conda_env():


def check_python_version():
req_version = (3, 6)
req_version = (3, 8)
cur_version = sys.version_info

if not (
Expand Down