path.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. 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,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Handle path related issue in test module."""
  18. from pathlib import Path
  19. from typing import Any, Generator
  20. project_root = Path(__file__).parent.parent.parent
  21. path_code_tasks = project_root.joinpath("src", "pydolphinscheduler", "tasks")
  22. path_example = project_root.joinpath("src", "pydolphinscheduler", "examples")
  23. path_doc_tasks = project_root.joinpath("docs", "source", "tasks")
  24. path_default_config_yaml = project_root.joinpath(
  25. "src", "pydolphinscheduler", "core", "default_config.yaml"
  26. )
  27. def get_all_examples() -> Generator[Path, Any, None]:
  28. """Get all examples files path in examples directory."""
  29. return (ex for ex in path_example.iterdir() if ex.is_file())
  30. def get_tasks(ignore_name: set = None) -> Generator[Path, Any, None]:
  31. """Get all tasks files path in src/pydolphinscheduler/tasks directory."""
  32. if not ignore_name:
  33. ignore_name = set()
  34. return (
  35. ex
  36. for ex in path_code_tasks.iterdir()
  37. if ex.is_file() and ex.name not in ignore_name
  38. )
  39. def get_doc_tasks(ignore_name: set = None) -> Generator[Path, Any, None]:
  40. """Get all tasks document path in docs/source/tasks directory."""
  41. if not ignore_name:
  42. ignore_name = set()
  43. return (
  44. ex
  45. for ex in path_doc_tasks.iterdir()
  46. if ex.is_file() and ex.name not in ignore_name
  47. )