Skip to content

Commit

Permalink
Merge pull request #578 from rfbgo/output_stderr_enum
Browse files Browse the repository at this point in the history
Update output capture semantics to not always capture stderr
  • Loading branch information
douglasjacobsen authored Jul 26, 2024
2 parents e799176 + 8cc6cd1 commit 7b691ca
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/ramble/ramble/appkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

from ramble.util.file_util import get_file_path

from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE
7 changes: 4 additions & 3 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from ramble.language.application_language import ApplicationMeta
from ramble.language.shared_language import SharedMeta, register_builtin, register_phase
from ramble.error import RambleError
from ramble.util.output_capture import output_mapper

from enum import Enum

Expand Down Expand Up @@ -1057,9 +1058,9 @@ def _define_commands(
if cmd_conf.redirect:
out_log = self.expander.expand_var(cmd_conf.redirect, exec_vars)
output_operator = cmd_conf.output_capture
redirect = f' {output_operator} "{out_log}"'
if ramble.config.get("config:shell") in ["bash", "sh"]:
redirect += " 2>&1"

redirect_mapper = output_mapper()
redirect = redirect_mapper.generate_out_string(out_log, output_operator)

if cmd_conf.run_in_background:
bg_cmd = " &"
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/modkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
import ramble.language.modifier_language
from ramble.language.modifier_language import *
from ramble.language.shared_language import *
from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

from ramble.util.file_util import get_file_path
2 changes: 1 addition & 1 deletion lib/ramble/ramble/pkgmankit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
import ramble.language.package_manager_language
from ramble.language.package_manager_language import *
from ramble.language.shared_language import *
from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

from ramble.software_environments import ExternalEnvironment
3 changes: 2 additions & 1 deletion lib/ramble/ramble/schema/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ramble.schema.types
import ramble.schema.variables
from ramble.util.output_capture import OUTPUT_CAPTURE


custom_executables_def = {
Expand All @@ -28,7 +29,7 @@
"use_mpi": False,
"redirect": "{log_file}",
"variables": {},
"output_capture": ramble.schema.types.OUTPUT_CAPTURE.DEFAULT,
"output_capture": OUTPUT_CAPTURE.DEFAULT,
},
"properties": union_dicts(
{
Expand Down
8 changes: 0 additions & 8 deletions lib/ramble/ramble/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

"""Base types for building schema files from"""


class OUTPUT_CAPTURE:
STDERR = "2>"
STDOUT = ">>"
ALL = "&>"
DEFAULT = STDOUT


string_or_num_list = [{"type": "string"}, {"type": "number"}]

string_or_num = {"anyOf": string_or_num_list}
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/util/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import ramble.error

from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

import spack.util.executable
from spack.util.path import system_path_filter
Expand Down
33 changes: 33 additions & 0 deletions lib/ramble/ramble/util/output_capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from enum import Enum


class OUTPUT_CAPTURE(Enum):
STDOUT = 0
STDERR = 1
ALL = 2
DEFAULT = 2


class output_mapper:
def __init__(self):
self.map = {
OUTPUT_CAPTURE.STDOUT: ">>",
OUTPUT_CAPTURE.STDERR: "2>>",
OUTPUT_CAPTURE.ALL: ">>",
}
self.SUFFIX = "2>&1"

def generate_out_string(self, out_log, output_operator):
redirect_str = f' {self.map.get(output_operator, output_operator)} "{out_log}"'
if output_operator is OUTPUT_CAPTURE.ALL:
redirect_str += f" {self.SUFFIX}"

return redirect_str

0 comments on commit 7b691ca

Please sign in to comment.