def run(self, command_line, verbose=True): """ Run a command in the context of this virtual environment :param command_line: A shell command line. :type command_line: str :param verbose: outputs the method call if True :type verbose: bool :returns: the output of running the command :rtype: str """ # info('VenvInfo.run verbose: %s' % repr(verbose)) new_env = Project.env_without_virtualenvwrapper() output = None with LocalShell() as local: venv_script = Project.virtualenvwrapper_script # noinspection PyArgumentEqualDefault venvs = local.run('/bin/bash -c "source {venv_script} ;' 'lsvirtualenv -b"'.format(venv_script=venv_script), verbose=False, env=new_env).strip().split("\n") if self.venv in venvs: output = local.run('/bin/bash -c "source {venv_script} ; ' 'workon {venv} ; python --version ; echo \"$VIRTUAL_ENV\" ; ' '{cmd}"'.format(venv_script=venv_script, venv=self.venv, cmd=command_line), verbose=verbose, env=new_env) return output
def exists(self): """Does this virtualenv exist?""" new_env = Project.env_without_virtualenvwrapper() with LocalShell() as local: venv_script = Project.virtualenvwrapper_script # noinspection PyArgumentEqualDefault venvs = local.run('/bin/bash -c "source {venv_script} ;' 'lsvirtualenv -b"'.format(venv_script=venv_script), verbose=False, env=new_env).strip().split("\n") return self.venv in venvs
def rmvirtualenv(self): """Remove this virtualenv""" new_env = Project.env_without_virtualenvwrapper() with LocalShell() as local: venv_script = Project.virtualenvwrapper_script # noinspection PyArgumentEqualDefault venvs = local.run('/bin/bash -c "source {venv_script} ;' 'lsvirtualenv -b"'.format(venv_script=venv_script), verbose=False, env=new_env).strip().split("\n") if self.venv in venvs: local.run('/bin/bash -c "source {venv_script} ; ' 'rmvirtualenv {venv}"'.format(venv_script=venv_script, venv=self.venv), verbose=True, env=new_env)
def mkvirtualenv(self): """Make a virtualenv""" new_env = Project.env_without_virtualenvwrapper() debug("os.environ['PATH']: \"{path}\"".format(path=os.environ['PATH'])) debug("new_env: {env}".format(env=pformat(new_env))) with LocalShell() as local: venv_script = Project.virtualenvwrapper_script # noinspection PyArgumentEqualDefault venvs = local.run('/bin/bash -c "source {venv_script} ;' 'lsvirtualenv -b"'.format(venv_script=venv_script), verbose=False, env=new_env).strip().split("\n") if self.venv not in venvs: python_path = local.system('which {python}'.format(python=self.python)).strip() local.run('/bin/bash -c "source {venv_script} ; ' 'mkvirtualenv -p {python} {venv}"'.format(venv_script=venv_script, python=python_path, venv=self.venv), verbose=True, env=new_env)
def version(): """Show the current version""" if Project.configured(): info("Current version is: %s" % get_project_version(project_package=Project.package))