|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | +# Copyright 2023 The vLLM team. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# This file is a part of the vllm-ascend project. |
| 17 | +# Adapted from https://github.com/vllm-project/vllm/tree/main/tools |
| 18 | +# |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +VLLM_ASCEND_SRC = "vllm_ascend" |
| 23 | +VLLM_SRC = "vllm-empty/vllm" |
| 24 | + |
| 25 | + |
| 26 | +def check_init_file_in_package(directory): |
| 27 | + """ |
| 28 | + Check if a Python package directory contains __init__.py file. |
| 29 | + A directory is considered a Python package if it contains `.py` files and an `__init__.py` file. |
| 30 | + """ |
| 31 | + try: |
| 32 | + files = os.listdir(directory) |
| 33 | + except FileNotFoundError: |
| 34 | + print(f"Warning: Directory does not exist: {directory}") |
| 35 | + return False |
| 36 | + |
| 37 | + # If any .py file exists, we expect an __init__.py |
| 38 | + if any(f.endswith('.py') for f in files): |
| 39 | + init_file = os.path.join(directory, '__init__.py') |
| 40 | + if not os.path.isfile(init_file): |
| 41 | + return False |
| 42 | + return True |
| 43 | + |
| 44 | + |
| 45 | +def find_missing_init_dirs(src_dir): |
| 46 | + """ |
| 47 | + Walk through the src_dir and return subdirectories missing __init__.py. |
| 48 | + """ |
| 49 | + missing_init = set() |
| 50 | + for dirpath, _, _ in os.walk(src_dir): |
| 51 | + if not check_init_file_in_package(dirpath): |
| 52 | + missing_init.add(dirpath) |
| 53 | + return missing_init |
| 54 | + |
| 55 | + |
| 56 | +def main(): |
| 57 | + all_missing = set() |
| 58 | + |
| 59 | + for src in [VLLM_ASCEND_SRC, VLLM_SRC]: |
| 60 | + missing = find_missing_init_dirs(src) |
| 61 | + all_missing.update(missing) |
| 62 | + |
| 63 | + if all_missing: |
| 64 | + print( |
| 65 | + "❌ Missing '__init__.py' files in the following Python package directories:" |
| 66 | + ) |
| 67 | + for pkg in sorted(all_missing): |
| 68 | + print(f" - {pkg}") |
| 69 | + sys.exit(1) |
| 70 | + else: |
| 71 | + print("✅ All Python packages have __init__.py files.") |
| 72 | + |
| 73 | + |
| 74 | +if __name__ == "__main__": |
| 75 | + main() |
0 commit comments