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..734452a7c 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 and when viewing the build logs.