|
1 | 1 | import pathlib |
2 | 2 |
|
3 | | -import requests |
4 | 3 | from loguru import logger |
5 | 4 |
|
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 | | - |
17 | 5 |
|
18 | 6 | 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") |
37 | 22 |
|
38 | 23 |
|
39 | 24 | if __name__ == "__main__": |
|
0 commit comments