diff --git a/5-UsefulConceptsAndSTL/1-ErrorHandling.ipynb b/5-UsefulConceptsAndSTL/1-ErrorHandling.ipynb index a3600d3597e84b7a25d56dc69b7a5789ece9f331..0a9e065256f8e7945aadb7a5d467005a74baa2f1 100644 --- a/5-UsefulConceptsAndSTL/1-ErrorHandling.ipynb +++ b/5-UsefulConceptsAndSTL/1-ErrorHandling.ipynb @@ -313,9 +313,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": true - }, + "metadata": {}, "outputs": [], "source": [ "#include <iostream>\n", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9176c27397b46e43958492ccba96bd1173a85e79..c6043f93c314d7c3af5065ae21dbccb1d47c742b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,8 @@ -All contributions are welcome. +# Contribution guide -# Git hook +All contributions are welcome, but please read this first. + +## Git hook If you intend to contribute, please install first the pre-commit hook: @@ -8,9 +10,9 @@ If you intend to contribute, please install first the pre-commit hook: cp Scripts/pre-commit .git/hooks/pre-commit ```` -This hook ensure no notebook with executed cells is committed. +This hook clears executed cells when committing a notebook. -# Workflow +## Workflow The project is led through an integration manager workflow, so when you have a contribution to share, just open a merge request. diff --git a/README.md b/README.md index bc21dd9c1df5e6bc93a8fe7a47c3e42ed550849d..ce36fdc67b86be5954e5a0a96f59bfad2e49fe10 100644 --- a/README.md +++ b/README.md @@ -120,3 +120,4 @@ A link to a BinderHub instance is given at the top of the project page; foresee ## For maintainers Informations related to CI are [here](CI.md). +All contributions are welcome, but please read the [contribution guide](CONTRIBUTING.md) first. diff --git a/Scripts/check_no_executed_cell.py b/Scripts/check_no_executed_cell.py deleted file mode 100644 index 93ca3dbf6ec23b8926deeb699c634c2d28b8b9b6..0000000000000000000000000000000000000000 --- a/Scripts/check_no_executed_cell.py +++ /dev/null @@ -1,42 +0,0 @@ -import argparse -import sys -from typing import Optional -from typing import Sequence - - -def find_executed_cell(filename): - """Read the file and check whether there is a line with "execution_count" and a non null value.""" - stream = open(filename, encoding="utf8", errors='ignore') - - executed_cells = [line.strip("\n,\" ") for line in stream if "execution_count" in line and "null" not in line ] - - return len(executed_cells) - - - -def main(argv: Optional[Sequence[str]] = None) -> int: - """First argument in command line is expected to be a list of filenames - - As the purpose of this file is to be used as a pre-commit git hook, the typical list are all the files modified by the commit in progress. - - If one or more file includes a cell that has been executed, the function returns 1 and print on screen the incriminated file(s). - """ - parser = argparse.ArgumentParser() - parser.add_argument('filenames', nargs='*', help='Filenames to check.') - args = parser.parse_args(argv) - - filenames_with_executed_cells = [] - - for filename in args.filenames: - if find_executed_cell(filename): - filenames_with_executed_cells.append(filename) - - if filenames_with_executed_cells: - print("Commit rejected: the following files feature executed cells: \n\t- {}".format("\n\t- ".join(filenames_with_executed_cells))) - return 1 - - return 0 - - -if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file diff --git a/Scripts/pre-commit b/Scripts/pre-commit index f5ab9387ad35fa2528a5c64b1c19e511b18ce206..378e760eb5aba8ba5889865f87feab8cdd8e773e 100755 --- a/Scripts/pre-commit +++ b/Scripts/pre-commit @@ -3,6 +3,12 @@ # This file is expected to be use as pre-commit git hook; copy it in .git/hooks/ file_list=`git diff --cached --diff-filter=ACM --name-only` -root_dir=`git rev-parse --show-toplevel` -/usr/bin/env python3 ${root_dir}/Scripts/check_no_executed_cell.py ${file_list} +for file in ${file_list} +do + if [ "${file##*.}" = "ipynb" ]; then + echo "Clear cells from ${file}" + jupyter nbconvert --clear-output --inplace ${file} + git add ${file} + fi +done