Skip to content
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

Adds incremental module creator to magic #883

Merged
merged 2 commits into from
May 5, 2024
Merged

Conversation

skrawcz
Copy link
Collaborator

@skrawcz skrawcz commented May 3, 2024

The idea is simple. Allow one to build up a module easily and quickly. This is useful when explaining a concept.

Example use:

%%incr_cell_to_module -m doc_pipeline -i 5 --display

The idea is that you can partition creating a module over multiple cells. The ONLY CAVEAT is that you maintain a unique identifier (int or string) for each cell so that they can are distinct; i.e. it's possible to override an earlier cell if you use the same identifier. Note: we use the sorted set of identifiers and build the module up in order of that. This is probably an unused feature, since we expect most people to logically increment the identifier and order things correctly top to bottom.

There are some utility methods to help reset state. Otherwise I duplicate some logic, since it wasn't easy to refactor. I centralized logic where it made sense.

Changes

  • adds new incr_cell_to_module cell magic.
  • adds new print_module line magic to print what's created
  • adds new reset_module line magic to reset an incremental module.

How I tested this

  • locally

Notes

  • the incremental path is

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

The idea is simple. Allow one to build up a module easily and quickly.
This is useful when explaining a concept.

Example use:
```
%%incr_cell_to_module -m doc_pipeline -i 5 --display
```
The idea is that you can partition creating a module
over multiple cells. The ONLY CAVEAT is that you maintain
a unique identifier (int or string) for each cell so that they
can are distinct; i.e. it's possible to override an earlier cell
if you use the same identifier. Note: we use the sorted
set of identifiers and build the module up in order of that.
This is probably an unused feature, since we expect most
people to logically increment the identifier and order things
correctly top to bottom.

There are some utility methods to help reset state.
Otherwise I duplicate some logic, since it wasn't easy to refactor.
I centralized logic where it made sense, and then removed
rebuild drivers from incremental -- we can always add it in.
@skrawcz skrawcz requested a review from elijahbenizzy May 3, 2024 22:18
Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one small comment but its not introduced here

@@ -260,6 +248,157 @@ def insert_module(self, line):
# insert source code as text in the next cell
self.shell.set_next_input(header + module_source, replace=False)

@magic_arguments() # needed on top to enable parsing
@argument(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll refactor to match jupyter v2 once we're there

Propagates that to other functions.
@skrawcz skrawcz merged commit 7e20827 into main May 5, 2024
23 checks passed
@skrawcz skrawcz deleted the add_incremental_magic branch May 5, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants