From a84efd19c5c405098ea4e4be24efe488aba2eb7a Mon Sep 17 00:00:00 2001 From: Bill Little Date: Mon, 8 Feb 2021 23:29:03 +0000 Subject: [PATCH 1/4] add nox session conda list --- noxfile.py | 142 +++++++++++++++++++---------------------------------- 1 file changed, 50 insertions(+), 92 deletions(-) diff --git a/noxfile.py b/noxfile.py index fc6175bdf0..43006d6396 100644 --- a/noxfile.py +++ b/noxfile.py @@ -93,6 +93,52 @@ def cache_cartopy(session): ) +def prepare_venv(session): + """ + Create and cache the nox session conda environment, and additionally + provide conda environment package details and info. + + Note that, iris is installed into the environment using pip. + + Parameters + ---------- + session: object + A `nox.sessions.Session` object. + + Notes + ----- + See + - https://github.com/theacodes/nox/issues/346 + - https://github.com/theacodes/nox/issues/260 + + """ + if not venv_cached(session): + # Determine the conda requirements yaml file. + fname = f"requirements/ci/py{session.python.replace('.', '')}.yml" + # Back-door approach to force nox to use "conda env update". + command = ( + "conda", + "env", + "update", + f"--prefix={session.virtualenv.location}", + f"--file={fname}", + "--prune", + ) + session._run(*command, silent=True, external="error") + cache_venv(session) + + cache_cartopy(session) + session.install("--no-deps", "--editable", ".") + session.run("conda", "info") + session.run("conda", "list", f"--prefix={session.virtualenv.location}") + session.run( + "conda", + "list", + f"--prefix={session.virtualenv.location}", + "--explicit", + ) + + @nox.session def flake8(session): """ @@ -141,30 +187,8 @@ def tests(session): session: object A `nox.sessions.Session` object. - Notes - ----- - See - - https://github.com/theacodes/nox/issues/346 - - https://github.com/theacodes/nox/issues/260 - """ - if not venv_cached(session): - # Determine the conda requirements yaml file. - fname = f"requirements/ci/py{session.python.replace('.', '')}.yml" - # Back-door approach to force nox to use "conda env update". - command = ( - "conda", - "env", - "update", - f"--prefix={session.virtualenv.location}", - f"--file={fname}", - "--prune", - ) - session._run(*command, silent=True, external="error") - cache_venv(session) - - cache_cartopy(session) - session.install("--no-deps", "--editable", ".") + prepare_venv(session) session.run( "python", "-m", @@ -184,30 +208,8 @@ def gallery(session): session: object A `nox.sessions.Session` object. - Notes - ----- - See - - https://github.com/theacodes/nox/issues/346 - - https://github.com/theacodes/nox/issues/260 - """ - if not venv_cached(session): - # Determine the conda requirements yaml file. - fname = f"requirements/ci/py{session.python.replace('.', '')}.yml" - # Back-door approach to force nox to use "conda env update". - command = ( - "conda", - "env", - "update", - f"--prefix={session.virtualenv.location}", - f"--file={fname}", - "--prune", - ) - session._run(*command, silent=True, external="error") - cache_venv(session) - - cache_cartopy(session) - session.install("--no-deps", "--editable", ".") + prepare_venv(session) session.run( "python", "-m", @@ -226,30 +228,8 @@ def doctest(session): session: object A `nox.sessions.Session` object. - Notes - ----- - See - - https://github.com/theacodes/nox/issues/346 - - https://github.com/theacodes/nox/issues/260 - """ - if not venv_cached(session): - # Determine the conda requirements yaml file. - fname = f"requirements/ci/py{session.python.replace('.', '')}.yml" - # Back-door approach to force nox to use "conda env update". - command = ( - "conda", - "env", - "update", - f"--prefix={session.virtualenv.location}", - f"--file={fname}", - "--prune", - ) - session._run(*command, silent=True, external="error") - cache_venv(session) - - cache_cartopy(session) - session.install("--no-deps", "--editable", ".") + prepare_venv(session) session.cd("docs") session.run( "make", @@ -274,30 +254,8 @@ def linkcheck(session): session: object A `nox.sessions.Session` object. - Notes - ----- - See - - https://github.com/theacodes/nox/issues/346 - - https://github.com/theacodes/nox/issues/260 - """ - if not venv_cached(session): - # Determine the conda requirements yaml file. - fname = f"requirements/ci/py{session.python.replace('.', '')}.yml" - # Back-door approach to force nox to use "conda env update". - command = ( - "conda", - "env", - "update", - f"--prefix={session.virtualenv.location}", - f"--file={fname}", - "--prune", - ) - session._run(*command, silent=True, external="error") - cache_venv(session) - - cache_cartopy(session) - session.install("--no-deps", "--editable", ".") + prepare_venv(session) session.cd("docs") session.run( "make", From 61a0faca2496eb8b1b8e7762de618f6b0edda3f9 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Tue, 9 Feb 2021 00:38:20 +0000 Subject: [PATCH 2/4] add whatsnew entry --- docs/src/whatsnew/latest.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index fbb98cb1e3..37fa42c13f 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -94,6 +94,10 @@ This document explains the changes made to Iris for this release #. `@jamesp`_ updated a test to the latest numpy version (:pull:`3977`) +#. `@bjlittle`_ rationalised the ``noxfile.py``, and for each ``nox`` session + executed list the ``conda`` environment packages and environment info. + (:pull:`3990`) + .. comment Whatsnew author names (@github name) in alphabetical order. Note that, From 35132f9b09b2ddb79a0f7bbb8a2e50e34a266922 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Tue, 9 Feb 2021 01:38:47 +0000 Subject: [PATCH 3/4] review actions --- docs/src/whatsnew/latest.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 37fa42c13f..ed11f60719 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -94,9 +94,9 @@ This document explains the changes made to Iris for this release #. `@jamesp`_ updated a test to the latest numpy version (:pull:`3977`) -#. `@bjlittle`_ rationalised the ``noxfile.py``, and for each ``nox`` session - executed list the ``conda`` environment packages and environment info. - (:pull:`3990`) +#. `@bjlittle`_ rationalised the ``noxfile.py``, and added the ability for + each ``nox`` session to list its ``conda`` environment packages and + environment info. (:pull:`3990`) .. comment From cd5e4b36ea5e13535ad097ea41121fb55b45d3cf Mon Sep 17 00:00:00 2001 From: Bill Little Date: Tue, 9 Feb 2021 09:49:24 +0000 Subject: [PATCH 4/4] add conda list verbosity for nox --- .cirrus.yml | 10 ++++----- .../contributing_running_tests.rst | 8 +++++++ noxfile.py | 22 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 971bd3b81b..007bab403e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -107,7 +107,7 @@ linux_minimal_task: tests_script: - echo "[Resources]" > ${SITE_CFG} - echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG} - - nox --session tests + - nox --session tests -- --verbose # @@ -137,7 +137,7 @@ linux_task: - echo "[Resources]" > ${SITE_CFG} - echo "test_data_dir = ${IRIS_TEST_DATA_DIR}/test_data" >> ${SITE_CFG} - echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG} - - nox --session tests + - nox --session tests -- --verbose # @@ -167,7 +167,7 @@ gallery_task: - echo "[Resources]" > ${SITE_CFG} - echo "test_data_dir = ${IRIS_TEST_DATA_DIR}/test_data" >> ${SITE_CFG} - echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG} - - nox --session gallery + - nox --session gallery -- --verbose # @@ -201,7 +201,7 @@ doctest_task: - mkdir -p ${MPL_RC_DIR} - echo "backend : agg" > ${MPL_RC_FILE} - echo "image.cmap : viridis" >> ${MPL_RC_FILE} - - nox --session doctest + - nox --session doctest -- --verbose # @@ -224,4 +224,4 @@ link_task: - mkdir -p ${MPL_RC_DIR} - echo "backend : agg" > ${MPL_RC_FILE} - echo "image.cmap : viridis" >> ${MPL_RC_FILE} - - nox --session linkcheck + - nox --session linkcheck -- --verbose diff --git a/docs/src/developers_guide/contributing_running_tests.rst b/docs/src/developers_guide/contributing_running_tests.rst index 99ea4e831c..0fd9fa8486 100644 --- a/docs/src/developers_guide/contributing_running_tests.rst +++ b/docs/src/developers_guide/contributing_running_tests.rst @@ -175,6 +175,14 @@ For further `nox`_ command-line options:: nox --help +.. tip:: + For `nox`_ sessions that use the `conda`_ backend, you can use the ``-v`` or ``--verbose`` + flag to display the `nox`_ `conda`_ environment package details and environment info. + For example:: + + nox --session tests -- --verbose + + .. note:: `nox`_ will cache its testing environments in the `.nox` root ``iris`` project directory. diff --git a/noxfile.py b/noxfile.py index 43006d6396..b6f9480290 100644 --- a/noxfile.py +++ b/noxfile.py @@ -129,14 +129,20 @@ def prepare_venv(session): cache_cartopy(session) session.install("--no-deps", "--editable", ".") - session.run("conda", "info") - session.run("conda", "list", f"--prefix={session.virtualenv.location}") - session.run( - "conda", - "list", - f"--prefix={session.virtualenv.location}", - "--explicit", - ) + + # Determine whether verbose diagnostics have been requested + # from the command line. + verbose = "-v" in session.posargs or "--verbose" in session.posargs + + if verbose: + session.run("conda", "info") + session.run("conda", "list", f"--prefix={session.virtualenv.location}") + session.run( + "conda", + "list", + f"--prefix={session.virtualenv.location}", + "--explicit", + ) @nox.session