Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix get_user_display_name on docker #90

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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