Skip to content

Commit

Permalink
fix get_user_display_name on docker (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-schick authored Jan 31, 2023
1 parent 7229bd2 commit 405352f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions mara_pipelines/logging/pipeline_events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Events that are emitted during pipeline execution"""

import datetime
import json
import os
import getpass

import enum
import typing as t
Expand All @@ -10,7 +11,7 @@


class PipelineEvent(Event):
def __init__(self, node_path: [str]) -> None:
def __init__(self, node_path: t.List[str]) -> None:
"""
Base class for events that are emitted during a pipeline run.
Expand All @@ -23,7 +24,7 @@ def __init__(self, node_path: [str]) -> None:


class RunStarted(PipelineEvent):
def __init__(self, node_path: [str],
def __init__(self, node_path: t.List[str],
start_time: datetime.datetime,
pid: int,
is_root_pipeline: bool = False,
Expand Down Expand Up @@ -51,7 +52,7 @@ def __init__(self, node_path: [str],


class RunFinished(PipelineEvent):
def __init__(self, node_path: [str],
def __init__(self, node_path: t.List[str],
end_time: datetime.datetime,
succeeded: bool,
interactively_started: bool = False) -> None:
Expand All @@ -71,7 +72,7 @@ def __init__(self, node_path: [str],


class NodeStarted(PipelineEvent):
def __init__(self, node_path: [str], start_time: datetime.datetime, is_pipeline: bool) -> None:
def __init__(self, node_path: t.List[str], start_time: datetime.datetime, is_pipeline: bool) -> None:
"""
A task run started.
Args:
Expand All @@ -85,7 +86,7 @@ def __init__(self, node_path: [str], start_time: datetime.datetime, is_pipeline:


class NodeFinished(PipelineEvent):
def __init__(self, node_path: [str], start_time: datetime.datetime, end_time: datetime.datetime,
def __init__(self, node_path: t.List[str], start_time: datetime.datetime, end_time: datetime.datetime,
is_pipeline: bool, succeeded: bool) -> None:
"""
A run of a task or pipeline finished.
Expand All @@ -110,7 +111,7 @@ class Format(enum.EnumMeta):
VERBATIM = 'verbatim'
ITALICS = 'italics'

def __init__(self, node_path: [str], message: str,
def __init__(self, node_path: t.List[str], message: str,
format: Format = Format.STANDARD, is_error: bool = False) -> None:
"""
Some text output occurred.
Expand All @@ -137,9 +138,11 @@ def get_user_display_name(interactively_started: bool) -> t.Optional[str]:
Patch if you have more sophisticated needs.
"""
import os
if 'MARA_RUN_USER_DISPLAY_NAME' in os.environ:
return os.environ.get('MARA_RUN_USER_DISPLAY_NAME')
if not interactively_started:
return None
return os.environ.get('SUDO_USER') or os.environ.get('USER') or os.getlogin()
try:
return os.environ.get('SUDO_USER') or os.environ.get('USER') or getpass.getuser()
except Exception: # pylint: disable=W0703
return None

0 comments on commit 405352f

Please # to comment.