Skip to content

Commit

Permalink
airbyte-lib: Improve source factory (#34849)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Reuter authored Feb 6, 2024
1 parent 65002d4 commit 0b79b9e
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions airbyte-lib/airbyte_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from airbyte_lib._factories.cache_factories import get_default_cache, new_local_cache
from airbyte_lib._factories.connector_factories import get_connector
from airbyte_lib._factories.connector_factories import get_source
from airbyte_lib.caches import DuckDBCache, DuckDBCacheConfig
from airbyte_lib.datasets import CachedDataset
from airbyte_lib.results import ReadResult
Expand All @@ -14,7 +14,7 @@
"CachedDataset",
"DuckDBCache",
"DuckDBCacheConfig",
"get_connector",
"get_source",
"get_default_cache",
"get_secret",
"new_local_cache",
Expand Down
10 changes: 5 additions & 5 deletions airbyte-lib/airbyte_lib/_factories/connector_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
from airbyte_lib.source import Source


def get_connector(
def get_source(
name: str,
version: str | None = None,
pip_url: str | None = None,
config: dict[str, Any] | None = None,
*,
version: str | None = None,
pip_url: str | None = None,
local_executable: Path | str | None = None,
install_if_missing: bool = True,
) -> Source:
"""Get a connector by name and version.
Args:
name: connector name
config: connector config - if not provided, you need to set it later via the set_config
method.
version: connector version - if not provided, the currently installed version will be used.
If no version is installed, the latest available version will be used. The version can
also be set to "latest" to force the use of the latest available version.
pip_url: connector pip URL - if not provided, the pip url will be inferred from the
connector name.
config: connector config - if not provided, you need to set it later via the set_config
method.
local_executable: If set, the connector will be assumed to already be installed and will be
executed using this path or executable name. Otherwise, the connector will be installed
automatically in a virtual environment.
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/airbyte_lib/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def set_config(
def _config(self) -> dict[str, Any]:
if self._config_dict is None:
raise exc.AirbyteConnectorConfigurationMissingError(
guidance="Provide via get_connector() or set_config()"
guidance="Provide via get_source() or set_config()"
)
return self._config_dict

Expand Down
4 changes: 2 additions & 2 deletions airbyte-lib/airbyte_lib/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _run_subprocess_and_raise_on_failure(args: list[str]) -> None:

def full_tests(connector_name: str, sample_config: str) -> None:
print("Creating source and validating spec and version...")
source = ab.get_connector(
source = ab.get_source(
# TODO: FIXME: noqa: SIM115, PTH123
connector_name,
config=json.load(open(sample_config)), # noqa: SIM115, PTH123,
Expand Down Expand Up @@ -90,7 +90,7 @@ def full_tests(connector_name: str, sample_config: str) -> None:

def install_only_test(connector_name: str) -> None:
print("Creating source and validating spec is returned successfully...")
source = ab.get_connector(connector_name)
source = ab.get_source(connector_name)
source._get_spec(force_refresh=True) # noqa: SLF001


Expand Down
10 changes: 5 additions & 5 deletions airbyte-lib/docs/generated/airbyte_lib.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_faker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SCALE = 5_000_000 # Number of records to generate between users and purchases.


source = ab.get_connector(
source = ab.get_source(
"source-faker",
config={"count": SCALE / 2},
install_if_missing=True,
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
GITHUB_TOKEN = ab.get_secret("GITHUB_PERSONAL_ACCESS_TOKEN")


source = ab.get_connector("source-github")
source = ab.get_source("source-github")
source.set_config(
{"repositories": ["airbytehq/airbyte"], "credentials": {"personal_access_token": GITHUB_TOKEN}}
)
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_pokeapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import airbyte_lib as ab


source = ab.get_connector(
source = ab.get_source(
"source-pokeapi",
config={"pokemon_name": "bulbasaur"},
install_if_missing=True,
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_snowflake_faker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from airbyte_lib.caches import SnowflakeCacheConfig, SnowflakeSQLCache


source = ab.get_connector(
source = ab.get_source(
"source-faker",
config={"count": 10000, "seed": 0, "parallelism": 1, "always_updated": False},
install_if_missing=True,
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_spacex.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# In separate terminal:
# poetry run python examples/run_spacex.py

source = ab.get_connector(
source = ab.get_source(
"source-spacex-api",
config={"id": "605b4b6aaa5433645e37d03f"},
install_if_missing=True,
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

os.environ["AIRBYTE_LOCAL_REGISTRY"] = "./tests/integration_tests/fixtures/registry.json"

source = ab.get_connector("source-test", config={"apiKey": "test"})
source = ab.get_source("source-test", config={"apiKey": "test"})
cache = ab.new_local_cache("cache_test")

source.check()
Expand Down
2 changes: 1 addition & 1 deletion airbyte-lib/examples/run_test_source_single_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

os.environ["AIRBYTE_LOCAL_REGISTRY"] = "./tests/integration_tests/fixtures/registry.json"

source = ab.get_connector("source-test", config={"apiKey": "test"})
source = ab.get_source("source-test", config={"apiKey": "test"})

print(list(source.read_stream("stream1")))
6 changes: 3 additions & 3 deletions airbyte-lib/tests/integration_tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from gettext import install
import pytest

from airbyte_lib._factories.connector_factories import get_connector
from airbyte_lib._factories.connector_factories import get_source
from airbyte_lib import exceptions as exc


def test_install_failure_log_pypi():
"""Test that the install log is created and contains the expected content."""
with pytest.raises(exc.AirbyteConnectorNotRegisteredError):
source = get_connector("source-not-found")
source = get_source("source-not-found")

with pytest.raises(exc.AirbyteConnectorInstallationError) as exc_info:
source = get_connector(
source = get_source(
"source-not-found",
pip_url="https://pypi.org/project/airbyte-not-found",
install_if_missing=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_which_source_faker() -> None:
@pytest.fixture(scope="function") # Each test gets a fresh source-faker instance.
def source_faker_seed_a() -> ab.Source:
"""Fixture to return a source-faker connector instance."""
source = ab.get_connector(
source = ab.get_source(
"source-faker",
local_executable="source-faker",
config={
Expand All @@ -74,7 +74,7 @@ def source_faker_seed_a() -> ab.Source:
@pytest.fixture(scope="function") # Each test gets a fresh source-faker instance.
def source_faker_seed_b() -> ab.Source:
"""Fixture to return a source-faker connector instance."""
source = ab.get_connector(
source = ab.get_source(
"source-faker",
local_executable="source-faker",
config={
Expand Down
Loading

0 comments on commit 0b79b9e

Please sign in to comment.