def create_venv(): """ Create virtual environment """ logging.debug("Creating venv: %s" % str(VENV_DIR)) import venv venv.main([str(VENV_DIR)])
def create_new_venv() -> str: """ Create a new venv. Note: Due to a bug in Python 3.5 pip needs to be manually installed. Returns: Path to created venv. """ # Create venv venv_dir = tempfile.mkdtemp() venv.main([venv_dir, "--without-pip"]) if os.name == "posix": python_executable = Path(venv_dir) / "bin" / "python" else: python_executable = Path(venv_dir) / "Scripts" / "python.exe" # Download and run pip installer # Windows blocks access unless delete set to False with tempfile.NamedTemporaryFile(delete=False) as tmp_file: tmp_file.write(download_url(PIP_INSTALL_SCRIPT).encode()) tmp_file.flush() os.fsync(tmp_file) subprocess.check_call([str(python_executable), tmp_file.name]) os.unlink(tmp_file.name) return venv_dir
def create_new_venv() -> Path: """Create a new venv. Returns: path to created venv """ # Create venv venv_dir = Path(tempfile.mkdtemp()) venv.main([str(venv_dir)]) return venv_dir
def run(self, *args, **kwargs): venv_path = PROJECT_NAME + '-venv' venv.create(venv_path, with_pip=True) venv.main() command = f". {venv_path}/bin/activate && " \ "pip install -r requirements-dev.txt" os.system(command)
def _create_new_venv() -> Path: """Create a new venv. Returns: path to created venv """ # Create venv venv_dir = _create_tmp_dir() venv.main([str(venv_dir)]) return venv_dir
def run(self): venv_path = Path(__file__).absolute().parent / 'venv' / 'asciietch' print(f'Creating virtual environment in {venv_path}') venv.main(args=[str(venv_path)]) print('Linking `activate` to top level of project.\n' 'To activate, simply run `source activate`.') activate = Path(venv_path, 'bin', 'activate') activate_link = Path(__file__).absolute().parent / 'activate' try: activate_link.symlink_to(activate) except FileExistsError: ...
def run(self): venv_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'venv', 'shiv') print('Creating virtual environment in {}'.format(venv_path)) venv.main(args=[venv_path]) print('Linking `activate` to top level of project.\n' 'To activate, simply run `source activate`.') try: os.symlink( Path(venv_path, 'bin', 'activate'), Path(Path(__file__).absolute().parent, 'activate'), ) except FileExistsError: pass
def run(self): venv_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'venv', 'shiv') print('Creating virtual environment in {}'.format(venv_path)) venv.main(args=[venv_path]) print( 'Linking `activate` to top level of project.\n' 'To activate, simply run `source activate`.' ) try: os.symlink( Path(venv_path, 'bin', 'activate'), Path(Path(__file__).absolute().parent, 'activate'), ) except FileExistsError: pass
def run(self): venv_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'venv', 'plague') print(f'Creating virtual environment in {venv_path}') venv.main(args=[venv_path]) print('Linking `activate` to top level of project.\n') print('To activate, simply run `source activate`.') try: os.symlink( os.path.join(venv_path, 'bin', 'activate'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'activate')) except OSError: print( 'Unable to create symlink, you may have a stale symlink from a previous invocation.' )
def make_venv(): if version_info < (3, 3): # Can't build the venv, alert but don't fail. print("Incompatible Python (<3.3). " + "Virtual environment must be created manually\n") return from venv import main cookiecutter_args = "{{cookiecutter.venv_args}}" args = "{}".format(join(getcwd(), 'venv')) if cookiecutter_args != "": args = "{} {}".format(cookiecutter_args, args) main(args.split()) print("Virtual environment successfully created. Activate " + "it with: \n" + "$ source venv/bin/activate \n" + "from the project root\n")
def main(): args = parser.parse_args() sys_path_entry, = glob.glob( os.path.join(args.directory, "lib/python*/site-packages") ) mo, = re.finditer("python(\d)\.(\d)", sys_path_entry) major, minor = map(int, mo.group(1, 2)) if (major, minor) == sys.version_info[:2]: parser.error( "Target venv has same Python version as current: %s.%s" % (major, minor) ) entries = list(pkg_resources.find_on_path(None, sys_path_entry)) print(entries) if not entries: parser.error("venv contains no installed packages") os.rename(args.directory, args.directory + "~") venv.main([args.directory]) subprocess.check_call( [os.path.join(args.directory, "bin/pip"), "install"] + ["%s==%s" % (o.project_name, o.version) for o in entries] )
def setUpModule(): """ The module specific setUp method """ logging.disable(logging.CRITICAL) # Create a Python 2 Virtual Environment try: import virtualenv # Note: We can't create it from virtualenv API so launch an external process. subprocess.Popen([sys.executable, '-m', 'virtualenv', PYTHON2_VE], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except ImportError: pass # Create a Python 3 Virtual Environment try: import venv venv.main([PYTHON3_VE]) except ImportError: pass
def run(self): venv_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'venv', 'incb') print('Creating virtual environment in {path}'.format(path=venv_path)) if '3' in self.python or sys.version_info[0] >= 3: import venv venv.main(args=[venv_path]) else: venv_cmd = ['virtualenv'] if self.python: venv_cmd.extend(['-p', self.python]) venv_cmd.append(venv_path) subprocess.check_call(venv_cmd) print('Linking `activate` to top level of project.\n') print('To activate, simply run `source activate`.') try: os.symlink( os.path.join(venv_path, 'bin', 'activate'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'activate')) except OSError: # symlink already exists pass
def install(self, pkg): version = pkg.provides['version'] exec_path = self._exec_paths[version] venv.main(['--python', exec_path, pkg.install_path])
# create the virtual env, if necessary if not is_in_venv: if (CURRENT_PYTHON[0] != REQUIRED_PYTHON[0] or CURRENT_PYTHON[1] < REQUIRED_PYTHON[1]): if platform.system() == 'Windows': raise Exception('This script requires Python %d.%d or later' % REQUIRED_PYTHON) exe = 'python%d.%d' % REQUIRED_PYTHON os.execlp(exe, exe, *sys.argv) if not os.path.isfile(venv_executable): import venv try: venv.main(['--upgrade', venvdir]) except SystemExit: # handle Ubuntu's horrible hackery where you get a # venv without pip... import shutil shutil.rmtree(venvdir) raise subprocess.check_call( [venv_executable, '-m', 'pip', 'install', '-qe', basedir]) if platform.system() == 'Windows': # os.execlp doesn't actually replace the current process # on Windows with subprocess.Popen([venv_executable] + sys.argv) as proc: try:
#!/usr/bin/env python3 if __name__ == '__main__': import sys import pathlib executable = pathlib.Path(sys.executable or 'python3').name print('WARNING: the pyenv script is deprecated in favour of ' f'`{executable} -m venv`', file=sys.stderr) rc = 1 try: import venv venv.main() rc = 0 except Exception as e: print('Error: %s' % e, file=sys.stderr) sys.exit(rc)
logger.error(message) exit(code) if __name__ == '__main__': arguments = docopt(__doc__) target = arguments['<target>'] outfile = arguments['--outfile'] virtualenv_name = 'venv-freeze' logging.basicConfig( level=logging.WARNING if not arguments['--verbose'] else logging.DEBUG) make_clean(virtualenv_name) logger.info(f'Creating virtualenv: {virtualenv_name}') venv.main(args=(virtualenv_name, )) logger.info( f'Installing requirements from {target} in virtualenv: {virtualenv_name}' ) install_cmd = subprocess.run( [f'{virtualenv_name}/bin/pip', 'install', '-r', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) if install_cmd.returncode >= 1: make_clean(virtualenv_name) exit_failure([install_cmd.stdout, install_cmd.stderr]) logger.info(
from os.path import join def make_venv(): if version_info < (3, 3): # Can't build the venv, alert but don't fail. print("Incompatible Python (<3.3). " + "Virtual environment must be created manually\n") return from venv import main cookiecutter_args = "{{cookiecutter.venv_args}}" args = "{}".format(join(getcwd(), 'venv')) if cookiecutter_args != "": args = "{} {}".format(cookiecutter_args, args) main(args.split()) print("Virtual environment successfully created. Activate " + "it with: \n" + "$ source venv/bin/activate \n" + "from the project root\n") def main(): print("Template successfully created.\n") make_venv() print("Done") main() exit(0)