|
1 | 1 | import pathlib |
2 | 2 |
|
3 | | -import requests |
4 | 3 | from loguru import logger |
5 | 4 |
|
6 | | -from dlt_init_openapi.config import REST_API_SOURCE_LOCATION |
7 | | - |
8 | | -BASEPATH = "https://raw.githubusercontent.com/dlt-hub/verified-sources/master/sources/rest_api/" |
9 | | -FILES = ["README.md", "__init__.py", "config_setup.py", "exceptions.py", "requirements.txt", "typing.py", "utils.py"] |
10 | | - |
11 | 5 |
|
12 | 6 | def update_rest_api(force: bool = False) -> None: |
13 | | - """updates local rest api""" |
14 | | - logger.info("Syncing rest_api verified source") |
15 | | - |
16 | | - path = pathlib.Path(REST_API_SOURCE_LOCATION) |
17 | | - if path.exists() and not force: |
18 | | - logger.info("rest_api verified source already present") |
19 | | - return |
20 | | - |
21 | | - path.mkdir(exist_ok=True) |
22 | | - for file in FILES: |
23 | | - src_path = BASEPATH + file |
24 | | - dst_path = REST_API_SOURCE_LOCATION + "/" + file |
25 | | - logger.info(f"Copying {src_path}") |
26 | | - with requests.get(src_path, stream=True) as r: |
27 | | - r.raise_for_status() |
28 | | - with open(dst_path, "wb") as f: |
29 | | - for chunk in r.iter_content(chunk_size=8192): |
30 | | - f.write(chunk) |
31 | | - 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") |
32 | 22 |
|
33 | 23 |
|
34 | 24 | if __name__ == "__main__": |
|
0 commit comments