Skip to content

Commit

Permalink
refactor: Use importlib.resources instead of __file__ to retrieve…
Browse files Browse the repository at this point in the history
… sample Singer output files (#1877)
  • Loading branch information
edgarrmondragon authored Jul 27, 2023
1 parent 6576f52 commit b0a8621
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion singer_sdk/helpers/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
from importlib import metadata
from typing import final # noqa: ICN003

__all__ = ["metadata", "final"]
if sys.version_info < (3, 9):
import importlib_resources as resources
else:
from importlib import resources

__all__ = ["metadata", "final", "resources"]
1 change: 1 addition & 0 deletions singer_sdk/testing/target_test_streams/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Singer output samples, used for testing target behavior."""
6 changes: 4 additions & 2 deletions singer_sdk/testing/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import warnings
from pathlib import Path

from singer_sdk.helpers._compat import resources
from singer_sdk.testing import target_test_streams

if t.TYPE_CHECKING:
from singer_sdk.streams import Stream

Expand Down Expand Up @@ -334,5 +337,4 @@ def singer_filepath(self) -> Path:
Returns:
The expected Path to this tests singer file.
"""
current_dir = Path(__file__).resolve().parent
return current_dir / "target_test_streams" / f"{self.name}.singer"
return resources.files(target_test_streams).joinpath(f"{self.name}.singer") # type: ignore[no-any-return] # noqa: E501

0 comments on commit b0a8621

Please sign in to comment.