dev-cafe / parselglossy

Generic input parsing library, speaking in tongues.
https://parselglossy.readthedocs.io
MIT License
7 stars 2 forks source link

Chain of dependencies #76

Closed stigrj closed 4 years ago

stigrj commented 5 years ago

Description

The following chain of dependencies currently does not work if neither bar nor baz is set:

keywords:
  - name: foo                                                             
    type: float                                                                  
    docstring: "Foo"
  - name: bar
    type: float
    default: "user['foo']"
    docstring: "Bar"
  - name: baz
    type: float
    default: "user['bar']"
    docstring: "Baz"

It seems baz is first set equal to the string "user['foo']" (which is a type mismatch), before bar is set to the value of foo. Related to issue #73.

bast commented 5 years ago

In a discussion with Stig and Roberto we are aiming at this:

robertodr commented 4 years ago

One solution we discussed is to reshuffle the tree (as extracted from template.yml) into a directed acyclic graph (DAG) using NetworkX. If there are circular dependencies, then there is no DAG and hence we error out.

Reminder to actually test for circular dependencies.

bast commented 4 years ago

To check my understanding of the problem: We want to detect cyclic dependencies and abort at the generate step, right? So this is an error that only the code developer using parselglossy can see, but never the user of the code that uses the generated parser. Correct?

robertodr commented 4 years ago

Correct. These are issues that happen in the template.yml specification and can be detected separately from any parsing, in https://github.com/dev-cafe/parselglossy/blob/dd57c64a278b0ba837743ab00fe24321cfda3342/parselglossy/validation.py#L89

I think that cycles can happen when:

  1. A keyword's default depends on another keyword's default (Stig's example) From the template one can get a "simplified" dictionary with view_by_default.
  2. A keyword's predicates depend on another keyword's value. From the template one can get a "simplified" dictionary with view_by_predicates.
bast commented 4 years ago

Thanks! I experimented a bit with networkx and agree that this is the way to go and should not be too difficult.

bast commented 4 years ago

Working on it ...

robertodr commented 4 years ago

:hammer_and_wrench:

bast commented 4 years ago

But right now the generator does not call any of these validators AFAICS - is this by design or by history?

robertodr commented 4 years ago

It checks whether the template is valid with is_template_valid: https://github.com/dev-cafe/parselglossy/blob/master/parselglossy/api.py#L172-L179

bast commented 4 years ago

Thanks! I was working in the wrong function (validate_from_dicts).

bast commented 4 years ago

It's only now that I understand that these are really two issues. One is to sort the graph, and the other is to detect whether the graph is sortable.

robertodr commented 4 years ago

96 has been merged which solves the "degenerate" case of dependency chains. We'll be working on the "non-degenerate" case soon :hammer_and_wrench: