kalekundert / stepwise

Modular, command-line scientific protocols
GNU General Public License v3.0
3 stars 0 forks source link

Don't check footnotes until protocol is printed? #39

Open kalekundert opened 3 years ago

kalekundert commented 3 years ago

Right now, I think footnote checking is skipped if there are no footnotes. But this doesn't work well with stepwise.load(), which could pull in a protocol with footnotes. For example:

p = stepwise.Protocol()

# Ok that [1] isn't defined yet, b/c protocol has no footnotes.
p += "Step with footnote [1]"

# Note that the footnotes in this protocol will be automatically renumbered.
p += stepwise.load('protocol with footnote [2]')

# This will trigger an error, because the protocol has footnotes but [3]
# is not yet defined:
p += "Step with footnote [3]"

# The current workaround is this:
p.footnotes[3] = "Footnote..."
p += "Step with footnote [3]"

My first impression is that it might be better to defer all checks until the protocol is rendered, but I'll have to think more carefully about how feasible that is.

kalekundert commented 3 years ago

protocol.add_footnotes() is another way to avoid this issue.

kalekundert commented 3 years ago

There is a fundamental difference between adding a step and merging in a new protocol; most of the logic in Protocol.merge doesn't apply when just adding a step.

But, by allowing steps with undefined footnotes to be added to the protocol, it opens the possibility of those footnotes getting messed up if another protocol with footnotes is merged before the undefined footnotes are defined. For example:

p = stepwise.Protocol()
p += "Step with footnote [1]"

p += stepwise.load('protocol with footnote [1]')

p.footnotes[1] = "Footnote..."

Because merge() resolves footnotes based on the kys in the footnotes dictionary, it won't notice that the first step and the loaded protocol both define the same footnote. So when the footnote is finally defined, it overwrites the footnote from the protocol. Thinking about this, maybe I actually want to be even more strict about footnotes than I am currently...