Skip to content

Commit 7a5f3ab

Browse files
committed
- Upgraded dlt from ^0.4.12 to ^1.11.0
- Updated rest_api.py, utils.py, and other files - Cleanup and minor fixes# This is a combination of 13 commits. Update dlt dependency from ^0.4.12 to ^1.11.0 Updated 'update_rest_api.py' Updated Updated utils.py updated Updted Updated Updated Updated Updated Updated Updated updated pokemon
1 parent 961b76c commit 7a5f3ab

File tree

11 files changed

+258
-102
lines changed

11 files changed

+258
-102
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
[Go to GitHub Releases](https://github.com/dlt-hub/dlt-init-openapi/releases)
22

3+
## Unreleased
4+
5+
* Bump dlt to 1.11.0
6+
7+
## 0.1.0
8+
9+
* Bump dlt to 0.4.12
10+
* First beta release of REST API client generator
11+
312
0.1.0 - Initial Release
413
* Bump dlt to 0.4.12
514

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ lint: update-rest-api
1313
poetry run flake8 dlt_init_openapi tests
1414
poetry run mypy dlt_init_openapi tests
1515
poetry run black tests dlt_init_openapi --check
16-
poetry run isort black tests dlt_init_openapi --check --diff
16+
poetry run isort --profile black tests dlt_init_openapi --check --diff
1717

1818
# format the whole project
1919
format: update-rest-api
2020
rm -rf tests/_local
21-
poetry run isort black tests dlt_init_openapi
21+
poetry run isort --profile black tests dlt_init_openapi
2222
poetry run black tests dlt_init_openapi
2323

2424
# all tests excluding the checks on e2e tests
@@ -42,7 +42,7 @@ create-pokemon-pipeline-interactive:
4242

4343
# e2e test helpers
4444
create-e2e-pokemon-pipeline:
45-
poetry run dlt-init-openapi pokemon --path tests/cases/e2e_specs/pokeapi.yml --global-limit 2 --no-interactive
45+
poetry run dlt-init-openapi pokemon --path tests/cases/e2e_specs/pokeapi.yml --no-interactive --global-limit 2
4646

4747
run-pokemon-pipeline:
4848
cd pokemon_pipeline && poetry run python pokemon_pipeline.py

dlt_init_openapi/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import mimetypes
33
import pathlib
44
from pathlib import Path
5-
from typing import Any, List, Optional
5+
from typing import Any, Dict, List, Optional
66

77
import yaml
88
from pydantic import BaseModel
@@ -11,7 +11,12 @@
1111

1212
from .typing import TEndpointFilter
1313

14-
REST_API_SOURCE_LOCATION = str(pathlib.Path(__file__).parent.resolve() / "../rest_api")
14+
# Vendored rest_api source should be located inside the dlt_init_openapi package directory
15+
# e.g., dlt_init_openapi/rest_api/
16+
REST_API_SOURCE_LOCATION = str(pathlib.Path(__file__).parent / "rest_api")
17+
18+
# Placeholder for SecretsTomlConfig to resolve ImportError in tests
19+
SecretsTomlConfig = Dict[str, Any]
1520

1621

1722
class Config(BaseModel):

dlt_init_openapi/renderer/default/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import shutil
66
import subprocess
7-
from distutils.dir_util import copy_tree
87

98
from jinja2 import Environment, PackageLoader
109
from loguru import logger
@@ -69,7 +68,7 @@ def run(self, openapi: OpenapiParser, dry: bool = False) -> None:
6968
self._run_post_hooks()
7069

7170
# copy rest api source into project dir
72-
copy_tree(REST_API_SOURCE_LOCATION, str(self.config.project_dir / "rest_api"))
71+
shutil.copytree(REST_API_SOURCE_LOCATION, str(self.config.project_dir / "rest_api"))
7372

7473
def _build_meta_files(self) -> None:
7574
requirements_template = self.env.get_template("requirements.txt.j2")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dlt>=0.4.12
1+
dlt>=1.11.0

dlt_init_openapi/renderer/default/templates/source.py.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ from typing import List
33
import dlt
44
from dlt.extract.source import DltResource
55

6-
from rest_api.typing import RESTAPIConfig
7-
from rest_api import rest_api_source
6+
from dlt.sources.rest_api.typing import RESTAPIConfig
7+
from dlt.sources.rest_api import rest_api_source
88

99

1010
@dlt.source(name="{{source_name}}", max_table_nesting=2)

dlt_init_openapi/utils/update_rest_api.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@
33
import requests
44
from loguru import logger
55

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"
713

814
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"]
1016

1117

1218
def update_rest_api(force: bool = False) -> None:
1319
"""updates local rest api"""
1420
logger.info("Syncing rest_api verified source")
1521

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}")
2025

21-
path.mkdir(exist_ok=True)
26+
path.mkdir(parents=True, exist_ok=True)
2227
for file in FILES:
2328
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}")
2631
with requests.get(src_path, stream=True) as r:
2732
r.raise_for_status()
28-
with open(dst_path, "wb") as f:
33+
with open(dst_file_path, "wb") as f:
2934
for chunk in r.iter_content(chunk_size=8192):
3035
f.write(chunk)
3136
logger.success("rest_api verified source synced")

0 commit comments

Comments
 (0)