Skip to content

Commit 335f719

Browse files
Expose hostname() function in labscript_profile
Since it is being removed from labscript_suite.labconfig /labscript-suite/blacs#68 will require this.
1 parent d7230c5 commit 335f719

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

labscript_profile/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
LABSCRIPT_SUITE_PROFILE = None
2828

2929

30+
def hostname():
31+
if sys.platform == 'darwin':
32+
return check_output(['scutil', '--get', 'LocalHostName']).decode('utf8').strip()
33+
else:
34+
return socket.gethostname()
35+
36+
3037
def default_labconfig_path():
3138
if LABSCRIPT_SUITE_PROFILE is None:
3239
return None
33-
if sys.platform == 'darwin':
34-
cmd = ['scutil', '--get', 'LocalHostName']
35-
hostname = check_output(cmd).decode('utf8').strip()
36-
else:
37-
hostname = socket.gethostname()
38-
labconfig = LABSCRIPT_SUITE_PROFILE / 'labconfig' / f'{hostname}.ini'
39-
return labconfig
40+
return LABSCRIPT_SUITE_PROFILE / 'labconfig' / f'{hostname()}.ini'
4041

4142

4243
def add_userlib_and_pythonlib():
@@ -46,18 +47,17 @@ def add_userlib_and_pythonlib():
4647
labscript_utils, since we dont' want to import something like labscript_utils every
4748
time the interpreter starts up"""
4849
labconfig = default_labconfig_path()
49-
if labconfig is None or not os.path.exists(labconfig):
50-
return
51-
config = ConfigParser()
52-
config.read(labconfig)
53-
for option in ['userlib', 'pythonlib']:
54-
try:
55-
paths = config.get('DEFAULT', option).split(',')
56-
except (NoSectionError, NoOptionError):
57-
paths = []
58-
for path in paths:
59-
if os.path.exists(path):
60-
sys.path.append(path)
50+
if labconfig is not None and labconfig.exists():
51+
config = ConfigParser()
52+
config.read(labconfig)
53+
for option in ['userlib', 'pythonlib']:
54+
try:
55+
paths = config.get('DEFAULT', option).split(',')
56+
except (NoSectionError, NoOptionError):
57+
paths = []
58+
for path in paths:
59+
if os.path.exists(path):
60+
sys.path.append(path)
6161

6262

6363
def add_development_directories():

0 commit comments

Comments
 (0)