Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive-paper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quantum Tinkerer
adaptive-paper
Commits
9db81040
Commit
9db81040
authored
5 years ago
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
add ipynb filter
parent
a24ca0d8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipynb_filter.py
+34
-0
34 additions, 0 deletions
ipynb_filter.py
with
34 additions
and
0 deletions
ipynb_filter.py
0 → 100644
+
34
−
0
View file @
9db81040
#!/usr/bin/env python3
# `ipynb_filter.py`:
# This is a git filters that strips out the outputs and
# meta data of a Jupyer notebook using `nbconvert`.
# Execute the following line in order to activate this filter:
# python ipynb_filter.py
#
# The following line should be in `.gitattributes`:
# *.ipynb filter=ipynb_filter
#
# from github.com/basnijholt/ipynb_git_filters
from
nbconvert.preprocessors
import
Preprocessor
class
RemoveMetadata
(
Preprocessor
):
def
preprocess
(
self
,
nb
,
resources
):
nb
.
metadata
=
{
"
language_info
"
:
{
"
name
"
:
"
python
"
,
"
pygments_lexer
"
:
"
ipython3
"
}}
return
nb
,
resources
if
__name__
==
'
__main__
'
:
# The filter is getting activated
import
os
git_cmd
=
'
git config filter.ipynb_filter.clean
"
jupyter nbconvert --to notebook --config ipynb_filter.py --stdin --stdout
"'
os
.
system
(
git_cmd
)
else
:
# This script is used as config
c
.
Exporter
.
preprocessors
=
[
RemoveMetadata
]
c
.
ClearOutputPreprocessor
.
enabled
=
True
c
.
ClearOutputPreprocessor
.
remove_metadata_fields
=
[
"
deletable
"
,
"
editable
"
,
"
collapsed
"
,
"
scrolled
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment