Skip to content

Commit

Permalink
Small tidy in units
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Jul 5, 2023
1 parent 0ed2286 commit 2f42948
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions fortdepend/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ def __init__(
contents = f.read()

preprocessor = FortranPreprocessor()
macros = macros or {}

if macros:
if isinstance(macros, dict):
for k, v in macros.items():
preprocessor.define(f"{k} {v}")
else:
if not isinstance(macros, list):
macros = [macros]
for macro in macros:
if "=" in macro:
key, value = macro.split("=")
preprocessor.define(f"{key} {value}")
else:
preprocessor.define(macro)
if isinstance(macros, dict):
for k, v in macros.items():
preprocessor.define(f"{k} {v}")
else:
if not isinstance(macros, list):
macros = [macros]
for macro in macros:
if "=" in macro:
key, value = macro.split("=")
preprocessor.define(f"{key} {value}")
else:
preprocessor.define(macro)

if cpp_includes:
if not isinstance(cpp_includes, list):
Expand Down Expand Up @@ -104,8 +104,9 @@ def get_modules(self, contents, macros=None):

if found_units:
if (len(found_units) != len(starts)) or (len(starts) != len(ends)):
error_string = f"Unmatched start/end of modules in {self.filename} ({len(starts)} begins/{len(ends)} ends)"
raise ValueError(error_string)
raise ValueError(
f"Unmatched start/end of modules in {self.filename} ({len(starts)} begins/{len(ends)} ends)"
)
for unit, start, end in zip(found_units, starts, ends):
name = unit.group("modname")
mod = FortranModule(
Expand Down

0 comments on commit 2f42948

Please sign in to comment.