Commit e02d725b49e852f3aa8a5a944a1b726b651ca665

Authored by Miguel Barão
1 parent 861d9ae5
Exists in master and in 1 other branch dev

Check if dependencies exist as nodes.

Showing 1 changed file with 15 additions and 4 deletions   Show diff stats
aprendizations/learnapp.py
... ... @@ -40,6 +40,11 @@ async def bcrypt_hash_gen(new_pw):
40 40  
41 41  
42 42 # ============================================================================
  43 +class LearnException(Exception):
  44 + pass
  45 +
  46 +
  47 +# ============================================================================
43 48 # LearnApp - application logic
44 49 # ============================================================================
45 50 class LearnApp(object):
... ... @@ -256,8 +261,8 @@ class LearnApp(object):
256 261 #
257 262 # Edges are obtained from the deps defined in the YAML file for each topic.
258 263 # ------------------------------------------------------------------------
259   - def populate_graph(self, conffile):
260   - logger.info(f'Populating graph from: {conffile}')
  264 + def populate_graph(self, conffile: str):
  265 + logger.info(f'Populating graph from: {conffile}...')
261 266 config = load_yaml(conffile) # course configuration
262 267  
263 268 # default attributes that apply to the topics
... ... @@ -275,7 +280,13 @@ class LearnApp(object):
275 280  
276 281 g.add_nodes_from(topics.keys())
277 282 for tref, attr in topics.items():
278   - g.add_edges_from((d, tref) for d in attr.get('deps', []))
  283 + for d in attr.get('deps', []):
  284 + if d not in g.nodes():
  285 + logger.error(f'Topic "{tref}" depends on "{d}" but the '
  286 + f'latter does not exist')
  287 + raise LearnException()
  288 + else:
  289 + g.add_edge(d, tref)
279 290  
280 291 t = g.node[tref] # get current topic node
281 292 t['type'] = attr.get('type', 'topic')
... ... @@ -302,7 +313,7 @@ class LearnApp(object):
302 313 # Buils dictionary of question factories
303 314 # ------------------------------------------------------------------------
304 315 def make_factory(self):
305   - logger.info('Building questions factory')
  316 + logger.info('Building questions factory...')
306 317 factory = {} # {'qref': QFactory()}
307 318 g = self.deps
308 319 for tref in g.nodes():
... ...