polymo 0.7.2__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polymo-0.7.2 → polymo-0.8.0}/PKG-INFO +1 -1
- {polymo-0.7.2 → polymo-0.8.0}/pyproject.toml +1 -1
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/app.py +28 -17
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/main.js +7 -7
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/config.py +107 -18
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/datasource.py +20 -4
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/rest_client.py +36 -27
- {polymo-0.7.2 → polymo-0.8.0}/README.md +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/__init__.py +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/__init__.py +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/countries.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/githubrepos.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/jsonplaceholder.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/jsonplaceholder_endpoints.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/multi_endpoints.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/examples/weather.yml +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/favicon.ico +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/favicon.png +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/index.html +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/logo.png +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/logo192.png +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/main.css +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/static/mockServiceWorker.js +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/builder/templates/index.html +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/cli.py +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/py.typed +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/scripts/__init__.py +0 -0
- {polymo-0.7.2 → polymo-0.8.0}/src/polymo/scripts/smoke.py +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import json
|
|
5
6
|
from functools import partial
|
|
6
7
|
from importlib import metadata, resources
|
|
7
8
|
from typing import Any, Dict, List, Optional, Tuple
|
|
@@ -308,19 +309,25 @@ def _collect_records(
|
|
|
308
309
|
config: RestSourceConfig, token: str | None, limit: int
|
|
309
310
|
) -> Tuple[List[Dict[str, Any]], List[Dict[str, str]]]:
|
|
310
311
|
"""Collect processed records and dtypes using PySpark DataSource."""
|
|
311
|
-
import tempfile
|
|
312
|
-
import os
|
|
313
|
-
from ..config import dump_config
|
|
314
312
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
313
|
+
from ..config import config_to_dict
|
|
314
|
+
|
|
315
|
+
if config.auth and not token:
|
|
316
|
+
if config.auth.type == "bearer" and config.auth.token:
|
|
317
|
+
token = config.auth.token
|
|
318
|
+
if config.auth.type == "oauth2" and config.auth.client_secret:
|
|
319
|
+
token = config.auth.client_secret
|
|
320
|
+
|
|
321
|
+
config_dict = config_to_dict(config)
|
|
320
322
|
|
|
321
323
|
spark = _get_or_create_spark()
|
|
322
324
|
try:
|
|
323
|
-
df = _get_preview_df(
|
|
325
|
+
df = _get_preview_df(
|
|
326
|
+
config_dict=config_dict,
|
|
327
|
+
token=token,
|
|
328
|
+
spark=spark,
|
|
329
|
+
reader_options=config.options
|
|
330
|
+
)
|
|
324
331
|
records = df.limit(limit).collect()
|
|
325
332
|
dtypes = df.dtypes
|
|
326
333
|
record_dicts = [row.asDict(recursive=True) for row in records]
|
|
@@ -332,12 +339,12 @@ def _collect_records(
|
|
|
332
339
|
return record_dicts, dtype_dicts
|
|
333
340
|
finally:
|
|
334
341
|
spark.stop()
|
|
335
|
-
os.unlink(config_path)
|
|
336
342
|
|
|
337
343
|
|
|
338
344
|
def _get_preview_df(
|
|
339
|
-
|
|
340
|
-
|
|
345
|
+
*,
|
|
346
|
+
config_dict: ConfigDict,
|
|
347
|
+
token: Optional[str],
|
|
341
348
|
spark: "SparkSession",
|
|
342
349
|
reader_options: Dict[str, Any],
|
|
343
350
|
):
|
|
@@ -347,18 +354,22 @@ def _get_preview_df(
|
|
|
347
354
|
|
|
348
355
|
_get_or_create_spark()
|
|
349
356
|
spark.dataSource.register(ApiReader)
|
|
357
|
+
config_json = json.dumps(config_dict, sort_keys=True)
|
|
358
|
+
options: Dict[str, str] = {"config_json": config_json}
|
|
350
359
|
|
|
351
|
-
# Alternative approach: Use the DataSource directly without format registration
|
|
352
|
-
# Create the DataSource instance manually
|
|
353
|
-
options = {
|
|
354
|
-
"config_path": config_path,
|
|
355
|
-
}
|
|
356
360
|
if token is not None:
|
|
357
361
|
options["token"] = token
|
|
362
|
+
|
|
363
|
+
if source := config_dict.get('source', {}):
|
|
364
|
+
if auth := source.get("auth"):
|
|
365
|
+
if auth.get("type") == "oauth2":
|
|
366
|
+
options["oauth_client_secret"] = token
|
|
367
|
+
|
|
358
368
|
for key, value in reader_options.items():
|
|
359
369
|
if key in {"config_path", "token"}:
|
|
360
370
|
continue
|
|
361
371
|
options[key] = value
|
|
372
|
+
|
|
362
373
|
return spark.read.format("polymo").options(**options).load()
|
|
363
374
|
|
|
364
375
|
|