From 437cc96067ec56dfb99eddfe2750e7cf984aa7e1 Mon Sep 17 00:00:00 2001 From: pdmurray Date: Sun, 12 May 2024 22:55:41 -0700 Subject: [PATCH 1/2] Add `conda config` warning docs/message; add duration log for actions --- .../conda_store_server/_internal/action/base.py | 7 +++++++ .../_internal/action/generate_lockfile.py | 7 +++++++ conda-store-server/tests/test_actions.py | 11 ++++++++--- .../conda-store/explanations/conda-concepts.md | 12 ++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/conda-store-server/conda_store_server/_internal/action/base.py b/conda-store-server/conda_store_server/_internal/action/base.py index 64ffac605..1e4d948ff 100644 --- a/conda-store-server/conda_store_server/_internal/action/base.py +++ b/conda-store-server/conda_store_server/_internal/action/base.py @@ -4,6 +4,7 @@ import logging import subprocess import tempfile +import time import typing import uuid @@ -27,8 +28,14 @@ def wrapper(*args, stdout=None, stderr=None, **kwargs): # enter temporary directory stack.enter_context(utils.chdir(tmpdir)) + start_time = time.monotonic() + # run function and store result action_context.result = f(action_context, *args, **kwargs) + action_context.log.info( + f"Action {f.__name__} completed in {time.monotonic() - start_time:.3f} s." + ) + return action_context return wrapper diff --git a/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py b/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py index 7ecdd8592..6c79a2def 100644 --- a/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py +++ b/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py @@ -27,6 +27,13 @@ def action_solve_lockfile( with environment_filename.open("w") as f: json.dump(specification.dict(), f) + context.log.info( + "Note that the output of `conda config --show` displayed below only reflects " + "settings in the conda configuration file, which might be overridden by " + "variables required to be set by conda-store via the environment. Overridden " + f"settings: CONDA_FLAGS={conda_flags}" + ) + # The info command can be used with either mamba or conda logged_command(context, [conda_command, "info"]) # The config command is not supported by mamba diff --git a/conda-store-server/tests/test_actions.py b/conda-store-server/tests/test_actions.py index de3ed5f6b..1657379cd 100644 --- a/conda-store-server/tests/test_actions.py +++ b/conda-store-server/tests/test_actions.py @@ -21,6 +21,8 @@ def test_action_decorator(): + """Test that the action decorator captures stdout/stderr and logs correctly.""" + @action.action def test_function(context): print("stdout") @@ -48,10 +50,13 @@ def test_function(context): return pathlib.Path.cwd() context = test_function() - assert ( - context.stdout.getvalue() - == "stdout\nstderr\nsubprocess\nsubprocess_stdout\nsubprocess_stderr\nlog\n" + + stdout = context.stdout.getvalue() + assert stdout.startswith( + "stdout\nstderr\nsubprocess\nsubprocess_stdout\nsubprocess_stderr\nlog\n" ) + assert re.search(r"Action test_function completed in \d+\.\d+ s.\n$", stdout) + assert context.stderr.getvalue() == "subprocess_stderr_no_redirect\n" # test that action direction is not the same as outside function assert context.result != pathlib.Path.cwd() diff --git a/docusaurus-docs/conda-store/explanations/conda-concepts.md b/docusaurus-docs/conda-store/explanations/conda-concepts.md index c326ba769..cf670c761 100644 --- a/docusaurus-docs/conda-store/explanations/conda-concepts.md +++ b/docusaurus-docs/conda-store/explanations/conda-concepts.md @@ -80,3 +80,15 @@ could be updated the next minute the same solve for the same [conda-docs-environments]: https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/environments.html + +## Understanding `conda config` and how it relates to conda-store + +Because conda-store needs to configure some parts of conda without modifying +the user's conda configuration file, internally conda-store sets some conda +configuration variables using environment variables. The impact of this is that +if a user tries to print their conda configuration with `conda config`, some of +the configuration settings displayed by that command will not reflect the values +that are actually used by conda-store. In particular, `conda-store` internally +sets `CONDA_FLAGS=--strict-channel-priority`, overriding the channel priority in +the conda configuration file. Please keep this in mind when using `conda config` +to inspect your conda configuration. From 1260dcc440ecc632c3297fb1b42d443b3f3c57f6 Mon Sep 17 00:00:00 2001 From: Peyton Murray Date: Wed, 3 Jul 2024 11:21:45 -0700 Subject: [PATCH 2/2] Update docusaurus-docs/conda-store/explanations/conda-concepts.md Co-authored-by: Kim Pevey --- docusaurus-docs/conda-store/explanations/conda-concepts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus-docs/conda-store/explanations/conda-concepts.md b/docusaurus-docs/conda-store/explanations/conda-concepts.md index cf670c761..734452a7c 100644 --- a/docusaurus-docs/conda-store/explanations/conda-concepts.md +++ b/docusaurus-docs/conda-store/explanations/conda-concepts.md @@ -91,4 +91,4 @@ the configuration settings displayed by that command will not reflect the values that are actually used by conda-store. In particular, `conda-store` internally sets `CONDA_FLAGS=--strict-channel-priority`, overriding the channel priority in the conda configuration file. Please keep this in mind when using `conda config` -to inspect your conda configuration. +to inspect your conda configuration and when viewing the build logs.