def init(venv_name): """Initializez a virtualenv""" inenv = InenvManager() inenv.get_prepped_venv(venv_name, skip_cached=False) if not os.getenv(INENV_ENV_VAR): activator_warn(inenv) click.echo(click.style("Your venv is ready. Enjoy!", fg='green'))
def run_cli(): try: inenv = InenvManager() for venv in inenv.registered_venvs.keys(): new_switch = copy.deepcopy(switch_or_run) for param in new_switch.params: if param.name == 'venv_name': param.default = venv main_cli.add_command(new_switch, name=venv, sort_later=True) main_cli(obj={}, prog_name="inenv") except InenvException as e: click.echo(click.style("{}".format(e.message), fg='red'))
def switch_or_run(cmd, venv_name=None): """Switch or run in this env""" if cmd: return _run(venv_name, cmd) inenv = InenvManager() if not os.getenv(INENV_ENV_VAR): activator_warn(inenv) return else: venv = inenv.get_prepped_venv(venv_name) inenv.clear_extra_source_file() inenv.write_extra_source_file("source {}".format(venv.activate_shell_file)) sys.exit(EVAL_EXIT_CODE)
def switch_or_run(cmd, venv_name=None): """Switch or run in this env""" if cmd: return _run(venv_name, cmd) inenv = InenvManager() if not os.getenv(INENV_ENV_VAR): activator_warn(inenv) return else: venv = inenv.get_prepped_venv(venv_name) inenv.clear_extra_source_file() inenv.write_extra_source_file("source {}".format( venv.activate_shell_file)) inenv.write_extra_source_file( override_envars_and_deactivate(inenv.get_envvars(venv_name))) if autojump_enabled(): dir = inenv.guess_contents_dir(venv_name) inenv.write_extra_source_file('cd {}'.format(dir)) click.echo(click.style("Jumping to {}".format(dir), fg='green')) sys.exit(EVAL_EXIT_CODE)
def _run(venv_name, cmd): if len(cmd) == 1: cmd = cmd[0].split() inenv = InenvManager() venv = inenv.get_prepped_venv(venv_name) venv.run(cmd, always_exit=True)
def extra_source(): """Path to file sourced after an inenv switch""" inenv = InenvManager() print(inenv.extra_source_file)
def root(venv_name): """ Removes the venv by name """ inenv = InenvManager() inenv.get_venv(venv_name) venv = inenv.registered_venvs[venv_name] click.echo(venv['root'])
def rm(venv_name): """ Removes the venv by name """ inenv = InenvManager() venv = inenv.get_venv(venv_name) click.confirm("Delete dir {}".format(venv.path)) shutil.rmtree(venv.path)
def switch_or_run(cmd, venv_name=None): """Switch or run in this env""" if cmd: return _run(venv_name, cmd) inenv = InenvManager() if not os.getenv(INENV_ENV_VAR): activator_warn(inenv) return else: venv = inenv.get_prepped_venv(venv_name) inenv.clear_extra_source_file() inenv.write_extra_source_file("source {}".format(venv.activate_shell_file)) inenv.write_extra_source_file(override_envars_and_deactivate(inenv.get_envvars(venv_name))) if autojump_enabled(): dir = inenv.guess_contents_dir(venv_name) inenv.write_extra_source_file('cd {}'.format(dir)) click.echo(click.style("Jumping to {}".format(dir), fg='green')) sys.exit(EVAL_EXIT_CODE)
def init(venv_name): """Initializez a virtualenv""" inenv = InenvManager() inenv.get_prepped_venv(venv_name) activator_warn(inenv)
def clean(venv_name): inenv = InenvManager() venv = inenv.get_venv(venv_name) click.confirm("Delete dir {}".format(venv.path)) shutil.rmtree(venv.path)