diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9a5221486..eac582c9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,23 +1,25 @@ repos: - repo: https://github.com/kynan/nbstripout - rev: 0.8.1 + rev: 34071b78c181af3bf5af955c1426466e096fc3db #0.9.1 hooks: - id: nbstripout - args: - - '--keep-output' + args: [--keep-output, '--extra-keys=metadata.kernelspec'] + files: ^doc/*\.(ipynb)$ - repo: local hooks: - - id: remove-notebook-headers - name: Remove Notebook Headers - entry: python ./build_scripts/remove_notebook_headers.py - language: python - files: ^doc.*\.(ipynb)$ - - id: sanitize-notebook-paths - name: Sanitize Notebook Paths - entry: python ./build_scripts/sanitize_notebook_paths.py - language: python - files: ^doc.*\.(ipynb)$ + - id: sanitize-notebook-paths + name: Sanitize Notebook Paths + entry: python ./build_scripts/sanitize_notebook_paths.py + language: python + files: ^doc.*\.(ipynb)$ + - id: validate-docs + name: Validate Documentation Structure + entry: python ./build_scripts/validate_docs.py + language: python + files: ^(doc/.*\.(py|ipynb|md)|doc/myst\.yml)$ + pass_filenames: false + additional_dependencies: ['pyyaml'] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -66,23 +68,3 @@ repos: entry: mypy language: system types: [ python ] - - - repo: local - hooks: - - id: remove-notebook-headers - name: Remove Notebook Headers - entry: python ./build_scripts/remove_notebook_headers.py - language: python - files: ^doc.*\.(ipynb)$ - - id: sanitize-notebook-paths - name: Sanitize Notebook Paths - entry: python ./build_scripts/sanitize_notebook_paths.py - language: python - files: ^doc.*\.(ipynb)$ - - id: validate-docs - name: Validate Documentation Structure - entry: python ./build_scripts/validate_docs.py - language: python - files: ^(doc/.*\.(py|ipynb|md)|doc/myst\.yml)$ - pass_filenames: false - additional_dependencies: ['pyyaml'] diff --git a/build_scripts/remove_notebook_headers.py b/build_scripts/remove_notebook_headers.py deleted file mode 100644 index 824c1851a..000000000 --- a/build_scripts/remove_notebook_headers.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT license. - -import json -import sys - - -def remove_kernelspec_from_ipynb_files(file_path: str): - modified_files = [] - - if file_path.endswith(".ipynb"): - # Iterate through all .ipynb files in the specified file - with open(file_path, encoding="utf-8") as f: - content = json.load(f) - # Remove the "kernelspec" metadata section if it exists - if "metadata" in content and "kernelspec" in content["metadata"]: - modified_files.append(file_path) - del content["metadata"]["kernelspec"] - # Save the modified content back to the .ipynb file - with open(file_path, "w", encoding="utf-8") as f: - json.dump(content, f, indent=1) - if modified_files: - print("Modified files:", modified_files) - sys.exit(1) - - -if __name__ == "__main__": - files = sys.argv[1:] - # # Remove the "kernelspec" section from all .ipynb files in the specified file - for file in files: - remove_kernelspec_from_ipynb_files(file)