Skip to content

Commit ed3617c

Browse files
refactor: Deprecate passing file paths to plugin and stream initialization (#2743)
1 parent 62c03bb commit ed3617c

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ filterwarnings = [
176176
"ignore:No records were available to test:UserWarning",
177177
# https://github.com/meltano/sdk/issues/1354
178178
"ignore:The function singer_sdk.testing.get_standard_tap_tests is deprecated:DeprecationWarning",
179+
# https://github.com/meltano/sdk/issues/2744
180+
"ignore::singer_sdk.helpers._compat.SingerSDKDeprecationWarning",
179181
# TODO: Address this SQLite warning in Python 3.13+
180182
"ignore::ResourceWarning",
181183
]

singer_sdk/helpers/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
date_fromisoformat = datetime.date.fromisoformat
3232
time_fromisoformat = datetime.time.fromisoformat
3333

34+
35+
class SingerSDKDeprecationWarning(DeprecationWarning):
36+
"""Custom deprecation warning for the Singer SDK."""
37+
38+
3439
__all__ = [
40+
"SingerSDKDeprecationWarning",
3541
"Traversable",
3642
"date_fromisoformat",
3743
"datetime_fromisoformat",

singer_sdk/plugin_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import time
1010
import typing as t
11+
import warnings
1112
from importlib import metadata
1213
from pathlib import Path, PurePath
1314
from types import MappingProxyType
@@ -22,6 +23,7 @@
2223
)
2324
from singer_sdk.exceptions import ConfigValidationError
2425
from singer_sdk.helpers._classproperty import classproperty
26+
from singer_sdk.helpers._compat import SingerSDKDeprecationWarning
2527
from singer_sdk.helpers._secrets import SecretString, is_common_secret_key
2628
from singer_sdk.helpers._util import read_json_file
2729
from singer_sdk.helpers.capabilities import (
@@ -144,12 +146,24 @@ def __init__(
144146
config_dict = {}
145147
elif isinstance(config, (str, PurePath)):
146148
config_dict = read_json_file(config)
149+
warnings.warn(
150+
"Passsing a config file path is deprecated. Please pass the config "
151+
"as a dictionary instead.",
152+
SingerSDKDeprecationWarning,
153+
stacklevel=2,
154+
)
147155
elif isinstance(config, list):
148156
config_dict = {}
149157
for config_path in config:
150158
# Read each config file sequentially. Settings from files later in the
151159
# list will override those of earlier ones.
152160
config_dict.update(read_json_file(config_path))
161+
warnings.warn(
162+
"Passsing a list of config file paths is deprecated. Please pass the "
163+
"config as a dictionary instead.",
164+
SingerSDKDeprecationWarning,
165+
stacklevel=2,
166+
)
153167
elif isinstance(config, dict):
154168
config_dict = config
155169
else:

singer_sdk/streams/core.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88
import json
99
import typing as t
10+
import warnings
1011
from os import PathLike
1112
from pathlib import Path
1213
from types import MappingProxyType
@@ -27,7 +28,10 @@
2728
SDKBatchMessage,
2829
)
2930
from singer_sdk.helpers._catalog import pop_deselected_record_properties
30-
from singer_sdk.helpers._compat import datetime_fromisoformat
31+
from singer_sdk.helpers._compat import (
32+
SingerSDKDeprecationWarning,
33+
datetime_fromisoformat,
34+
)
3135
from singer_sdk.helpers._flattening import get_flattening_options
3236
from singer_sdk.helpers._state import (
3337
finalize_state_progress_markers,
@@ -157,6 +161,12 @@ def __init__(
157161
raise FileNotFoundError(msg)
158162

159163
self._schema_filepath = Path(schema)
164+
warnings.warn(
165+
"Passing a schema filepath is deprecated. Please pass the schema "
166+
"dictionary or a Singer Schema object instead.",
167+
SingerSDKDeprecationWarning,
168+
stacklevel=2,
169+
)
160170
elif isinstance(schema, dict):
161171
self._schema = schema
162172
elif isinstance(schema, singer.Schema):

singer_sdk/tap_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import abc
66
import contextlib
77
import typing as t
8+
import warnings
89
from enum import Enum
910

1011
import click
@@ -18,6 +19,7 @@
1819
)
1920
from singer_sdk.helpers import _state
2021
from singer_sdk.helpers._classproperty import classproperty
22+
from singer_sdk.helpers._compat import SingerSDKDeprecationWarning
2123
from singer_sdk.helpers._state import write_stream_state
2224
from singer_sdk.helpers._util import dump_json, read_json_file
2325
from singer_sdk.helpers.capabilities import (
@@ -102,6 +104,12 @@ def __init__(
102104
self._input_catalog = Catalog.from_dict(catalog) # type: ignore[arg-type]
103105
elif catalog is not None:
104106
self._input_catalog = Catalog.from_dict(read_json_file(catalog))
107+
warnings.warn(
108+
"Passsing a catalog file path is deprecated. Please pass the catalog "
109+
"as a dictionary or Catalog object instead.",
110+
SingerSDKDeprecationWarning,
111+
stacklevel=2,
112+
)
105113

106114
self._mapper: PluginMapper | None = None
107115

@@ -114,6 +122,12 @@ def __init__(
114122
state_dict = state
115123
elif state:
116124
state_dict = read_json_file(state)
125+
warnings.warn(
126+
"Passsing a state file path is deprecated. Please pass the state "
127+
"as a dictionary instead.",
128+
SingerSDKDeprecationWarning,
129+
stacklevel=2,
130+
)
117131
self.load_state(state_dict)
118132

119133
# Class properties

0 commit comments

Comments
 (0)