Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 121e88c0 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#2 Add a script which checks whether there are executed cells in a bunch of Notebook files.

parent fd837c21
import argparse
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)
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):
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__':
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment