__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from importlib import resources
  10. from pathlib import Path
  11. from typing import cast
  12. def resource_path(name: str) -> Path:
  13. # NOTE: we have to do this cast because pyright is not comfortable with the
  14. # Traversable protocol.
  15. return cast(Path, resources.files(__package__)) / name
  16. def scenarios() -> list[str]:
  17. """
  18. Determines a list of avilable scenarios based on the intersection
  19. of files located in both the `schema` and `workload` resource paths.
  20. """
  21. schema_files = {
  22. p.name.removesuffix(".sql")
  23. for p in resource_path("schema").iterdir()
  24. if p.is_file() and p.name.endswith(".sql")
  25. }
  26. workload_files = {
  27. p.name.removesuffix(".sql")
  28. for p in resource_path("workload").iterdir()
  29. if p.is_file() and p.name.endswith(".sql")
  30. }
  31. return sorted(schema_files.intersection(workload_files))
  32. class Scenario:
  33. def __init__(self, value: str) -> None:
  34. self.value = value
  35. def schema_path(self) -> Path:
  36. return resource_path(f"schema/{self}.sql")
  37. def workload_path(self) -> Path:
  38. return resource_path(f"workload/{self}.sql")
  39. def __str__(self) -> str:
  40. return self.value