Skip to content

Commit

Permalink
Merge branch 'main' into henryiii/feat/emptylist
Browse files Browse the repository at this point in the history
  • Loading branch information
DiddiLeija committed Dec 23, 2021
2 parents 02ede6f + c4376af commit 2191d94
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/usage.rst
Expand Up @@ -329,7 +329,8 @@ Controlling color output
By default, Nox will output colorful logs if you're using in an interactive
terminal. However, if you are redirecting ``stderr`` to a file or otherwise
not using an interactive terminal, or the environment variable ``NO_COLOR`` is
set, nox will output in plaintext.
set, nox will output in plaintext. If this is not set, and ``FORCE_COLOR`` is
present, color will be forced.

You can manually control Nox's output using the ``--nocolor`` and ``--forcecolor`` flags.

Expand Down
2 changes: 1 addition & 1 deletion nox/_options.py
Expand Up @@ -463,7 +463,7 @@ def _session_completer(
"--forcecolor",
"--force-color",
group=options.groups["reporting"],
default=False,
default=lambda: "FORCE_COLOR" in os.environ,
action="store_true",
help="Force color output, even if stdout is not an interactive terminal.",
),
Expand Down
22 changes: 18 additions & 4 deletions nox/sessions.py
Expand Up @@ -360,7 +360,11 @@ def _run(
return nox.command.run(args, env=env, paths=self.bin_paths, **kwargs)

def conda_install(
self, *args: str, auto_offline: bool = True, **kwargs: Any
self,
*args: str,
auto_offline: bool = True,
channel: Union[str, Sequence[str]] = "",
**kwargs: Any,
) -> None:
"""Install invokes `conda install`_ to install packages inside of the
session's environment.
Expand All @@ -369,7 +373,7 @@ def conda_install(
session.conda_install('pandas')
session.conda_install('numpy', 'scipy')
session.conda_install('--channel=conda-forge', 'dask==2.1.0')
session.conda_install('dask==2.1.0', channel='conda-forge')
To install packages from a ``requirements.txt`` file::
Expand All @@ -387,6 +391,10 @@ def conda_install(
# Install in editable mode.
session.install('-e', '.', '--no-deps')
You can specify a conda channel using `channel=`; a falsy value will
not change the current channels. You can specify a list of channels if
needed.
Additional keyword args are the same as for :meth:`run`.
.. _conda install:
Expand All @@ -413,12 +421,18 @@ def conda_install(
if "silent" not in kwargs:
kwargs["silent"] = True

extraopts = () # type: Tuple[str, ...]
extraopts = [] # type: List[str]
if auto_offline and venv.is_offline():
logger.warning(
"Automatically setting the `--offline` flag as conda repo seems unreachable."
)
extraopts = ("--offline",)
extraopts.append("--offline")

if channel:
if isinstance(channel, str):
extraopts.append(f"--channel={channel}")
else:
extraopts += [f"--channel={c}" for c in channel]

self._run(
venv.conda_cmd,
Expand Down
5 changes: 5 additions & 0 deletions noxfile.py
Expand Up @@ -23,6 +23,11 @@

ON_WINDOWS_CI = "CI" in os.environ and platform.system() == "Windows"

# Skip 'conda_tests' if user doesn't have conda installed
nox.options.sessions = ["tests", "cover", "blacken", "lint", "docs"]
if shutil.which("conda"):
nox.options.sessions.append("conda_tests")


def is_python_version(session, version):
if not version.startswith(session.python):
Expand Down
17 changes: 14 additions & 3 deletions tests/test_sessions.py
Expand Up @@ -385,7 +385,12 @@ def test_conda_install_not_a_condaenv(self):
)
@pytest.mark.parametrize("offline", [False, True], ids="offline={}".format)
@pytest.mark.parametrize("conda", ["conda", "mamba"], ids=str)
def test_conda_install(self, auto_offline, offline, conda):
@pytest.mark.parametrize(
"channel",
["", "conda-forge", ["conda-forge", "bioconda"]],
ids=["default", "conda-forge", "bioconda"],
)
def test_conda_install(self, auto_offline, offline, conda, channel):
runner = nox.sessions.SessionRunner(
name="test",
signatures=["test"],
Expand All @@ -405,8 +410,14 @@ class SessionNoSlots(nox.sessions.Session):
session = SessionNoSlots(runner=runner)

with mock.patch.object(session, "_run", autospec=True) as run:
args = ("--offline",) if auto_offline and offline else ()
session.conda_install("requests", "urllib3", auto_offline=auto_offline)
args = ["--offline"] if auto_offline and offline else []
if channel and isinstance(channel, str):
args.append(f"--channel={channel}")
else:
args += [f"--channel={c}" for c in channel]
session.conda_install(
"requests", "urllib3", auto_offline=auto_offline, channel=channel
)
run.assert_called_once_with(
conda,
"install",
Expand Down
1 change: 1 addition & 0 deletions tests/test_virtualenv.py
Expand Up @@ -233,6 +233,7 @@ def test_condaenv_bin_windows(make_conda):
assert [dir_.strpath, dir_.join("Scripts").strpath] == venv.bin_paths


@pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")
def test_condaenv_(make_conda):
venv, dir_ = make_conda()
assert not venv.is_offline()
Expand Down

0 comments on commit 2191d94

Please sign in to comment.