Skip to content

Commit 0791056

Browse files
committed
fix dict issue, delimiter causing break in line, and file remains opened
1 parent a607e75 commit 0791056

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

concore.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,22 @@ def safe_literal_eval(filename, defaultValue):
157157
# Parameter Parsing
158158
# ===================================================================
159159
def parse_params(sparams: str) -> dict:
160-
"""Parse semicolon-delimited key=value pairs into a dictionary.
161-
162-
Args:
163-
sparams: String in format "key1=value1;key2=value2"
164-
165-
Returns:
166-
Dictionary with parsed key-value pairs
167-
"""
168160
params = {}
169161
if not sparams:
170162
return params
171163

172-
for item in sparams.split(";"):
164+
s = sparams.strip()
165+
166+
#full dict literal
167+
if s.startswith("{") and s.endswith("}"):
168+
try:
169+
val = literal_eval(s)
170+
if isinstance(val, dict):
171+
return val
172+
except (ValueError, SyntaxError):
173+
pass
174+
175+
for item in s.split(";"):
173176
if "=" in item:
174177
key, value = item.split("=", 1) # split only once
175178
key=key.strip()
@@ -187,7 +190,7 @@ def parse_params(sparams: str) -> dict:
187190
sparams_path = concore_params_file
188191
if os.path.exists(sparams_path):
189192
with open(sparams_path, "r") as f:
190-
sparams = f.read()
193+
sparams = f.read().strip()
191194
if sparams: # Ensure sparams is not empty
192195
# Windows sometimes keeps quotes
193196
if sparams[0] == '"' and sparams[-1] == '"': #windows keeps "" need to remove

concoredocker.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ def parse_params(sparams):
3030
if not sparams:
3131
return params
3232

33+
s = sparams.strip()
34+
35+
# full dict literal
36+
if s.startswith("{") and s.endswith("}"):
37+
try:
38+
val = literal_eval(s)
39+
if isinstance(val, dict):
40+
return val
41+
except (ValueError, SyntaxError):
42+
pass
43+
3344
# keep backward compatibility: comma-separated params
34-
for item in sparams.split(","):
45+
for item in s.split(","):
3546
if "=" in item:
3647
key, value = item.split("=", 1)
3748
key = key.strip()
@@ -46,7 +57,8 @@ def parse_params(sparams):
4657
return params
4758

4859
try:
49-
sparams = open(concore_params_file).read().strip()
60+
with open(concore_params_file, "r") as f:
61+
sparams = f.read().strip()
5062

5163
if sparams and sparams[0] == '"': # windows keeps quotes
5264
sparams = sparams[1:]

0 commit comments

Comments
 (0)