def main_pip(start_time, use_lock): """ Install pip-based project (uses venv), looks for requirements.txt files Parameters ---------- start_time : datetime The initial runtime of the function. use_lock : bool If True Uses requirements.txt and requirements.dev.lock.txt files """ reqs_txt = _REQS_LOCK_TXT if use_lock else _REQS_TXT reqs_dev_txt = ('requirements.dev.lock.txt' if use_lock else 'requirements.dev.txt') cmdr = Commander() # TODO: modify readme to add how to activate env? probably also in conda name = Path('.').resolve().name venv_dir = f'venv-{name}' cmdr.run('python', '-m', 'venv', venv_dir, description='Creating venv') # add venv_dir to .gitignore if it doesn't exist if Path('.gitignore').exists(): with open('.gitignore') as f: if venv_dir not in f.read(): cmdr.append_inline(venv_dir, '.gitignore') else: cmdr.append_inline(venv_dir, '.gitignore') folder, bin_name = _get_pip_folder_and_bin_name() pip = str(Path(venv_dir, folder, bin_name)) if Path(_SETUP_PY).exists(): _pip_install_setup_py_pip(cmdr, pip) _pip_install(cmdr, pip, lock=not use_lock, requirements=reqs_txt) if Path(reqs_dev_txt).exists(): _pip_install(cmdr, pip, lock=not use_lock, requirements=reqs_dev_txt) if os.name == 'nt': cmd_activate = f'{venv_dir}\\Scripts\\Activate.ps1' else: cmd_activate = f'source {venv_dir}/bin/activate' _next_steps(cmdr, cmd_activate, start_time)
def main_pip(): if not Path('requirements.txt').exists(): raise exceptions.ClickException( '"ploomber install" requires a pip ' 'requirements.txt file. Use "ploomber scaffold" to create one ' 'from a template or create one manually') cmdr = Commander() # TODO: modify readme to add how to activate env? probably also in conda # TODO: add to gitignore, create if it doesn't exist name = Path('.').resolve().name venv_dir = f'venv-{name}' cmdr.run('python', '-m', 'venv', venv_dir, description='Creating venv') cmdr.append_inline(venv_dir, '.gitignore') folder = 'Scripts' if os.name == 'nt' else 'bin' bin_name = 'pip.EXE' if os.name == 'nt' else 'pip' pip = str(Path(venv_dir, folder, bin_name)) _try_pip_install_setup_py(cmdr, pip) _pip_install_and_lock(cmdr, pip, requirements='requirements.txt') if Path('requirements.dev.txt').exists(): _pip_install_and_lock(cmdr, pip, requirements='requirements.dev.txt') if os.name == 'nt': cmd_activate = ( f'\nIf using cmd.exe: {venv_dir}\\Scripts\\activate.bat' f'\nIf using PowerShell: {venv_dir}\\Scripts\\Activate.ps1') else: cmd_activate = f'source {venv_dir}/bin/activate' _next_steps(cmdr, cmd_activate)