-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT: review and refactor package #37
Conversation
Thanks for submitting your first pull request! You are awesome! 🤗 |
Codecov Report
@@ Coverage Diff @@
## master #37 +/- ##
==========================================
- Coverage 95.83% 93.34% -2.49%
==========================================
Files 4 6 +2
Lines 384 436 +52
==========================================
+ Hits 368 407 +39
- Misses 16 29 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
… reference support
Fix the following test collections
|
|
@AakashGfude this is getting close. Integrating with the When you have time would you mind reviewing the The main changes are I have worked directly with the If you could also take a look at |
Pretty hefty PR 😬. Will carefully inspect and also add the changes you asked for. |
thanks @AakashGfude I should add that full I will also add some docs etc. but would value some initial feedback. |
@mmcky are there particular questions that you have, where you'd like people to focus their reviews? |
thanks @choldgraf I was planning to get @AakashGfude to review (as a first round) then I will apply some final lessons learnt and update the docs. I was then planning to open up for wider review at that stage with some specific questions around |
<p>This is a third reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text 1</span></a>.</p> | ||
<p>This is a fourth reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text 1</span></a>.</p> | ||
<p>This is a fifth reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span>some text Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span></span></a>.</p> | ||
<p>This is a fourth reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text Exercise</span></a>.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AakashGfude this is one of the numref
fixtures I am referring to
sphinx_exercise/post_transforms.py
Outdated
title = node.children[0] | ||
if isinstance(title, exercise_title): | ||
node_number = get_node_number(app, node, "exercise") | ||
updated_title = exercise_title() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AakashGfude perhaps this new exercise_title
node is detached from the parent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmcky it does get attached to the admonition node
later here:
node.children[0] = updated_title |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it replaces the child for sure -- but that isn't necessarily the same as
node += updated_title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a quick look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmcky adding visit, depart exercise_title support for latex here:
sphinx-exercise/sphinx_exercise/__init__.py
Line 179 in 84a3d2a
app.add_node(exercise_title, html=(visit_exercise_title, depart_exercise_title)) |
encountered title node not in section, topic, table, ' 'admonition or sidebar
error, but needs some formatting for proper latex output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it get's detached as the node metadata isn't retained 😮💨
> sphinx-exercise/.tox/py38/lib/python3.8/site-packages/sphinx_exercise/post_transforms.py(25)resolve_enumerated_exercise_node_title()
-> title = node.children[0]
(Pdb) node.children[0]
<exercise_title: <#text: 'Exercise'><exercise_subtitle...>>
(Pdb) node.children[0].parent
<exercise_enumerable_node "exercise-1": <exercise_title...><section...>>
(Pdb) c
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB continue (IO-capturing resumed) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> sphinx-exercise/.tox/py38/lib/python3.8/site-packages/sphinx_exercise/post_transforms.py(39)resolve_enumerated_exercise_node_title()
-> return node
(Pdb) node.children[0].parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fixed by ebf67f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @mmcky
sphinx_exercise/post_transforms.py
Outdated
exercise_target = app.env.sphinx_exercise_registry[node.get("target_label")]["node"] | ||
title = node.children[0] | ||
if isinstance(title, solution_title): | ||
new_title = solution_title() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AakashGfude similarly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly for this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding visit, depart exercise_title support for latex here:
@AakashGfude indeed. All the LaTex
elements are current raise NotImplementedError
for title and subtitle visit/depart.
@AakashGfude I think this is looking pretty good. I have opened a test build here on a real-world test case |
|
|
@AakashGfude I think we have now resolved the integration with |
@mmcky Looking good to me. |
@chrisjsewell @choldgraf we have given our best shot at integrating closely with sphinx in this PR. The focus of the re-write has been to alter the nodes in the We choose to integrate with the |
@mmcky I think the pop_index is not required anymore https://github.com/executablebooks/sphinx-exercise/pull/37/files#diff-77185f1ed5e85402b80a05b1e8610ab9f33a9188e54393f8bdb3868594d0b5deR99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick pass through, with a focus on the docs since you mentioned that the main goal here was maintainability. I think in general it looks good to go (though didn't have time to do a deep dive since this changes a ton of things). The main comment I have is to make sure that the docstrings and documented well-enough that a person who isn't familiar with the codebase could orient themselves relatively quickly. There are likely a few places where there's assumptions being made and missing information because you all know a lot more about how the package works already :-) it might also be helpful to have a short explainer of the structure of this repository, so that others know how it is implemented, where to look for things in the codebase etc. I don't think any of that needs to block this PR, but there could be some low-hanging fruit there if you want to give it a shot
sphinx_exercise/post_transforms.py
Outdated
node.children[0] = inline | ||
|
||
# TODO: Is it possible for the target_node not to be resolved? | ||
# if not target_node.resolved_title: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this "if" statement that's commented out intentionally left in? When will it be un-commented?
sphinx_exercise/post_transforms.py
Outdated
|
||
def resolve_solution_title(app, node, exercise_node): | ||
""" | ||
Resolve Solution Nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use slightly more descriptive docstrings here and in general? If somebody had never seen this codebase before, they should know:
- What does this function/class do at a high level
- What are the outputs and inputs
- Any gotchas or extra information that can help them understand what's going on
These don't need to be as well documented as more user-facing functions but I think it's helpful to at least have this minimal info in there
logger = logging.getLogger(__name__) | ||
|
||
|
||
def build_reference_node(app, target_node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing docstring - please add docstrings to all functions
# Test Node Functions | ||
|
||
|
||
def is_exercise_node(node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these functions are straightforward enough they don't need a docstring IMO
sphinx_exercise/nodes.py
Outdated
@@ -2,149 +2,171 @@ | |||
sphinx_exercise.nodes | |||
~~~~~~~~~~~~~~~~~~~~~ | |||
|
|||
Enumerable and unenumerable nodes | |||
Sphinx Exercise Nodes | |||
|
|||
:copyright: Copyright 2020 by the QuantEcon team, see AUTHORS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a note that in general we've been using "Executable Books Project" for copyright
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure -- just didn't review that when we transferred to EBP :-). 👍
thanks for the review @choldgraf will do a final pass on docs and internal comments + docstrings today. I'l be adding a section with lessons learnt on the design of the package (which can serve as a source for a more general set of notes about writing a sphinx package for EBP) |
|
thanks @choldgraf and @AakashGfude I think this is good to be merged now. I'll merge tomorrow morning unless any further comments. |
This is a refactor PR to make this extension more maintainable.
It introduces:
exercise
andsolution
directive code (rather than inheriting from the same base) which lowers cognitive load when working with the objects.env.exercise_list
toenv.sphinx_exercise_registry
as it was confusing to haveexercise
andsolution
nodes going into an object calledexercise_list
.post_transforms
intopost_transforms.py
directives
andpost_transforms
by introducingexercise-
andsolution-
titles and subtitles which enables targeted processes within the node (rather than have custom string modification code as before). This integrates more closely with sphinx and let's sphinx translators do the translation work from theast
exercise
admonitions wasn't trivial as it requires recastingnumbered
references in apost_transform
to a custom node to enable processing at the translator layer, as it wasn't possible to integrate with the base sphinx latex translator to include custom title text.Exercises:
Solutions:
Links to Solutions: