Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix import error in metadata: fails on systems without pwd #2152

Merged
merged 1 commit into from
Dec 6, 2022
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
15 changes: 13 additions & 2 deletions ctapipe/io/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

"""
import os
import pwd
import uuid
import warnings
from collections import OrderedDict
Expand Down Expand Up @@ -65,6 +64,18 @@ def convert(value):
return value


def _get_user_name():
"""return the logged in user's name, as a fall-back if none is specified"""
try:
import pwd

return pwd.getpwuid(os.getuid()).pw_gecos
except ImportError:
# the pwd module is not available on some non-unix systems (Windows), so
# here we just fall back to a default name
return "Unknown User"


class Contact(Configurable):
"""Contact information"""

Expand All @@ -76,7 +87,7 @@ class Contact(Configurable):
def default_name(self):
"""if no name specified, use the system's user name"""
try:
return pwd.getpwuid(os.getuid()).pw_gecos
return _get_user_name()
except RuntimeError:
return ""

Expand Down