Skip to content

Commit

Permalink
feat: add virtualenvs binaries to the path
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec4r committed Aug 10, 2022
1 parent 4839129 commit b72cf67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ def project_creator(self, version: str) -> None:
"tutor_root": f"{self.PROJECT_PATH}",
"tutor_plugins_root": f"{self.PROJECT_PATH}/plugins",
}
context = {
"version": data.get("version", None),
"tvm": f"{TVM_PATH}",
}

self.create_config_json(data)
self.create_active_script(data)
self.create_tutor_switcher(context)
self.create_project(version)

def current_version(self) -> ProjectName:
Expand All @@ -57,18 +52,13 @@ def create_config_json(self, data: dict) -> None:

def create_active_script(self, context: dict) -> None:
"""Create active script file."""
context.update({
"tvm_path": TVM_PATH
})
activate_script = f"{self.TVM_ENVIRONMENT}/bin/activate"
with open(activate_script, "w", encoding="utf-8") as activate_file:
activate_file.write(TVM_ACTIVATE_SCRIPT.render(**context))

def create_tutor_switcher(self, context: dict) -> None:
"""Create tutor switcher file."""
tutor_file = f"{self.TVM_ENVIRONMENT}/bin/tutor"
with open(tutor_file, "w", encoding="utf-8") as switcher_file:
switcher_file.write(TUTOR_SWITCHER_TEMPLATE.render(**context))
# set execute permissions
os.chmod(tutor_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH)

def create_project(self, project: str) -> None:
"""Duplicate the version directory and rename it."""
if not os.path.exists(f"{TVM_PATH}/{project}"):
Expand All @@ -86,7 +76,7 @@ def setup_version_virtualenv(version=None) -> None:
"""Create virtualenv and install tutor cloned."""
# Create virtualenv
subprocess.run(
f"cd {TVM_PATH}/{version}; virtualenv venv",
f"cd {TVM_PATH}/{version}; virtualenv --prompt {version} venv",
shell=True,
check=True,
executable="/bin/bash",
Expand Down
2 changes: 1 addition & 1 deletion tvm/templates/tvm_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
TVM_PROJECT_ENV="{{ tutor_root }}"
export TVM_PROJECT_ENV
_TVM_OLD_VIRTUAL_PATH="$PATH"
PATH="$TVM_PROJECT_ENV/.tvm/bin:$PATH"
PATH="{{tvm_path}}/{{version}}/venv/bin:$PATH"
export PATH
if ! [ -z "${TUTOR_ROOT+_}" ] ; then
_TVM_OLD_TUTOR_ROOT="$TUTOR_ROOT"
Expand Down

0 comments on commit b72cf67

Please sign in to comment.