Skip to content

Commit 57152c8

Browse files
committed
Updated
- 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 Updated
1 parent 961b76c commit 57152c8

File tree

11 files changed

+251
-117
lines changed

11 files changed

+251
-117
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+
# In dlt>=1.11.0, the rest_api is part of the main package
15+
# For backwards compatibility, we keep a stub directory
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 & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
import pathlib
22

3-
import requests
43
from loguru import logger
54

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-
115

126
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")
3222

3323

3424
if __name__ == "__main__":

0 commit comments

Comments
 (0)