From 857bad6e534f90d16843c5b0ae84c23c022f06af Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Thu, 26 Jan 2023 15:33:47 +0100 Subject: [PATCH] check paths in `utils/documentation_tests.txt` (#21315) * check paths in utils/documentation_tests.txt * check paths in utils/documentation_tests.txt Co-authored-by: ydshieh --- .circleci/config.yml | 1 + Makefile | 1 + utils/check_doctest_list.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 utils/check_doctest_list.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 7b839f250dc..8c93359c068 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -174,6 +174,7 @@ jobs: - run: python utils/check_repo.py - run: python utils/check_inits.py - run: python utils/check_config_docstrings.py + - run: python utils/check_doctest_list.py - run: make deps_table_check_updated - run: python utils/tests_fetcher.py --sanity_check - run: python utils/update_metadata.py --check-only diff --git a/Makefile b/Makefile index 999ddd6ee15..e6325d8260c 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ repo-consistency: python utils/check_repo.py python utils/check_inits.py python utils/check_config_docstrings.py + python utils/check_doctest_list.py python utils/tests_fetcher.py --sanity_check python utils/update_metadata.py --check-only diff --git a/utils/check_doctest_list.py b/utils/check_doctest_list.py new file mode 100644 index 00000000000..330832e04cb --- /dev/null +++ b/utils/check_doctest_list.py @@ -0,0 +1,36 @@ +# coding=utf-8 +# Copyright 2023 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +# All paths are set with the intent you should run this script from the root of the repo with the command +# python utils/check_doctest_list.py +REPO_PATH = "." + + +if __name__ == "__main__": + + doctest_file_path = os.path.join(REPO_PATH, "utils/documentation_tests.txt") + non_existent_paths = [] + with open(doctest_file_path) as fp: + for line in fp: + line = line.strip() + path = os.path.join(REPO_PATH, line) + if not (os.path.isfile(path) or os.path.isdir(path)): + non_existent_paths.append(line) + if len(non_existent_paths) > 0: + non_existent_paths = "\n".join(non_existent_paths) + raise ValueError(f"`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}")