-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from DeanLight/stop_filtering_magics
Stop filtering magics
- Loading branch information
Showing
2 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import inspect | ||
from nbdev.processors import FilterDefaults | ||
from nbdev.quarto import nbdev_docs | ||
|
||
monkey_patch_procs = """ | ||
# already_appended_marker | ||
all_procs = FilterDefaults().procs() | ||
def new_procs(self): | ||
procs = [proc for proc in all_procs if proc.__name__ != 'clean_magics'] | ||
return procs | ||
FilterDefaults.procs = new_procs | ||
""" | ||
|
||
def check_appeneded_marker(file_path # Path to nbdev.processors.py file | ||
) -> bool: # True if we already appended new_procs, False otherwise | ||
try: | ||
with open(file_path, 'r') as file: | ||
lines = file.readlines() | ||
|
||
for line in lines: | ||
if 'already_appended_marker' in line: | ||
return True | ||
return False | ||
|
||
except FileNotFoundError: | ||
print(f"File {file_path} not found!") | ||
|
||
if __name__ == '__main__': | ||
module_file_path = inspect.getfile(FilterDefaults) | ||
|
||
# Check if we already appended new_procs | ||
if not check_appeneded_marker(module_file_path): | ||
with open(module_file_path, 'a') as f: | ||
f.write(monkey_patch_procs) | ||
|
||
nbdev_docs() |