Python virtualenv.create_environment() Examples

The following are 7 code examples of virtualenv.create_environment(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module virtualenv , or try the search function .
Example #1
Source File: config.py    From pulsar with Apache License 2.0 7 votes vote down vote up
def _handle_install(args, dependencies):
    if args.install and dependencies:
        if pip is None:
            raise ImportError("Bootstrapping Pulsar dependencies requires pip library.")

        pip.main(["install"] + dependencies)


# def _install_pulsar_in_virtualenv(venv):
#     if virtualenv is None:
#         raise ImportError("Bootstrapping Pulsar into a virtual environment, requires virtualenv.")
#     if IS_WINDOWS:
#         bin_dir = "Scripts"
#     else:
#         bin_dir = "bin"
#     virtualenv.create_environment(venv)
#     # TODO: Remove --pre on release.
#     subprocess.call([os.path.join(venv, bin_dir, 'pip'), 'install', "--pre", "pulsar-app"]) 
Example #2
Source File: virtualenv_utils.py    From idapkg with MIT License 6 votes vote down vote up
def _install_virtualenv(path):
    from hashlib import sha256
    from .downloader import download

    log.info('Downloading virtualenv from %r ...', VIRTUALENV_URL)
    data = download(VIRTUALENV_URL).read()
    assert sha256(data).hexdigest() == HASH, 'hash error... MITM?'

    import tempfile

    with tempfile.NamedTemporaryFile('wb', suffix=".zip", delete=False) as zf:
        zf.write(data)
        zf.flush()
        sys.path.insert(0, zf.name)
        import virtualenv

        with FixInterpreter():
            log.info('Creating environment using virtualenv...')
            virtualenv.create_environment(path, site_packages=True)
            log.info('Done!') 
Example #3
Source File: test_packaging.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def _setUp(self):
        path = self.useFixture(fixtures.TempDir()).path
        virtualenv.create_environment(path, clear=True)
        python = os.path.join(path, 'bin', 'python')
        command = [python] + self.pip_cmd + ['-U']
        if self.modules and len(self.modules) > 0:
            command.extend(self.modules)
            self.useFixture(base.CapturedSubprocess(
                'mkvenv-' + self._reason, command))
        self.addCleanup(delattr, self, 'path')
        self.addCleanup(delattr, self, 'python')
        self.path = path
        self.python = python
        return path, python 
Example #4
Source File: scaffold_test.py    From nefertari with Apache License 2.0 5 votes vote down vote up
def make_venv(self, directory):  # pragma: no cover
        import virtualenv
        from virtualenv import Logger
        logger = Logger([(Logger.level_for_integer(2), sys.stdout)])
        virtualenv.logger = logger
        virtualenv.create_environment(directory,
                                      site_packages=False,
                                      clear=False,
                                      unzip_setuptools=True) 
Example #5
Source File: conftest.py    From pip-api with Apache License 2.0 5 votes vote down vote up
def venv(tmpdir, isolate):
    """
    Return a virtual environment which is unique to each test function
    invocation created inside of a sub directory of the test function's
    temporary directory.
    """
    venv_location = os.path.join(str(tmpdir), "workspace", "venv")
    venv = virtualenv.create_environment(venv_location)

    os.environ["PIPAPI_PYTHON_LOCATION"] = os.path.join(venv_location, "bin", "python")

    yield venv

    del os.environ["PIPAPI_PYTHON_LOCATION"]
    shutil.rmtree(venv_location) 
Example #6
Source File: test_packaging.py    From keras-lambda with MIT License 5 votes vote down vote up
def _setUp(self):
        path = self.useFixture(fixtures.TempDir()).path
        virtualenv.create_environment(path, clear=True)
        python = os.path.join(path, 'bin', 'python')
        command = [python] + self.pip_cmd + ['-U']
        if self.modules and len(self.modules) > 0:
            command.extend(self.modules)
            self.useFixture(base.CapturedSubprocess(
                'mkvenv-' + self._reason, command))
        self.addCleanup(delattr, self, 'path')
        self.addCleanup(delattr, self, 'python')
        self.path = path
        self.python = python
        return path, python 
Example #7
Source File: test_integration.py    From exec-wrappers with MIT License 4 votes vote down vote up
def test_execute_virtualenv_wrappers(tmpdir, monkeypatch):
    import virtualenv

    # monkey patch the current dir to make sure we convert the relative paths
    # passed as arguments to absolute
    monkeypatch.chdir(tmpdir)
    virtualenv.create_environment(
        "virtual envs/test", no_setuptools=True, no_pip=True, no_wheel=True
    )

    if sys.platform != "win32":
        bin_dir = "virtual envs/test/bin"
    else:
        bin_dir = "virtual envs/test/Scripts"

    create_wrappers._main(
        [
            "-t",
            "virtualenv",
            "--virtual-env-dir",
            "virtual envs/test",
            "--bin-dir",
            bin_dir,
            "--dest-dir",
            "wrappers",
        ]
    )

    environ_from_activate = _environ_from_activate(
        _activate_virtualenv_script(), tmpdir
    )
    # Remove some variables we don't care
    if sys.platform != "win32":
        environ_from_activate.pop("PS1", None)
        environ_from_activate.pop("SHLVL")
    else:
        environ_from_activate.pop("_OLD_VIRTUAL_PATH")
        environ_from_activate.pop("_OLD_VIRTUAL_PROMPT")
        environ_from_activate.pop("PROMPT")
        environ_from_activate["PATH"] = os.path.normcase(environ_from_activate["PATH"])
        environ_from_activate["VIRTUAL_ENV"] = os.path.normcase(
            environ_from_activate["VIRTUAL_ENV"]
        )

    environ_from_wrapper = _environ_from_wrapper()
    if sys.platform != "win32":
        environ_from_wrapper.pop("SHLVL")
    else:
        environ_from_wrapper.pop("PROMPT")
        environ_from_wrapper["PATH"] = os.path.normcase(environ_from_wrapper["PATH"])
        environ_from_wrapper["VIRTUAL_ENV"] = os.path.normcase(
            environ_from_wrapper["VIRTUAL_ENV"]
        )

    assert environ_from_activate == environ_from_wrapper