Skip to content

Commit fcd89e6

Browse files
committed
Updated
1 parent 7a5f3ab commit fcd89e6

File tree

3 files changed

+19
-41
lines changed

3 files changed

+19
-41
lines changed

dlt_init_openapi/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from .typing import TEndpointFilter
1313

14-
# Vendored rest_api source should be located inside the dlt_init_openapi package directory
15-
# e.g., dlt_init_openapi/rest_api/
14+
# In dlt>=1.11.0, the rest_api is part of the main package
15+
# For backwards compatibility, we keep a stub directory
1616
REST_API_SOURCE_LOCATION = str(pathlib.Path(__file__).parent / "rest_api")
1717

1818
# Placeholder for SecretsTomlConfig to resolve ImportError in tests

dlt_init_openapi/utils/update_rest_api.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
import pathlib
22

3-
import requests
43
from loguru import logger
54

6-
# REST_API_SOURCE_LOCATION from config might resolve to site-packages.
7-
# For this script, we explicitly want to write into the source tree.
8-
# Assuming this script is in dlt_init_openapi/utils/update_rest_api.py
9-
# The target is dlt_init_openapi/dlt_init_openapi/rest_api/
10-
SCRIPT_DIR = pathlib.Path(__file__).parent.resolve()
11-
# Target path: dlt_init_openapi/dlt_init_openapi/rest_api/
12-
VENDOR_PATH = SCRIPT_DIR.parent / "rest_api"
13-
14-
BASEPATH = "https://raw.githubusercontent.com/dlt-hub/verified-sources/master/sources/rest_api/"
15-
FILES = ["__init__.py", "requirements.txt"]
16-
175

186
def update_rest_api(force: bool = False) -> None:
19-
"""updates local rest api"""
20-
logger.info("Syncing rest_api verified source")
21-
22-
# Use the locally determined VENDOR_PATH for file operations
23-
path = VENDOR_PATH
24-
logger.info(f"Target absolute path for rest_api (script-determined): {path}")
25-
26-
path.mkdir(parents=True, exist_ok=True)
27-
for file in FILES:
28-
src_path = BASEPATH + file
29-
dst_file_path = path / file
30-
logger.info(f"Copying {src_path} to {dst_file_path}")
31-
with requests.get(src_path, stream=True) as r:
32-
r.raise_for_status()
33-
with open(dst_file_path, "wb") as f:
34-
for chunk in r.iter_content(chunk_size=8192):
35-
f.write(chunk)
36-
logger.success("rest_api verified source synced")
7+
"""
8+
This function is kept for backwards compatibility.
9+
In dlt >=1.0.0, rest_api is part of the main package.
10+
No need to vendor the files separately.
11+
"""
12+
logger.info("Using built-in dlt.sources.rest_api (dlt >=1.11.0)")
13+
# Create an empty rest_api directory to maintain compatibility
14+
script_dir = pathlib.Path(__file__).parent.resolve()
15+
vendor_path = script_dir.parent / "rest_api"
16+
vendor_path.mkdir(parents=True, exist_ok=True)
17+
# Create empty __init__.py to make it a proper package
18+
init_file = vendor_path / "__init__.py"
19+
if not init_file.exists():
20+
with open(init_file, "w") as f:
21+
f.write("# This is a compatibility package. Use dlt.sources.rest_api instead.\n")
3722

3823

3924
if __name__ == "__main__":

tests/integration/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,8 @@ def get_source_or_dict_from_open_api(
6161
source = source.replace("rest_api_source(source_config)", "source_config")
6262
source = source.replace("dlt.secrets.value", '"SECRET_VALUE"')
6363

64-
# Directly correct the known problematic imports from the renderer\'s template
65-
source = source.replace(
66-
"from rest_api.typing import RESTAPIConfig",
67-
"from dlt.sources.rest_api.typing import RESTAPIConfig",
68-
)
69-
source = source.replace(
70-
"from rest_api import rest_api_source",
71-
"from dlt.sources.rest_api import rest_api_source",
72-
)
64+
# The template now correctly uses dlt.sources.rest_api imports
65+
# No need to replace imports
7366

7467
basename = os.path.basename(case).split(".")[0] + "_" + rt
7568

0 commit comments

Comments
 (0)