This Engineering Notebook post discusses how I created @jupytext and its companion, @language jupytext. As always, please feel free to ignore this post.
@jupytext
I created @jupytext to solve a specific problem: synchronizing .ipynb files with their corresponding .py pseudo files. Long experience has taught me that synchronizing files is difficult or impossible.
@jupytext was no stroke of genius. It is a natural extension of @clean. The new code practically wrote itself. I added only the following:
- A wrapper class for the jupytext api.
- Two new methods: at.read/writeOneAtJupytextNode.
These methods merely extend Leo's existing @<file> machinery.
- A one-line hook in the code that detects changes to external files.
No wonder the entire project went smoothly.
@language jupytext
In contrast, @language jupytext required arduous work. The inspiration came late and required a complete re-imaging of:
- the colorizer's api.
- how the colorizer delegates work.
I set myself an absolute requirement. The work could only add methods to the JEditColorizer class. No substantial changes to existing methods were permissible.
Two Ahas appeared only after many doomed attempts:
Aha: The new pattern matcher should use a predicate instead of a long list of kwargs. Doh!
Aha: The new pattern pattern matcher must use a secondary colorizer main loop instead of delegation. The colorizer's delegation machinery can not possibly work in a line-oriented context.
This second Aha immediately lead me to this code in jedit.restart_match_span_delegated_line:
n = self.currentState()
self.init()
self.language = self.delegated_lines_language
self.mainLoop(n, s)
The final code looks so simple. You cannot imagine how complex my early attempts were.
Summary
@jupytext is a straightforward extension of Leo's @<file> machinery. The inspiration came first. I needed no other invention. The code practically wrote itself.
In contrast, @language jupytext required arduous work. The inspiration came late. Significant invention was required. Perhaps nobody else could have done what I did. I'm proud of this work.
Edward
P.S. Another ENB, coming soon, will discuss the implications of @language jupytext. It's possible to re-imagine Leo's syntax coloring safely. There will be minimal changes to Leo's colorizer and no changes to any file in the leo/modes directory.
EKR
This Engineering Notebook post discusses how I created @jupytext and its companion, @language jupytext
.
...