code: def test_pre_commit_hook_sync_black_flake8(tmpdir, python_notebook):
      # Load real notebook metadata to get the 'auto' extension in --pipe-fmt to work
      metadata = python_notebook.metadata
  
      git = git_in_tmpdir(tmpdir)
      hook = str(tmpdir.join(".git/hooks/pre-commit"))
      with open(hook, "w") as fp:
          fp.write(
              "#!/bin/sh\n"
              "# Pair ipynb notebooks to a python file, reformat content with black, and run flake8\n"
              "# Note: this hook only acts on ipynb files. When pulling, run 'jupytext --sync' to "
              "update the ipynb file.\n"
              "jupytext --pre-commit --from ipynb --set-formats ipynb,py --pipe black --check flake8\n"
          )
  
      st = os.stat(hook)
      os.chmod(hook, st.st_mode | stat.S_IEXEC)
  
      tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
      tmp_py = str(tmpdir.join("notebook.py"))
      nb = new_notebook(
          cells=[new_code_cell(source="1+    1")], metadata=metadata
      )
  
      write(nb, tmp_ipynb)
      git("add", "notebook.ipynb")
      git("status")
      git("commit", "-m", "created")
      git("status")
      assert os.path.isfile(tmp_py)
      assert os.path.isfile(tmp_ipynb)
      with open(tmp_py) as fp:
          assert fp.read().splitlines()[-1] == "1 + 1"
  
      nb = new_notebook(
          cells=[new_code_cell(source='"""trailing   \nwhitespace"""')],
          metadata=metadata,
      )
      write(nb, tmp_ipynb)
      git("add", "notebook.ipynb")
      git("status")
      with pytest.raises(SystemExit):  # not flake8
          git("commit", "-m", "created")
  
file_path: jupytext/tests/external/pre_commit/test_pre_commit_scripts.py
imports: import os
  import stat
  import unittest.mock
  import pytest
  from nbformat.v4.nbbase import new_code_cell, new_markdown_cell, new_notebook
  from jupytext import read, write
  from jupytext.cli import jupytext, system
  from jupytext.compare import compare_cells, compare_notebooks
label_desc: Use image node_id 7 for calling a global function with example usage: test_pre_commit_hook_sync_black_flake8(tmpdir, python_notebook) without return types