-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Bootstrap code #186
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
Merged
Merged
Add Bootstrap code #186
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e9c4806
bootstrap
sudivate dc47906
redmi file
sudivate d8aac45
intial doc
sudivate 8e8370b
update doc
sudivate 230cf26
directory structure
sudivate b777a2f
added directory structure doc
sudivate 16ea77c
updated doc
sudivate 13101be
Merge branch 'master' of https://github.com/microsoft/MLOpsPython int…
sudivate 8f6b318
fixed linting
sudivate 6e5ddd0
fixed linting
sudivate a0a20f3
Merge branch 'master' into sudivate-bootstrap
dtzar 0b64096
pr comments
sudivate a913a37
Merge branch 'master' of https://github.com/microsoft/MLOpsPython int…
sudivate bc7ca2f
Merge branch 'sudivate-bootstrap' of https://github.com/microsoft/MLO…
sudivate afac78e
formating
sudivate 4a92955
fomratting
sudivate 2d053bd
PR
sudivate 4da39ba
removed git clone
sudivate c5bbe53
removed gitpython
sudivate d1403a3
commented gitpython import
sudivate 9210b3e
pr
sudivate aa6774f
updated doc
sudivate 4fe51cd
added dirs
sudivate fdd704e
replaced dir
sudivate ec6c268
updated path
sudivate 8ae2249
fixed imports
sudivate 6a0f07b
updated script
sudivate aaac71b
linting fix
sudivate 4a9db3d
linting fix
sudivate 80e5d45
pr
sudivate fb4b33f
corrected URL
sudivate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Bootstrap from MLOpsPython repository | ||
|
||
To use this existing project structure and scripts for your new ML project, you can quickly get started from the existing repository, bootstrap and create a template that works for your ML project. Bootstraping will prepare a similar directory structure for your project which includes renaming files and folders, deleting and cleaning up some directories and fixing imports and absolute path based on your project name. This will enable reusing various resources like pre-built pipelines and scripts for your new project. | ||
|
||
To bootstrap from the existing MLOpsPython repository clone this repository and run bootstrap.py script as below | ||
|
||
>python bootstrap.py --d [dirpath] --n [projectname] | ||
|
||
Where [dirpath] is the absolute path to the root of your directory where MLOps repo is cloned and [projectname] is the name of your ML project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import os | ||
import sys | ||
import argparse | ||
# from git import Repo | ||
|
||
|
||
class Helper: | ||
|
||
def __init__(self, project_directory, project_name): | ||
self._project_directory = project_directory | ||
self._project_name = project_name | ||
self._git_repo = "https://github.com/microsoft/MLOpsPython.git" | ||
|
||
@property | ||
def project_directory(self): | ||
return self._project_directory | ||
|
||
@property | ||
def project_name(self): | ||
return self._project_name | ||
|
||
@property | ||
def git_repo(self): | ||
return self._git_repo | ||
|
||
# def clonerepo(self): | ||
# # Download MLOpsPython repo from git | ||
# Repo.clone_from( | ||
# self._git_repo, self._project_directory, branch="master", depth=1) # NOQA: E501 | ||
# print(self._project_directory) | ||
|
||
def renamefiles(self): | ||
# Rename all files starting with diabetes_regression with project name | ||
strtoreplace = "diabetes_regression" | ||
dirs = [".pipelines", r"ml_service\pipelines"] | ||
for dir in dirs: | ||
dirpath = os.path.join(self._project_directory, dir) | ||
for filename in os.listdir(dirpath): | ||
if(filename.find(strtoreplace) != -1): | ||
src = os.path.join(self._project_directory, dir, filename) | ||
dst = os.path.join(self._project_directory, | ||
dir, 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) | ||
|
||
def deletedir(self): | ||
# Delete unwanted directories | ||
dirs = ["docs", r"diabetes_regression\training\R"] | ||
for dir in dirs: | ||
os.system( | ||
'rmdir /S /Q "{}"'.format(os.path.join(self._project_directory, dir))) # NOQA: E501 | ||
|
||
def replaceprojectname(self): | ||
# Replace instances of diabetes_regression within files | ||
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\training\test_train.py"] # NOQA: E501 | ||
|
||
for file in dirs: | ||
fin = open(os.path.join(self._project_directory, file), | ||
"rt", encoding="utf8") | ||
data = fin.read() | ||
data = data.replace("diabetes_regression", self.project_name) | ||
fin.close() | ||
fin = open(os.path.join(self._project_directory, file), | ||
"wt", encoding="utf8") | ||
fin.write(data) | ||
fin.close() | ||
|
||
def cleandir(self): | ||
# Clean up directories | ||
dirs = ["data", "experimentation"] | ||
for dir in dirs: | ||
for root, dirs, files in os.walk(os.path.join(self._project_directory, dir)): # NOQA: E501 | ||
for file in files: | ||
os.remove(os.path.join(root, file)) | ||
|
||
def validateargs(self): | ||
# Validate arguments | ||
if (os.path.isdir(self._project_directory) is False): | ||
raise Exception( | ||
"Not a valid directory. Please provide absolute directory path") # NOQA: E501 | ||
# if (len(os.listdir(self._project_directory)) > 0): | ||
# raise Exception("Directory not empty. PLease empty directory") | ||
if(len(self._project_name) < 3 or len(self._project_name) > 15): | ||
raise Exception("Project name should be 3 to 15 chars long") | ||
|
||
|
||
def main(args): | ||
parser = argparse.ArgumentParser(description='New Template') | ||
parser.add_argument("--d", type=str, | ||
help="Absolute path to new project direcory") | ||
parser.add_argument( | ||
"--n", type=str, help="Name of the project[3-15 chars] ") | ||
try: | ||
args = parser.parse_args() | ||
project_directory = args.d | ||
project_name = args.n | ||
helper = Helper(project_directory, project_name) | ||
helper.validateargs() | ||
# helper.clonerepo() | ||
helper.cleandir() | ||
helper.replaceprojectname() | ||
helper.deletedir() | ||
helper.renamefiles() | ||
helper.renamedir() | ||
except Exception as e: | ||
print(e) | ||
return 0 | ||
|
||
|
||
if '__main__' == __name__: | ||
sys.exit(main(sys.argv)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.