Check for missing colon in input command

这个提交包含在:
nmannall
2024-10-04 17:27:29 +01:00
父节点 1ad7ed64da
当前提交 8e40fcaad3

查看文件

@@ -48,7 +48,9 @@ def process_python_include_code(inputfile, usernamespace):
"""
# Strip out any newline characters and comments that must begin with double hashes
inputlines = [line.rstrip() for line in inputfile if (not line.startswith("##") and line.rstrip("\n"))]
inputlines = [
line.rstrip() for line in inputfile if (not line.startswith("##") and line.rstrip("\n"))
]
# Rewind input file in preparation for any subsequent reading function
inputfile.seek(0)
@@ -74,7 +76,8 @@ def process_python_include_code(inputfile, usernamespace):
x += 1
if x == len(inputlines):
logger.exception(
"Cannot find the end of the Python code " + "block, i.e. missing #end_python: command."
"Cannot find the end of the Python code "
+ "block, i.e. missing #end_python: command."
)
raise SyntaxError
# Compile code for faster execution
@@ -281,6 +284,15 @@ def check_cmd_names(processedlines, checkessential=True):
lindex = 0
while lindex < len(processedlines):
cmd = processedlines[lindex].split(":")
# Check the command name and parameters were both found
if len(cmd) < 2:
logger.error(
f"Unable to identify command and parameters in '{processedlines[lindex].strip()}'."
" There must be a colon ':' between the command name and parameters."
)
exit(1)
cmdname = cmd[0]
cmdparams = cmd[1]
@@ -289,7 +301,9 @@ def check_cmd_names(processedlines, checkessential=True):
# are no parameters for a command, e.g. for #taguchi:
if " " not in cmdparams[0] and len(cmdparams.strip("\n")) != 0:
logger.exception(
"There must be a space between the command name " + "and parameters in " + processedlines[lindex]
"There must be a space between the command name "
+ "and parameters in "
+ processedlines[lindex]
)
raise SyntaxError
@@ -312,7 +326,9 @@ def check_cmd_names(processedlines, checkessential=True):
if singlecmds[cmdname] is None:
singlecmds[cmdname] = cmd[1].strip(" \t\n")
else:
logger.exception("You can only have a single instance of " + cmdname + " in your model")
logger.exception(
"You can only have a single instance of " + cmdname + " in your model"
)
raise SyntaxError
elif cmdname in multiplecmds:
@@ -384,7 +400,9 @@ def parse_hash_commands(scene):
for key, value in sorted(usernamespace.items()):
if key != "__builtins__":
uservars += f"{key}: {value}, "
logger.info(f"Constants/variables used/available for Python scripting: " + f"{{{uservars[:-2]}}}\n")
logger.info(
f"Constants/variables used/available for Python scripting: " + f"{{{uservars[:-2]}}}\n"
)
# Write a file containing the input commands after Python or include
# file commands have been processed