Skip to content

Commit

Permalink
Add conda config warning docs/message; add duration log for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
peytondmurray committed Jun 25, 2024
1 parent fcac335 commit 437cc96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import subprocess
import tempfile
import time
import typing
import uuid

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions conda-store-server/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions docusaurus-docs/conda-store/explanations/conda-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@ could be updated the next minute the same solve for the same

<!-- External links -->
[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.

0 comments on commit 437cc96

Please sign in to comment.