Skip to content

Commit

Permalink
Merge pull request #2 from mforbes/0.2
Browse files Browse the repository at this point in the history
Start branch 0.2.0. Only process .ipynb files unless option -f is used
  • Loading branch information
kynan committed Jan 24, 2016
2 parents bcf28dc + c7a3ce4 commit 8c098e0
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
20 changes: 20 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
0.1.x branch
------------
Maintained by Florian Rathgeber

* https://github.com/kynan/nbstripout

0.1.0:
* Based on Min RK's orginal but supports multiple versions of
IPython/Jupyter and also strips the execution count.


0.2.x branch
------------
Maintained by Michael McNeil Forbes

* https://github.com/mforbes/nbstripout

0.2.0:
* Only process .ipynb files unless -f flag is used
* Will process multiple files
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2015 Min RK, Florian Rathgeber, Michael McNeil Forbes

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 18 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ Based on https://gist.github.com/minrk/6176788.
Usage
=====

Strip output from IPython / Jupyter notebook (modifies the file in-place): ::
Strip output from IPython / Jupyter notebook (modifies the files in-place): ::

nbstripout FILE.ipynb
nbstripout FILE.ipynb [FILE2.ipynb ...]

Force processing of non ``.ipynb`` files:

nbstripout -f FILE.ipynb.bak

Use as part of a shell pipeline: ::

Expand All @@ -44,3 +48,15 @@ Set up a git filter using nbstripout as follows: ::
Create a file ``.gitattributes`` or ``.git/info/attributes`` with: ::

*.ipynb filter=nbstripout

Mercurial usage
===============

Mercurial does not have the equivalent of smudge filters. One can use
an encode/decode hook but this has some issues. An alternative
solution is to provide a set of commands that first run `nbstripout`,
then perform there operations. This is the approach of the
[`mmf-setup` package](https://pypi.python.org/pypi/mmf-setup) which
uses the 0.2.x branch of `nbstripout`:

* http://bitbucket.org/mforbes/mmf_setup
31 changes: 25 additions & 6 deletions nbstripout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
nbstripout <file.ipynb>
By default, nbstripout will only modify files ending in '.ipynb', to
process other files us the '-f' flag to force the application.
nbstripout -f <file.ipynb.bak>
Use as part of a shell pipeline: ::
FILE.ipynb | nbstripout > OUT.ipynb
Expand Down Expand Up @@ -120,12 +125,26 @@ def main():
sys.exit(1)
if sys.argv[1] in ['install', '--install']:
sys.exit(install())
filename = sys.argv[1]
with io.open(filename, 'r', encoding='utf8') as f:
nb = read(f, as_version=NO_CONVERT)
nb = strip_output(nb)
with io.open(filename, 'w', encoding='utf8') as f:
write(nb, f)

force = False
filenames = sys.argv[1:]
if filenames[0] in ['-f', '--force']:
force = True
filenames.pop(0)

for filename in filenames:
if not force and not filename.endswith('.ipynb'):
continue
try:
with io.open(filename, 'r', encoding='utf8') as f:
nb = read(f, as_version=NO_CONVERT)
nb = strip_output(nb)
with io.open(filename, 'w', encoding='utf8') as f:
write(nb, f)
except Exception:
# Ignore exceptions for non-notebook files.
print("Could not strip '{}'".format(filename))
raise
else:
write(strip_output(read(sys.stdin, as_version=NO_CONVERT)), sys.stdout)

Expand Down
29 changes: 24 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@
long_description = f.read()

setup(name='nbstripout',
version='0.1.0',
version='0.2.0',
author='Min RK',
author_email='[email protected]',
maintainer='Florian Rathgeber',
maintainer_email='[email protected]',
url='https://github.com/kynan/nbstripout',

# 0.1 branch
# maintainer='Florian Rathgeber',
# maintainer_email='[email protected]',
# url='https://github.com/kynan/nbstripout',

# 0.2 branch
maintainer='Michael McNeil Forbes',
maintainer_email='[email protected]',
url='https://github.com/mforbes/nbstripout',

license="License :: OSI Approved :: MIT License",

description='Strips outputs from Jupyter and IPython notebooks',
long_description=long_description,
py_modules=['nbstripout'],
entry_points={
'console_scripts': [
'nbstripout = nbstripout:main'
]
})
},

classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Framework :: IPython",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Topic :: Software Development :: Version Control",
])

0 comments on commit 8c098e0

Please sign in to comment.