Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scrapy source registration #573

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sources/pg_replication/schema_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def _get_scale(type_id: int, atttypmod: int) -> Optional[int]:
@lru_cache(maxsize=None)
def _type_mapper() -> Any:
from dlt.destinations import postgres
from dlt.destinations.impl.postgres.postgres import PostgresTypeMapper

try:
from dlt.destinations.impl.postgres.postgres import PostgresTypeMapper
except ImportError:
from dlt.destinations.impl.postgres.factory import PostgresTypeMapper # type: ignore

return PostgresTypeMapper(postgres().capabilities())

Expand Down
13 changes: 5 additions & 8 deletions sources/scraping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dlt

from dlt.sources import DltResource
from dlt.common.source import _SOURCES, SourceInfo

from scrapy import Spider # type: ignore

Expand Down Expand Up @@ -65,10 +64,8 @@ def run_pipeline( # type: ignore[valid-type]
scraping_host.run(*args, **kwargs)


# This way we allow dlt init to detect scraping source it is indeed hacky
# and the core team is working to provide a better alternative.
_SOURCES[run_pipeline.__qualname__] = SourceInfo(
ScrapingConfig,
run_pipeline,
inspect.getmodule(run_pipeline),
)
@dlt.source(spec=ScrapingConfig)
def _register() -> DltResource:
raise NotImplementedError(
"Due to internal architecture of Scrapy, we could not represent it as a generator. Please use `run_pipeline` function instead"
)
2 changes: 1 addition & 1 deletion sources/scraping/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ def run(
logger.info("Starting scrapy crawler")
self.scrapy_runner.run()

# Wait to for pipeline finish it's job
# Wait to for pipeline finish its job
pipeline_worker.join()
Loading