Skip to content

Commit 5139baf

Browse files
Merge pull request #135 from dlt-hub/update-dependencies/aman
Update dlt dependency from ^0.4.12 to latest
2 parents 961b76c + c3b2a86 commit 5139baf

File tree

16 files changed

+255
-159
lines changed

16 files changed

+255
-159
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: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1-
# some useful commands for developing
2-
3-
4-
update-rest-api:
5-
poetry run python dlt_init_openapi/utils/update_rest_api.py
6-
71
dev:
82
poetry install --all-extras
93

104
# lint
11-
lint: update-rest-api
5+
lint:
126
rm -rf tests/_local
137
poetry run flake8 dlt_init_openapi tests
148
poetry run mypy dlt_init_openapi tests
159
poetry run black tests dlt_init_openapi --check
16-
poetry run isort black tests dlt_init_openapi --check --diff
10+
poetry run isort --profile black tests dlt_init_openapi --check --diff
1711

1812
# format the whole project
19-
format: update-rest-api
13+
format:
2014
rm -rf tests/_local
21-
poetry run isort black tests dlt_init_openapi
15+
poetry run isort --profile black tests dlt_init_openapi
2216
poetry run black tests dlt_init_openapi
2317

2418
# all tests excluding the checks on e2e tests
25-
test: update-rest-api
26-
poetry run python dlt_init_openapi/utils/update_rest_api.py
19+
test:
2720
poetry run pytest tests --ignore=tests/e2e
2821

2922
# test without running all the specs through a source
30-
test-fast: update-rest-api
23+
test-fast:
3124
poetry run pytest tests -m "not slow" --ignore=tests/e2e
3225

33-
test-slow: update-rest-api
26+
test-slow:
3427
poetry run pytest tests -m "slow" --ignore=tests/e2e
3528

3629
# dev helpers
@@ -42,7 +35,7 @@ create-pokemon-pipeline-interactive:
4235

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

4740
run-pokemon-pipeline:
4841
cd pokemon_pipeline && poetry run python pokemon_pipeline.py

dlt_init_openapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Generate modern Python clients from OpenAPI """
1+
"""Generate modern Python clients from OpenAPI"""
22

33
from enum import Enum
44
from importlib.metadata import version

dlt_init_openapi/cli/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from dlt_init_openapi.cli.cli_endpoint_selection import questionary_endpoint_selection
1111
from dlt_init_openapi.config import Config
1212
from dlt_init_openapi.exceptions import DltOpenAPITerminalException
13-
from dlt_init_openapi.utils import update_rest_api
1413

1514
app = typer.Typer(add_completion=False)
1615

@@ -50,7 +49,6 @@ def init(
5049
"--allow-openapi-2",
5150
help="Allow to use OpenAPI v2. specs. Migration of the spec to 3.0 is recommended though.",
5251
),
53-
update_rest_api_source: bool = typer.Option(False, help="Update the locally cached rest_api verified source."),
5452
version: bool = typer.Option(False, "--version", callback=_print_version, help="Print the version and exit"),
5553
) -> None:
5654
"""Generate a new dlt pipeline"""
@@ -64,7 +62,6 @@ def init(
6462
interactive=interactive,
6563
log_level=log_level,
6664
global_limit=global_limit,
67-
update_rest_api_source=update_rest_api_source,
6865
allow_openapi_2=allow_openapi_2,
6966
)
7067

@@ -100,7 +97,6 @@ def _init_command_wrapped(
10097
try:
10198

10299
# sync rest api
103-
update_rest_api.update_rest_api(force=update_rest_api_source)
104100

105101
config = _load_config(
106102
path=config_path,

dlt_init_openapi/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import mimetypes
3-
import pathlib
43
from pathlib import Path
54
from typing import Any, List, Optional
65

@@ -11,8 +10,6 @@
1110

1211
from .typing import TEndpointFilter
1312

14-
REST_API_SOURCE_LOCATION = str(pathlib.Path(__file__).parent.resolve() / "../rest_api")
15-
1613

1714
class Config(BaseModel):
1815
"""Contains any configurable values passed by the user."""

dlt_init_openapi/parser/properties/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Utils for converting default values into valid Python """
1+
"""Utils for converting default values into valid Python"""
22

33
__all__ = ["convert", "convert_chain"]
44

dlt_init_openapi/renderer/default/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
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
1110

12-
from dlt_init_openapi.config import REST_API_SOURCE_LOCATION, Config
11+
from dlt_init_openapi.config import Config
1312
from dlt_init_openapi.parser.openapi_parser import OpenapiParser
1413
from dlt_init_openapi.renderer.base_renderer import BaseRenderer
1514
from dlt_init_openapi.utils import misc
@@ -68,9 +67,6 @@ def run(self, openapi: OpenapiParser, dry: bool = False) -> None:
6867
self._build_meta_files()
6968
self._run_post_hooks()
7069

71-
# copy rest api source into project dir
72-
copy_tree(REST_API_SOURCE_LOCATION, str(self.config.project_dir / "rest_api"))
73-
7470
def _build_meta_files(self) -> None:
7571
requirements_template = self.env.get_template("requirements.txt.j2")
7672
req_path = self.config.project_dir / "requirements.txt"
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/paths.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os.path
21
from typing import Dict, Iterable, List, Optional, Tuple
32

43

@@ -15,12 +14,23 @@ def table_names_from_paths(paths: Iterable[str]) -> Dict[str, str]:
1514
# Remove common prefix for endpoints. For example all paths might
1615
# start with /api/v2 and we don't want this to be part of the name
1716
paths = list(paths)
18-
if not (paths := list(paths)):
17+
if not paths:
1918
return {}
2019

21-
# normalize paths
22-
api_prefix = os.path.commonpath(paths)
23-
norm_paths = [p.removeprefix(api_prefix) for p in paths]
20+
# Get path parts for all paths
21+
path_parts = [tuple(get_path_parts(path)) for path in paths]
22+
# Find the longest common prefix
23+
common_prefix = find_longest_common_prefix(path_parts)
24+
# Remove the common prefix from each path
25+
norm_paths = []
26+
for path, parts in zip(paths, path_parts):
27+
if common_prefix:
28+
# Remove the common prefix parts
29+
remaining_parts = parts[len(common_prefix) :]
30+
norm_path = "/" + "/".join(remaining_parts) if remaining_parts else "/"
31+
else:
32+
norm_path = path
33+
norm_paths.append(norm_path)
2434

2535
# Get all path components without slashes and without {parameters}
2636
split_paths = [get_non_var_path_parts(path) for path in norm_paths]

0 commit comments

Comments
 (0)