|
3 | 3 | import requests |
4 | 4 | from loguru import logger |
5 | 5 |
|
6 | | -from dlt_init_openapi.config import REST_API_SOURCE_LOCATION |
| 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" |
7 | 13 |
|
8 | 14 | 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"] |
| 15 | +FILES = ["__init__.py", "requirements.txt"] |
10 | 16 |
|
11 | 17 |
|
12 | 18 | def update_rest_api(force: bool = False) -> None: |
13 | 19 | """updates local rest api""" |
14 | 20 | logger.info("Syncing rest_api verified source") |
15 | 21 |
|
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 |
| 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}") |
20 | 25 |
|
21 | | - path.mkdir(exist_ok=True) |
| 26 | + path.mkdir(parents=True, exist_ok=True) |
22 | 27 | for file in FILES: |
23 | 28 | src_path = BASEPATH + file |
24 | | - dst_path = REST_API_SOURCE_LOCATION + "/" + file |
25 | | - logger.info(f"Copying {src_path}") |
| 29 | + dst_file_path = path / file |
| 30 | + logger.info(f"Copying {src_path} to {dst_file_path}") |
26 | 31 | with requests.get(src_path, stream=True) as r: |
27 | 32 | r.raise_for_status() |
28 | | - with open(dst_path, "wb") as f: |
| 33 | + with open(dst_file_path, "wb") as f: |
29 | 34 | for chunk in r.iter_content(chunk_size=8192): |
30 | 35 | f.write(chunk) |
31 | 36 | logger.success("rest_api verified source synced") |
|
0 commit comments