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

VER: 0.1.1: Ignore errors if not an ".ipynb" file #1

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .hgtags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2434b1429da1f8965915003d889f56dde92e2b72 0.1.2
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = f.read()

setup(name='nbstripout',
version='0.1.0',
version='0.1.2',
author='Min RK',
author_email='[email protected]',
maintainer='Florian Rathgeber',
Expand Down