Missing weapons now raise a warning, and recursive directory parsing.

In order to avoid parsing arbitrary python files encountered during
directory recursion, ``makesheets`` now checks each python file for a
string listing the *dungeonsheets_version* before trying to import the
character file.
This commit is contained in:
Mark Wolfman
2020-11-08 14:14:50 -06:00
parent debbfc5ae1
commit ccf886b8ae
10 changed files with 153 additions and 57 deletions
+4 -7
View File
@@ -697,13 +697,10 @@ class Character():
try:
NewWeapon = findattr(weapons, weapon)
except AttributeError:
try:
findattr(spells, weapon)
except AttributeError:
raise AttributeError(f'Weapon "{weapon}" is not defined')
else:
warnings.warn(f"Ignoring spell {weapon} listed as weapon.")
return
warnings.warn(f"Unknown weapon '{weapon}'. Please add it to ``weapons.py`` "
"or submit an issue: https://github.com/canismarko/dungeon-sheets/issues",
RuntimeWarning)
return
weapon_ = NewWeapon(wielder=self)
elif issubclass(weapon, weapons.Weapon):
weapon_ = weapon(wielder=self)