Skip to content

Commit b0a8621

Browse files
refactor: Use importlib.resources instead of __file__ to retrieve sample Singer output files (#1877)
1 parent 6576f52 commit b0a8621

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

singer_sdk/helpers/_compat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
from importlib import metadata
1212
from typing import final # noqa: ICN003
1313

14-
__all__ = ["metadata", "final"]
14+
if sys.version_info < (3, 9):
15+
import importlib_resources as resources
16+
else:
17+
from importlib import resources
18+
19+
__all__ = ["metadata", "final", "resources"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Singer output samples, used for testing target behavior."""

singer_sdk/testing/templates.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import warnings
88
from pathlib import Path
99

10+
from singer_sdk.helpers._compat import resources
11+
from singer_sdk.testing import target_test_streams
12+
1013
if t.TYPE_CHECKING:
1114
from singer_sdk.streams import Stream
1215

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

0 commit comments

Comments
 (0)