Exemple #1
0
 def run(self, args, in_venv=True):
     """Runs a command. By default, the command runs within the
     environment."""
     return Command(args=args,
                    env=self.env if in_venv else None,
                    silent=True,
                    path=self.bin if in_venv else None).run()
Exemple #2
0
    def run(self, *args, **kwargs):
        """
        Schedule a command or function to in the session.

        Commands must be specified as a list of strings, for example::

            session.run('py.test', '-k', 'fast', 'tests/')
            session.run('flake8', '--import-order-style=google')

        You **can not** just pass everything as one string. For example, this
        **will not work**::

            session.run('py.test -k fast tests/')

        You can set environment variables for the command using ``env``::

            session.run(
                'bash', '-c', 'echo $SOME_ENV',
                env={'SOME_ENV': 'Hello'})

        You can also tell nox to treat non-zero exit codes as success using
        ``success_codes``. For example, if you wanted to treat the ``py.test``
        "tests discovered, but none selected" error as success::

            session.run(
                'py.test', '-k', 'not slow',
                success_codes=[0, 5])

        :param env: A dictionary of environment variables to expose to the
            command. By default, all evironment variables are passed.
        :type env: dict or None
        :param bool silent: Silence command output, unless the command fails.
            ``False`` by default.
        :param success_codes: A list of return codes that are considered
            successful. By default, only ``0`` is considered success.
        :type success_codes: list, tuple, or None

        Functions can be scheduled just by passing the function and any args,
        just like :func:`functools.partial`::

            session.run(shutil.rmtree, 'docs/_build')

        """
        if not args:
            raise ValueError('At least one argument required to run().')
        if callable(args[0]):
            self._commands.append(
                FunctionCommand(args[0], args[1:], kwargs))
        else:
            self._commands.append(Command(args=args, **kwargs))