def _project_init(project_name): pyversion = '%s.%s' % (sys.version_info[0], sys.version_info[1]) # Create project structure os.mkdir(project_name) os.mkdir(os.path.join(project_name, 'notebooks')) os.mkdir(os.path.join(project_name, 'data')) os.mkdir(os.path.join(project_name, 'logs')) os.mkdir(os.path.join(project_name, 'experiments')) os.mkdir(os.path.join(project_name, 'config')) open(os.path.join(project_name, 'README.md'), 'a').close() open(os.path.join(project_name, 'notebooks', 'README.md'), 'a').close() file = open(os.path.join(project_name, '.gitignore'), 'w') file.write('.venv') file.close() # ignore these files when pushing lab repo to minio file = open(os.path.join(project_name, '.labignore'), 'w') file.write('.venv\n') file.write('.ipynb_checkpoints') file.close() # Copy requirements.txt file shutil.copyfile('requirements.txt', project_name + '/requirements.txt') # Create a virtual environment create_venv(project_name) # Create runtime configuration runtime = { 'name': project_name, 'path': os.path.join(os.getcwd(), project_name), 'description': None, 'python': pyversion, 'timestamp': str(datetime.datetime.now()), 'last_push': '', 'venv': '.venv' } with open(os.path.join(project_name, 'config', 'runtime.yaml'), 'w') as file: yaml.dump(runtime, file, default_flow_style=False)
def lab_update(): """ Update Lab Environment from Project's requirements.txt """ if not os.path.isfile('requirements.txt'): click.secho('requirements.txt file is missing.', fg='red') raise click.Abort() # Update project directory if it hasn't been updated try: with open(os.path.join(os.getcwd(), 'config', 'runtime.yaml'), 'r') as file: config = yaml.load(file) home_dir = config['path'] if home_dir != os.getcwd(): config['path'] = os.getcwd() with open(os.path.join(os.getcwd(), 'config', 'runtime.yaml'), 'w') as file: yaml.dump(config, file, default_flow_style=False) except FileNotFoundError: click.secho( 'Having trouble parsing configuration file for this ' "project. It's likely that this is either not a " 'Lab Project or the Project was created with an older ' 'version of Lab.\n', fg='red') raise click.Abort() if not os.path.isdir('.venv'): click.secho("Couldn't find .venv. Creating one for you...", fg='blue') create_venv('') home_dir = os.getcwd() venv_dir = os.path.join(home_dir, '.venv') click.secho('Updating lab', fg='cyan') subprocess.call([venv_dir + '/bin/pip', 'install', '--upgrade', 'lab-ml']) click.secho('Updating environment using requirements.txt', fg='cyan') subprocess.call([ venv_dir + '/bin/pip', 'install', '--upgrade', '-r', 'requirements.txt' ])