def virtualenv_template(request, tmpdir_factory, pip_src, setuptools_install, common_wheels): if six.PY3 and request.config.getoption('--use-venv'): venv_type = 'venv' else: venv_type = 'virtualenv' # Create the virtual environment tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv'))) venv = VirtualEnvironment(tmpdir.join("venv_orig"), venv_type=venv_type) # Install setuptools and pip. install_egg_link(venv, 'setuptools', setuptools_install) pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip' pip_src.copytree(pip_editable) assert compileall.compile_dir(str(pip_editable), quiet=1) subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'], cwd=pip_editable) # Drop (non-relocatable) launchers. for exe in os.listdir(venv.bin): if not (exe.startswith('python') or exe.startswith('libpy') # Don't remove libpypy-c.so... ): (venv.bin / exe).remove() # Enable user site packages. venv.user_site_packages = True # Rename original virtualenv directory to make sure # it's not reused by mistake from one of the copies. venv_template = tmpdir / "venv_template" venv.move(venv_template) yield venv
def virtualenv_template( request: pytest.FixtureRequest, tmpdir_factory: pytest.TempPathFactory, pip_src: Path, setuptools_install: Path, coverage_install: Path, ) -> Iterator[VirtualEnvironment]: venv_type: VirtualEnvironmentType if request.config.getoption("--use-venv"): venv_type = "venv" else: venv_type = "virtualenv" # Create the virtual environment tmpdir = tmpdir_factory.mktemp("virtualenv") venv = VirtualEnvironment(tmpdir.joinpath("venv_orig"), venv_type=venv_type) # Install setuptools and pip. install_pth_link(venv, "setuptools", setuptools_install) pip_editable = tmpdir_factory.mktemp("pip") / "pip" shutil.copytree(pip_src, pip_editable, symlinks=True) # noxfile.py is Python 3 only assert compileall.compile_dir( str(pip_editable), quiet=1, rx=re.compile("noxfile.py$"), ) subprocess.check_call( [os.fspath(venv.bin / "python"), "setup.py", "-q", "develop"], cwd=pip_editable ) # Install coverage and pth file for executing it in any spawned processes # in this virtual environment. install_pth_link(venv, "coverage", coverage_install) # zz prefix ensures the file is after easy-install.pth. with open(venv.site / "zz-coverage-helper.pth", "a") as f: f.write("import coverage; coverage.process_startup()") # Drop (non-relocatable) launchers. for exe in os.listdir(venv.bin): if not ( exe.startswith("python") or exe.startswith("libpy") # Don't remove libpypy-c.so... ): (venv.bin / exe).unlink() # Enable user site packages. venv.user_site_packages = True # Rename original virtualenv directory to make sure # it's not reused by mistake from one of the copies. venv_template = tmpdir / "venv_template" venv.move(venv_template) yield venv
def virtualenv_template(request, tmpdir_factory, pip_src, setuptools_install, coverage_install): if six.PY3 and request.config.getoption('--use-venv'): venv_type = 'venv' else: venv_type = 'virtualenv' # Create the virtual environment tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv'))) venv = VirtualEnvironment(tmpdir.joinpath("venv_orig"), venv_type=venv_type) # Install setuptools and pip. install_egg_link(venv, 'setuptools', setuptools_install) pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip' shutil.copytree(pip_src, pip_editable, symlinks=True) # noxfile.py is Python 3 only assert compileall.compile_dir( str(pip_editable), quiet=1, rx=re.compile("noxfile.py$"), ) subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'], cwd=pip_editable) # Install coverage and pth file for executing it in any spawned processes # in this virtual environment. install_egg_link(venv, 'coverage', coverage_install) # zz prefix ensures the file is after easy-install.pth. with open(venv.site / 'zz-coverage-helper.pth', 'a') as f: f.write('import coverage; coverage.process_startup()') # Drop (non-relocatable) launchers. for exe in os.listdir(venv.bin): if not (exe.startswith('python') or exe.startswith('libpy') # Don't remove libpypy-c.so... ): (venv.bin / exe).unlink() # Enable user site packages. venv.user_site_packages = True # Rename original virtualenv directory to make sure # it's not reused by mistake from one of the copies. venv_template = tmpdir / "venv_template" venv.move(venv_template) yield venv
def test_install_user_venv_nositepkgs_fails( self, virtualenv: VirtualEnvironment, script: PipTestEnvironment, data: TestData ) -> None: """ user install in virtualenv (with no system packages) fails with message """ # We can't use PYTHONNOUSERSITE, as it's not # honoured by virtualenv's custom site.py. virtualenv.user_site_packages = False run_from = data.packages.joinpath("FSPkg") result = script.pip( "install", "--user", curdir, cwd=run_from, expect_error=True, ) assert ( "Can not perform a '--user' install. User site-packages are not " "visible in this virtualenv." in result.stderr )
def virtualenv_template(request, tmpdir_factory, pip_src, setuptools_install, common_wheels): if six.PY3 and request.config.getoption('--use-venv'): venv_type = 'venv' else: venv_type = 'virtualenv' # Create the virtual environment tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv'))) venv = VirtualEnvironment(tmpdir.join("venv_orig"), venv_type=venv_type) # Install setuptools and pip. install_egg_link(venv, 'setuptools', setuptools_install) pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip' pip_src.copytree(pip_editable) assert compileall.compile_dir(str(pip_editable), quiet=1) subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'], cwd=pip_editable) # Drop (non-relocatable) launchers. for exe in os.listdir(venv.bin): if not ( exe.startswith('python') or exe.startswith('libpy') # Don't remove libpypy-c.so... ): (venv.bin / exe).remove() # Enable user site packages. venv.user_site_packages = True # Rename original virtualenv directory to make sure # it's not reused by mistake from one of the copies. venv_template = tmpdir / "venv_template" venv.move(venv_template) yield venv