How to use the nox.virtualenv.VirtualEnv function in nox

To help you get started, we’ve selected a few nox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theacodes / nox / tests / test_virtualenv.py View on Github external
def factory(*args, **kwargs):
        location = tmpdir.join("venv")
        venv = nox.virtualenv.VirtualEnv(location.strpath, *args, **kwargs)
        return (venv, location)
github theacodes / nox / tests / test_sessions.py View on Github external
def test_install_non_default_kwargs(self):
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test"],
            func=mock.sentinel.func,
            global_config=_options.options.namespace(posargs=mock.sentinel.posargs),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
        runner.venv.env = {}

        class SessionNoSlots(nox.sessions.Session):
            pass

        session = SessionNoSlots(runner=runner)

        with mock.patch.object(session, "_run", autospec=True) as run:
            session.install("requests", "urllib3", silent=False)
            run.assert_called_once_with(
                "pip", "install", "requests", "urllib3", silent=False, external="error"
            )
github theacodes / nox / tests / test_sessions.py View on Github external
            ("nox.virtualenv.VirtualEnv.create", None, nox.virtualenv.VirtualEnv),
            (
                "nox.virtualenv.VirtualEnv.create",
                "virtualenv",
                nox.virtualenv.VirtualEnv,
            ),
            ("nox.virtualenv.VirtualEnv.create", "venv", nox.virtualenv.VirtualEnv),
            ("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv),
        ],
    )
    def test__create_venv_options(self, create_method, venv_backend, expected_backend):
        runner = self.make_runner()
        runner.func.python = "coolpython"
        runner.func.reuse_venv = True
        runner.func.venv_backend = venv_backend

        with mock.patch(create_method, autospec=True) as create:
github theacodes / nox / nox / sessions.py View on Github external
def _create_venv(self):
        if not self.config.virtualenv:
            self.venv = ProcessEnv()
            self._should_install_deps = False
            return

        self.venv = VirtualEnv(
            _normalize_path(
                self.global_config.envdir, self.signature or self.name),
            interpreter=self.config.interpreter,
            reuse_existing=(
                self.config.reuse_existing_virtualenv or
                self.global_config.reuse_existing_virtualenvs))
        self._should_install_deps = self.venv.create()
github theacodes / nox / nox / sessions.py View on Github external
To install packages from a ``requirements.txt`` file::

            session.install('-r', 'requirements.txt')
            session.install('-r', 'requirements-dev.txt')

        To install the current package::

            session.install('.')
            # Install in editable mode.
            session.install('-e', '.')

        Additional keyword args are the same as for :meth:`run`.

        .. _pip: https://pip.readthedocs.org
        """
        if not isinstance(self.virtualenv, (CondaEnv, VirtualEnv)):
            raise ValueError(
                "A session without a virtualenv can not install dependencies."
            )
        if not args:
            raise ValueError("At least one argument required to install().")

        if "silent" not in kwargs:
            kwargs["silent"] = True

        self._run("pip", "install", *args, external="error", **kwargs)
github theacodes / nox / nox / sessions.py View on Github external
def _create_venv(self):
        if self.func.python is False:
            self.venv = ProcessEnv()
            return

        path = _normalize_path(self.global_config.envdir, self.friendly_name)
        reuse_existing = (
            self.func.reuse_venv or self.global_config.reuse_existing_virtualenvs
        )

        if not self.func.venv_backend or self.func.venv_backend == "virtualenv":
            self.venv = VirtualEnv(
                path, interpreter=self.func.python, reuse_existing=reuse_existing
            )
        elif self.func.venv_backend == "conda":
            self.venv = CondaEnv(
                path, interpreter=self.func.python, reuse_existing=reuse_existing
            )
        elif self.func.venv_backend == "venv":
            self.venv = VirtualEnv(
                path,
                interpreter=self.func.python,
                reuse_existing=reuse_existing,
                venv=True,
            )
        else:
            raise ValueError(
                "Expected venv_backend one of ('virtualenv', 'conda', 'venv'), but got '{}'.".format(
github theacodes / nox / nox / sessions.py View on Github external
path = _normalize_path(self.global_config.envdir, self.friendly_name)
        reuse_existing = (
            self.func.reuse_venv or self.global_config.reuse_existing_virtualenvs
        )

        if not self.func.venv_backend or self.func.venv_backend == "virtualenv":
            self.venv = VirtualEnv(
                path, interpreter=self.func.python, reuse_existing=reuse_existing
            )
        elif self.func.venv_backend == "conda":
            self.venv = CondaEnv(
                path, interpreter=self.func.python, reuse_existing=reuse_existing
            )
        elif self.func.venv_backend == "venv":
            self.venv = VirtualEnv(
                path,
                interpreter=self.func.python,
                reuse_existing=reuse_existing,
                venv=True,
            )
        else:
            raise ValueError(
                "Expected venv_backend one of ('virtualenv', 'conda', 'venv'), but got '{}'.".format(
                    self.func.venv_backend
                )
            )

        self.venv.create()
github scrapd / scrapd / tasks.py View on Github external
def get_venv(venv):
    """
    Return `Path` objects from the venv.

    :param str venv: venv name
    :return: the venv `Path`, the `bin` folder `Path` within the venv, and if specified, the `Path` object of the
        activate script within the venv.
    :rtype: a tuple of 3 `Path` objects.
    """
    location = Path(venv)
    venv = VirtualEnv(location.resolve())
    venv_bin = Path(venv.bin)
    activate = venv_bin / 'activate'
    return venv, venv_bin, activate