Support multiple types of comments in utils.get_hashflags

This commit is contained in:
jesopo 2018-10-07 11:24:13 +01:00
parent af39136f83
commit 681866339c

View file

@ -128,15 +128,23 @@ def export(setting, value):
return module return module
return _export_func return _export_func
COMMENT_TYPES = ["#", "//"]
def get_hashflags(filename): def get_hashflags(filename):
hashflags = {} hashflags = {}
with io.open(filename, mode="r", encoding="utf8") as f: with io.open(filename, mode="r", encoding="utf8") as f:
for line in f: for line in f:
line = line.strip("\n") line = line.strip("\n")
if not line.startswith("#"): found = False
for comment_type in COMMENT_TYPES:
if line.startswith(comment_type):
line = line.replace(comment_type, "", 1).lstrip()
found = True
break
if not found:
break break
elif line.startswith("#--"): elif line.startswith("--"):
hashflag, sep, value = line[3:].partition(" ") hashflag, sep, value = line[2:].partition(" ")
hashflags[hashflag] = value if sep else None hashflags[hashflag] = value if sep else None
return hashflags.items() return hashflags.items()