def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest path = (workon_home / envname).absolute() try: check_call([sys.executable, "-m", "virtualenv", str(path)] + rest) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', *packages)
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise
def wipeenv_cmd(): """Remove all installed packages from the current env.""" pkgs = map(lambda d: d.split("==")[0], invoke('pip', 'freeze').out.split()) to_remove = [pkg for pkg in pkgs if pkg not in ('distribute', 'wsgiref')] if to_remove: print("Uninstalling packages:\n%s" % "\n".join(to_remove)) check_call(['pip', 'uninstall', '-y'] + to_remove) else: print("Nothing to remove")
def wipeenv_cmd(): """Remove all installed packages from the current env.""" pkgs = map(lambda d: d.split("==")[0], invoke("pip", "freeze").out.split()) to_remove = [pkg for pkg in pkgs if pkg not in ("distribute", "wsgiref")] if to_remove: print("Uninstalling packages:\n%s" % "\n".join(to_remove)) check_call(["pip", "uninstall", "-y"] + to_remove) else: print("Nothing to remove")
def restore_cmd(argv): """Try to restore a broken virtualenv by reinstalling the same python version on top of it""" if len(argv) < 1: sys.exit("You must provide a valid virtualenv to target") env = argv[0] py = workon_home / env / env_bin_dir / ("python.exe" if windows else "python") exact_py = py.resolve().name check_call(["virtualenv", env, "--python=%s" % exact_py], cwd=str(workon_home))
def restore_cmd(argv): """Try to restore a broken virtualenv by reinstalling the same python version on top of it""" if len(argv) < 1: sys.exit('You must provide a valid virtualenv to target') env = argv[0] py = workon_home / env / env_bin_dir / ('python.exe' if windows else 'python') exact_py = py.resolve().name check_call(["virtualenv", env, "--python=%s" % exact_py], cwd=str(workon_home))
def restore_cmd(argv): """Try to restore a broken virtualenv by reinstalling the same python version on top of it""" if len(argv) < 1: sys.exit('You must provide a valid virtualenv to target') env = argv[0] path = workon_home / env py = path / env_bin_dir / ('python.exe' if windows else 'python') exact_py = py.resolve().name check_call([sys.executable, "-m", "virtualenv", str(path.absolute()), "--python=%s" % exact_py])
def inve(env, command, *args, exec_=False, **kwargs): """Run a command in the given virtual environment. If not execcing (replacing the python process with the specified process), pass additional keyword arguments to ``subprocess.check_call()``.""" # we don't strictly need to restore the environment, since pew runs in # its own process, but it feels like the right thing to do with temp_environ(): os.environ['VIRTUAL_ENV'] = str(workon_home / env) os.environ['PATH'] = compute_path(env) unsetenv('PYTHONHOME') unsetenv('__PYVENV_LAUNCHER__') parser = InveParser() parser.read(os.path.join(os.environ['VIRTUAL_ENV'], '.inve.ini')) os.environ.update(parser.section_items('env', os.environ)) if exec_: if 'cwd' in kwargs: os.chdir(kwargs['cwd']) os.execvp(command, [command] + list(args)) else: try: return check_call([command] + list(args), shell=windows, **kwargs) # need to have shell=True on windows, otherwise the PYTHONPATH # won't inherit the PATH except OSError as e: if e.errno == 2: err('Unable to find', command) else: raise
def inve(env, *args, **kwargs): assert args # we don't strictly need to restore the environment, since pew runs in # its own process, but it feels like the right thing to do with temp_environ(): envdir = workon_home / env os.environ['VIRTUAL_ENV'] = str(envdir) os.environ['PATH'] = os.pathsep.join([ str(envdir / env_bin_dir), os.environ['PATH'], ]) unsetenv('PYTHONHOME') unsetenv('__PYVENV_LAUNCHER__') try: return check_call(args, shell=windows, **kwargs) # need to have shell=True on windows, otherwise the PYTHONPATH # won't inherit the PATH except OSError as e: if e.errno == 2: print(kwargs) sys.stderr.write("Unable to find %s\n" % args[0]) else: raise
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, "pip", "install", "-r", str(expandpath(requirements))) if packages: inve(envname, "pip", "install", *packages)
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages) except CalledProcessError: rmvirtualenvs([envname]) raise
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, pytype='cpython', rest=[]): if python: version_path = locate_python_by_version(python, pytype) if version_path: python = version_path rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages)
def inve(env, command, *args, **kwargs): """Run a command in the given virtual environment. Pass additional keyword arguments to ``subprocess.check_call()``.""" # we don't strictly need to restore the environment, since pew runs in # its own process, but it feels like the right thing to do with temp_environ(): os.environ['VIRTUAL_ENV'] = str(workon_home / env) os.environ['PATH'] = compute_path(env) unsetenv('PYTHONHOME') unsetenv('__PYVENV_LAUNCHER__') try: return check_call([command] + list(args), shell=windows, **kwargs) # need to have shell=True on windows, otherwise the PYTHONPATH # won't inherit the PATH except OSError as e: if e.errno == 2: sys.stderr.write("Unable to find %s\n" % command) else: raise
def inve(env, command, *args, **kwargs): """Run a command in the given virtual environment. Pass additional keyword arguments to ``subprocess.check_call()``.""" # we don't strictly need to restore the environment, since pew runs in # its own process, but it feels like the right thing to do with temp_environ(): os.environ["VIRTUAL_ENV"] = str(workon_home / env) os.environ["PATH"] = compute_path(env) unsetenv("PYTHONHOME") unsetenv("__PYVENV_LAUNCHER__") try: return check_call([command] + list(args), shell=windows, **kwargs) # need to have shell=True on windows, otherwise the PYTHONPATH # won't inherit the PATH except OSError as e: if e.errno == 2: err("Unable to find", command) else: raise