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

Bootstrap for Mac/Linux/Windows #190

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 47 additions & 36 deletions bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sys
import platform
import argparse
# import shutil
# from git import Repo


Expand Down Expand Up @@ -32,30 +34,39 @@ def git_repo(self):
def renamefiles(self):
# Rename all files starting with diabetes_regression with project name
strtoreplace = "diabetes_regression"
dirs = [".pipelines", r"ml_service\pipelines"]
dirs = [".pipelines", r"ml_service/pipelines"]
for dir in dirs:
dirpath = os.path.join(self._project_directory, dir)
normDir = os.path.normpath(dir)
dirpath = os.path.join(self._project_directory, normDir)
for filename in os.listdir(dirpath):
if(filename.find(strtoreplace) != -1):
src = os.path.join(self._project_directory, dir, filename)
src = os.path.join(self._project_directory, normDir, filename) # NOQA: E501
dst = os.path.join(self._project_directory,
dir, filename.replace(strtoreplace, self._project_name, 1)) # NOQA: E501
normDir, filename.replace(strtoreplace, self._project_name, 1)) # NOQA: E501
os.rename(src, dst)

def renamedir(self):
# Rename any directory with diabetes_regression with project name
dirs = ["diabetes_regression"]
for dir in dirs:
src = os.path.join(self._project_directory, dir)
dst = os.path.join(self._project_directory, self._project_name)
os.rename(src, dst)
dir = "diabetes_regression"
src = os.path.join(self._project_directory, dir)
for path, subdirs, files in os.walk(src):
for name in files:
newPath = path.replace(dir, self._project_name)
if (not (os.path.exists(newPath))):
os.mkdir(newPath)
file_path = os.path.join(path, name)
new_name = os.path.join(newPath, name)
os.rename(file_path, new_name)

def deletedir(self):
# Delete unwanted directories
dirs = ["docs", r"diabetes_regression\training\R"]
dirs = ["docs", r"diabetes_regression"]
if (platform.system() == "Windows"):
cmd = 'rmdir /S /Q "{}"'
else:
cmd = 'rm -r "{}"'
for dir in dirs:
os.system(
'rmdir /S /Q "{}"'.format(os.path.join(self._project_directory, dir))) # NOQA: E501
cmd.format(os.path.join(self._project_directory, os.path.normpath(dir)))) # NOQA: E501

def cleandir(self):
# Clean up directories
Expand All @@ -79,33 +90,33 @@ def validateargs(self):
def replaceprojectname(project_dir, project_name, rename_name):
# Replace instances of rename_name within files with project_name
dirs = [r".env.example",
r".pipelines\azdo-base-pipeline.yml",
r".pipelines\azdo-pr-build-train.yml",
r".pipelines\diabetes_regression-ci-build-train.yml",
r".pipelines\diabetes_regression-ci-image.yml",
r".pipelines\diabetes_regression-template-get-model-version.yml", # NOQA: E501
r".pipelines\diabetes_regression-variables.yml",
r"environment_setup\Dockerfile",
r"environment_setup\install_requirements.sh",
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r_on_dbricks.py", # NOQA: E501
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r.py", # NOQA: E501
r"ml_service\pipelines\diabetes_regression_build_train_pipeline.py", # NOQA: E501
r"ml_service\pipelines\diabetes_regression_verify_train_pipeline.py", # NOQA: E501
r"ml_service\util\create_scoring_image.py",
r"diabetes_regression\azureml_environment.json",
r"diabetes_regression\conda_dependencies.yml",
r"diabetes_regression\evaluate\evaluate_model.py",
r"diabetes_regression\register\register_model.py",
r"diabetes_regression\training\test_train.py"] # NOQA: E501

for file in dirs:
fin = open(os.path.join(project_dir, file),
r".pipelines/azdo-base-pipeline.yml",
r".pipelines/azdo-pr-build-train.yml",
r".pipelines/diabetes_regression-ci-build-train.yml",
r".pipelines/diabetes_regression-ci-image.yml",
r".pipelines/diabetes_regression-template-get-model-version.yml", # NOQA: E501
r".pipelines/diabetes_regression-variables.yml",
r"environment_setup/Dockerfile",
r"environment_setup/install_requirements.sh",
r"ml_service/pipelines/diabetes_regression_build_train_pipeline_with_r_on_dbricks.py", # NOQA: E501
r"ml_service/pipelines/diabetes_regression_build_train_pipeline_with_r.py", # NOQA: E501
r"ml_service/pipelines/diabetes_regression_build_train_pipeline.py", # NOQA: E501
r"ml_service/pipelines/diabetes_regression_verify_train_pipeline.py", # NOQA: E501
r"ml_service/util/create_scoring_image.py",
r"diabetes_regression/azureml_environment.json",
r"diabetes_regression/conda_dependencies.yml",
r"diabetes_regression/evaluate/evaluate_model.py",
r"diabetes_regression/register/register_model.py",
r"diabetes_regression/training/test_train.py"] # NOQA: E501

for dir in dirs:
file = os.path.join(project_dir, os.path.normpath(dir))
fin = open(file,
"rt", encoding="utf8")
data = fin.read()
data = data.replace(rename_name, project_name)
fin.close()
fin = open(os.path.join(project_dir, file),
"wt", encoding="utf8")
fin = open(os.path.join(project_dir, file), "wt", encoding="utf8") # NOQA: E501
fin.write(data)
fin.close()

Expand All @@ -127,9 +138,9 @@ def main(args):
replaceprojectname(project_directory, project_name,
"diabetes_regression")
replaceprojectname(project_directory, project_name, "diabetes")
helper.deletedir()
helper.renamefiles()
helper.renamedir()
helper.deletedir()
except Exception as e:
print(e)
return 0
Expand Down