1
0
Fork 0
mirror of synced 2024-06-27 02:20:36 +12:00

shield pwd import for windows

This commit is contained in:
Nick Sweeting 2021-04-24 03:51:38 -04:00
parent 3db77fd1a2
commit 79e19ecd47

View file

@ -25,7 +25,6 @@ import os
import io
import re
import sys
import pwd
import json
import getpass
import platform
@ -49,6 +48,15 @@ from .config_stubs import (
ConfigDefaultDict,
)
SYSTEM_USER = getpass.getuser() or os.getlogin()
try:
import pwd
SYSTEM_USER = pwd.getpwuid(os.geteuid()).pw_name or SYSTEM_USER
except ModuleNotFoundError:
# pwd is only needed for some linux systems, doesn't exist on windows
pass
############################### Config Schema ##################################
CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = {
@ -313,7 +321,7 @@ ALLOWED_IN_OUTPUT_DIR = {
DYNAMIC_CONFIG_SCHEMA: ConfigDefaultDict = {
'TERM_WIDTH': {'default': lambda c: lambda: shutil.get_terminal_size((100, 10)).columns},
'USER': {'default': lambda c: pwd.getpwuid(os.geteuid()).pw_name or getpass.getuser() or os.getlogin()},
'USER': {'default': lambda c: SYSTEM_USER},
'ANSI': {'default': lambda c: DEFAULT_CLI_COLORS if c['USE_COLOR'] else {k: '' for k in DEFAULT_CLI_COLORS.keys()}},
'PACKAGE_DIR': {'default': lambda c: Path(__file__).resolve().parent},