nbdev/cli.py
def nbdev_install_git_hooks():
    "Install git hooks to clean/trust notebooks automatically"
    path = Config().config_file.parent
    fn = path/'.git'/'hooks'/'post-merge'
    #Trust notebooks after merge
    with open(fn, 'w') as f:
        f.write("""#!/bin/bash
echo "Trusting notebooks"
nbdev_trust_nbs
"""
        )
    os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)
    #Clean notebooks on commit/diff
    with open(path/'.gitconfig', 'w') as f:
        f.write("""# Generated by nbdev_install_git_hooks
#
# If you need to disable this instrumentation do:
#
# git config --local --unset include.path
#
# To restore the filter
#
# git config --local include.path .gitconfig
#
# If you see notebooks not stripped, checked the filters are applied in .gitattributes
#
[filter "clean-nbs"]
        clean = nbdev_clean_nbs --read_input_stream True
        smudge = cat
        required = true
[diff "ipynb"]
        textconv = nbdev_clean_nbs --disp True --fname
""")
    cmd = "git config --local include.path ../.gitconfig"
    print(f"Executing: {cmd}")
    result = subprocess.run(cmd.split(), shell=False, check=False, stderr=subprocess.PIPE)
    if result.returncode == 0:
        print("Success: hooks are installed and repo's .gitconfig is now trusted")
    else:
        print("Failed to trust repo's .gitconfig")
        if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
    with open(Config().nbs_path/'.gitattributes', 'w') as f:
        f.write("""**/*.ipynb filter=clean-nbs
**/*.ipynb diff=ipynb
"""
               )
Install git hooks to clean/trust notebooks automatically
Install git hooks to clean/trust notebooks automatically
Install git hooks to clean / trust notebooks automatically
def nbdev_install_git_hooks():
    path = Config().config_file.parent
    fn = path/'.git'/'hooks'/'post-merge'
    with open(fn, 'w') as f:
        f.write("""#!/bin/bash
echo "Trusting notebooks"
nbdev_trust_nbs
"""
        )
    os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)
    with open(path/'.gitconfig', 'w') as f:
        f.write("""# Generated by nbdev_install_git_hooks
#
# If you need to disable this instrumentation do:
#
# git config --local --unset include.path
#
# To restore the filter
#
# git config --local include.path .gitconfig
#
# If you see notebooks not stripped, checked the filters are applied in .gitattributes
#
[filter "clean-nbs"]
        clean = nbdev_clean_nbs --read_input_stream True
        smudge = cat
        required = true
[diff "ipynb"]
        textconv = nbdev_clean_nbs --disp True --fname
""")
    cmd = "git config --local include.path ../.gitconfig"
    print(f"Executing: {cmd}")
    result = subprocess.run(cmd.split(), shell=False, check=False, stderr=subprocess.PIPE)
    if result.returncode == 0:
        print("Success: hooks are installed and repo's .gitconfig is now trusted")
    else:
        print("Failed to trust repo's .gitconfig")
        if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
    with open(Config().nbs_path/'.gitattributes', 'w') as f:
        f.write("""**/*.ipynb filter=clean-nbs
**/*.ipynb diff=ipynb
"""
               )
def nbdev_install_git_hooks ( ) : path = Config ( ) . config_file . parent fn = path / '.git' / 'hooks' / 'post-merge' with open ( fn , 'w' ) as f : f . write ( """#!/bin/bash
echo "Trusting notebooks"
nbdev_trust_nbs
""" ) os . chmod ( fn , os . stat ( fn ) . st_mode | stat . S_IEXEC ) with open ( path / '.gitconfig' , 'w' ) as f : f . write ( """# Generated by nbdev_install_git_hooks
#
# If you need to disable this instrumentation do:
#
# git config --local --unset include.path
#
# To restore the filter
#
# git config --local include.path .gitconfig
#
# If you see notebooks not stripped, checked the filters are applied in .gitattributes
#
[filter "clean-nbs"]
        clean = nbdev_clean_nbs --read_input_stream True
        smudge = cat
        required = true
[diff "ipynb"]
        textconv = nbdev_clean_nbs --disp True --fname
""" ) cmd = "git config --local include.path ../.gitconfig" print ( f"Executing: {cmd}" ) result = subprocess . run ( cmd . split ( ) , shell = False , check = False , stderr = subprocess . PIPE ) if result . returncode == 0 : print ( "Success: hooks are installed and repo's .gitconfig is now trusted" ) else : print ( "Failed to trust repo's .gitconfig" ) if result . stderr : print ( f"Error: {result.stderr.decode('utf-8')}" ) with open ( Config ( ) . nbs_path / '.gitattributes' , 'w' ) as f : f . write ( """**/*.ipynb filter=clean-nbs
**/*.ipynb diff=ipynb
""" )
Install git hooks to clean/trust notebooks automatically
Install git hooks to clean / trust notebooks automatically
"Install git hooks to clean/trust notebooks automatically" #Trust notebooks after merge #Clean notebooks on commit/diff