path.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. path_code_tasks = Path(__file__).parent.parent.parent.joinpath(
  21. "src", "pydolphinscheduler", "tasks"
  22. )
  23. path_example = Path(__file__).parent.parent.parent.joinpath(
  24. "src", "pydolphinscheduler", "examples"
  25. )
  26. path_doc_tasks = Path(__file__).parent.parent.parent.joinpath("docs", "source", "tasks")
  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. )