change category.py loading to deal with nutty cwd() issues and encourage on-demand computation

This commit is contained in:
Neale Pickett 2017-02-02 17:56:10 +00:00
parent 846643dcb0
commit 9266adab9a
1 changed files with 4 additions and 3 deletions

View File

@ -112,7 +112,7 @@ class Puzzle:
def read_directory(self, path): def read_directory(self, path):
try: try:
fn = os.path.join(path, "puzzle.py") fn = os.path.abspath(os.path.join(path, "puzzle.py"))
loader = importlib.machinery.SourceFileLoader('puzzle_mod', fn) loader = importlib.machinery.SourceFileLoader('puzzle_mod', fn)
puzzle_mod = loader.load_module() puzzle_mod = loader.load_module()
except FileNotFoundError: except FileNotFoundError:
@ -260,9 +260,10 @@ class Category:
if os.path.exists(os.path.join(path, 'category.py')): if os.path.exists(os.path.join(path, 'category.py')):
with pushd(path): with pushd(path):
loader = importlib.machinery.SourceFileLoader('catmod', 'category.py') fn = os.path.abspath('category.py')
loader = importlib.machinery.SourceFileLoader('category', fn)
self.catmod = loader.load_module() self.catmod = loader.load_module()
self.pointvals.extend(self.catmod.points) self.pointvals.extend(self.catmod.pointvals())
else: else:
for fpath in glob.glob(os.path.join(path, "[0-9]*")): for fpath in glob.glob(os.path.join(path, "[0-9]*")):
pn = os.path.basename(fpath) pn = os.path.basename(fpath)