- Small CLI program capable of cleaning
.ipynband.pysources. - Apply tools on python code like
- Apply equally to entire
.pyor.ipynbfiles. - Additionally, can clear all
.ipynbcell outputs and execution counts (squeeze those diffs!).
Via git pip:
pip install git+https://github.com/KwatME/clean_ipynbVia source:
git clone https://github.com/KwatME/clean_ipynb
cd clean_ipynb
pip install .Clean .ipynb source:
clean_ipynb a_single_notebook.ipynbOr .py source:
clean_ipynb a_single_script.pyOr an entire directory recursively:
clean_ipynb <some_dir_containing_py_ipynb_source>Or a list of files and directories:
clean_ipynb a_single_script.py <some_dir_containing_py_ipynb_source>Clean without specific features if necessary (uses all features by default):
clean_ipynb <some_dir_containing_py_ipynb_source> --no-black --no-autoflakeA full list of parameters can be found via:
clean_ipynb --help- Added support for generic tooling i.e, use any tool for python code
- Make sure that tool when used along with arguments doesn't output to stderr when no errors have occured. Ex:
blackdoes this, we need to use-qflag to stop it from doing so - It is reqired that the
commandwhen passed withargstakes input from stdin & returns output in stdout, else your file wont get updated by tool - Use of generic is supported by using
JSON-jor--tools-jsonflag is used to providejson- This flag takes both
<path/to/json>and alsojsonas string{...}
- Generic tooling has by default:
blackenabledisortenabledyapfdisabled
- Important to note:
- Generic Tools mentioned in
jsonare done in order, so you can decide which order to run formatters (this is enabled through ordered dicts)- This ensures that your tools are used in the order you specified (Except for
black&isortwhich if active, will always be run at first in orderblack,isort)
- This ensures that your tools are used in the order you specified (Except for
- If conflicting configurations are specified in flags &
json(Ex: for which formatter to useblackoryapf), the one injsontakes precedence
- Generic Tools mentioned in
{
"<name_of_your_choice_for_tool>": {
"command": "<command>",
"args": ["<arg1>", "<arg2>", ...],
"active": <boolean_incicating_whether_to_use_this_tool>
},
"<other_tool>": {
...
},
...
}Ex: If you want to use autopep8 instead of black
{
"black": {
"command": "black",
"args": ["-q", "-"],
"active": false
},
"autopep8": {
"command": "autopep8",
"args": [],
"active": true
}
}- Unit tests. Null parameter, invalid parameter edge cases etc.
-
Reimplement sub-command arg parsing. Parse specific black/autoflake/isort args to main CLI.(Done with 3.0, by using JSON String / File as input) - Remove subprocess calls. Reach into subprograms, natively use without subprocess calls.
- Autoflake for ipynb sources. Keep module imports which are only used in other cells. This will require awareness of all code cells at once for the application of autoflake. Current workaround: Disables autoflake (by hardcoding) for Jupyter notebooks, and
--no-ipynbfor Python files (to avoid repeat operations when applied to identical inputs for both sets of flags). - Read from standard input and write to standard output. Exhibit behaviour analogous to other tools such as black which do this if
-is used as a filename. -
Handle errors of pipes gracefully Use try to catch errors