Skip to content

Commit

Permalink
fix: use shutil instead of disutils and fix template syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec4r committed Jul 7, 2024
1 parent 4203f47 commit f98ff3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pathlib
import shutil
import subprocess
from distutils.dir_util import copy_tree # pylint: disable=W0402
from typing import List

import yaml
Expand Down Expand Up @@ -99,25 +98,31 @@ def create_active_script(self, context: dict) -> None:

def create_project(self, project_name: ProjectName) -> None:
"""Duplicate the version directory and rename it."""
if not os.path.exists(f"{TVM_PATH}/{project_name}"):
project_path = os.path.join(TVM_PATH, project_name)

if not os.path.exists(project_path):
tutor_version = project_name.split("@")[0]
tutor_version_folder = f"{TVM_PATH}/{tutor_version}"
tutor_version_folder = os.path.join(TVM_PATH, tutor_version)

tvm_project = f"{TVM_PATH}/{project_name}"
copy_tree(tutor_version_folder, tvm_project)
with open(f"{tvm_project}/config.yml", "w", encoding='utf-8') as f:
data = {'project_directories': [f"{self.PROJECT_PATH}"]}
shutil.copytree(tutor_version_folder, project_path, dirs_exist_ok=True)

config_path = os.path.join(project_path, "config.yml")
with open(config_path, "w", encoding='utf-8') as f:
data = {'project_directories': [self.PROJECT_PATH]}
yaml.dump(data, f, default_flow_style=False)

shutil.rmtree(f"{tvm_project}/venv")
venv_path = os.path.join(project_path, "venv")
shutil.rmtree(venv_path, ignore_errors=True)
self.setup_version_virtualenv(project_name)
else:
with open(f"{TVM_PATH}/{project_name}/config.yml", "r+", encoding='utf-8') as f:
config_path = os.path.join(project_path, "config.yml")
with open(config_path, "r+", encoding='utf-8') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
data['project_directories'].append(f"{self.PROJECT_PATH}")
f.truncate(0)
f.seek(0)
yaml.dump(data, f, default_flow_style=False)
if self.PROJECT_PATH not in data['project_directories']:
data['project_directories'].append(self.PROJECT_PATH)
f.seek(0)
f.truncate()
yaml.dump(data, f, default_flow_style=False)

@staticmethod
def setup_version_virtualenv(version=None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tvm/templates/tvm_activate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tutor switcher jinja template."""
from jinja2 import Template

TEMPLATE = '''
TEMPLATE = r'''
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
if [ "${BASH_SOURCE-}" = "$0" ]; then
Expand Down

0 comments on commit f98ff3b

Please sign in to comment.