Skip to content

Commit

Permalink
Rename print_cmd to logged_command, move it to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaretnikov committed Jan 28, 2024
1 parent 6aa7d74 commit f79b198
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import pathlib
import subprocess
import sys
import tempfile
import warnings

import yaml
from conda_store_server import action, schema
from conda_store_server.action.utils import logged_command


def get_installer_platform():
Expand All @@ -26,15 +26,6 @@ def action_generate_constructor_installer(
installer_dir: pathlib.Path,
version: str,
):
# Helpers
def print_cmd(cmd, **kwargs):
context.log.info(f"Running command: {' '.join(cmd)}")
context.log.info(
subprocess.check_output(
cmd, stderr=subprocess.STDOUT, encoding="utf-8", **kwargs
)
)

def write_file(filename, s):
with open(filename, "w") as f:
context.log.info(f"{filename}:\n{s}")
Expand All @@ -46,7 +37,7 @@ def write_file(filename, s):
"constructor",
"--help",
]
print_cmd(command, timeout=10)
logged_command(context, command, timeout=10)
except FileNotFoundError:
warnings.warn(
"Installer generation requires constructor: https://github.com/conda/constructor"
Expand Down Expand Up @@ -124,6 +115,6 @@ def write_file(filename, s):
get_installer_platform(),
str(tmp_dir),
]
print_cmd(command)
logged_command(context, command)

return installer_filename
14 changes: 4 additions & 10 deletions conda-store-server/conda_store_server/action/generate_lockfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json
import os
import pathlib
import subprocess
import typing

import yaml
from conda_lock.conda_lock import run_lock
from conda_store_server import action, conda_utils, schema
from conda_store_server.action.utils import logged_command


@action.action
Expand All @@ -25,17 +25,11 @@ def action_solve_lockfile(
with environment_filename.open("w") as f:
json.dump(specification.dict(), f)

def print_cmd(cmd):
context.log.info(f"Running command: {' '.join(cmd)}")
context.log.info(
subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding="utf-8")
)

# The info command can be used with either mamba or conda
print_cmd([conda_command, "info"])
logged_command(context, [conda_command, "info"])
# The config command is not supported by mamba
print_cmd(["conda", "config", "--show"])
print_cmd(["conda", "config", "--show-sources"])
logged_command(context, ["conda", "config", "--show"])
logged_command(context, ["conda", "config", "--show-sources"])

# conda-lock ignores variables defined in the specification, so this code
# gets the value of CONDA_OVERRIDE_CUDA and passes it to conda-lock via
Expand Down
10 changes: 10 additions & 0 deletions conda-store-server/conda_store_server/action/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import subprocess


def logged_command(context, command, **kwargs):
context.log.info(f"Running command: {' '.join(command)}")
context.log.info(
subprocess.check_output(
command, stderr=subprocess.STDOUT, encoding="utf-8", **kwargs
)
)

0 comments on commit f79b198

Please sign in to comment.