|
24 | 24 | ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)) |
25 | 25 |
|
26 | 26 |
|
27 | | -def check_example_dags_dir_init_file(example_dags_dirs: List[str]) -> None: |
| 27 | +def check_dir_init_file(provider_files: List[str]) -> None: |
28 | 28 | missing_init_dirs = [] |
29 | | - for example_dags_dir in example_dags_dirs: |
30 | | - if not os.path.exists(example_dags_dir + "__init__.py"): |
31 | | - missing_init_dirs.append(example_dags_dir) |
| 29 | + for dags_file in provider_files: |
| 30 | + if os.path.isdir(dags_file) and not os.path.exists(os.path.join(dags_file, "__init__.py")): |
| 31 | + missing_init_dirs.append(dags_file) |
32 | 32 |
|
33 | 33 | if missing_init_dirs: |
34 | 34 | with open(os.path.join(ROOT_DIR, "license-templates/LICENSE.txt")) as license: |
35 | 35 | license_txt = license.readlines() |
36 | 36 | prefixed_licensed_txt = [f"# {line}" if line != "\n" else "#\n" for line in license_txt] |
37 | 37 |
|
38 | 38 | for missing_init_dir in missing_init_dirs: |
39 | | - with open(missing_init_dir + "__init__.py", "w") as init_file: |
| 39 | + with open(os.path.join(missing_init_dir, "__init__.py"), "w") as init_file: |
40 | 40 | init_file.write("".join(prefixed_licensed_txt)) |
41 | 41 |
|
42 | | - print("No __init__.py file was found in the following provider example_dags directories:") |
| 42 | + print("No __init__.py file was found in the following provider directories:") |
43 | 43 | print("\n".join(missing_init_dirs)) |
44 | 44 | print("\nThe missing __init__.py files have been created. Please add these new files to a commit.") |
45 | 45 | sys.exit(1) |
46 | 46 |
|
47 | 47 |
|
48 | 48 | if __name__ == "__main__": |
49 | | - all_provider_example_dags_dirs = sorted( |
50 | | - glob(f"{ROOT_DIR}/airflow/providers/**/example_dags/", recursive=True) |
51 | | - ) |
52 | | - check_example_dags_dir_init_file(all_provider_example_dags_dirs) |
| 49 | + all_provider_subpackage_dirs = sorted(glob(f"{ROOT_DIR}/airflow/providers/**/*", recursive=True)) |
| 50 | + check_dir_init_file(all_provider_subpackage_dirs) |
| 51 | + all_test_provider_subpackage_dirs = sorted(glob(f"{ROOT_DIR}/tests/providers/**/*", recursive=True)) |
| 52 | + check_dir_init_file(all_test_provider_subpackage_dirs) |
0 commit comments