Skip to content

Commit

Permalink
Correct linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jirispilka committed Jul 30, 2024
1 parent 2aa79a9 commit dd9b75e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
18 changes: 9 additions & 9 deletions poetry.lock

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

6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "haystack"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "haystack.dataclasses"
module = "haystack.*"
ignore_missing_imports = true

[tool.mypy-sortedcollections]
Expand Down
6 changes: 4 additions & 2 deletions scripts/update_version_for_prerelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

# We can only transform a stable release version (X.Y.Z) to a prerelease version (X.Y.ZxxxN)
if not re.match(r"^\d+\.\d+\.\d+$", current_version):
raise RuntimeError(f"The current version {current_version} does not match the proper semver format for "
f"stable releases (X.Y.Z)")
raise RuntimeError(
f"The current version {current_version} does not match the proper semver format for "
f"stable releases (X.Y.Z)"
)

# Load the version numbers of the currently published versions from PyPI
published_versions = get_published_package_versions()
Expand Down
4 changes: 2 additions & 2 deletions src/apify_haystack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__version__ = metadata.version("apify-haystack")

from apify_haystack.apify_dataset import ApifyDatasetLoader
from apify_haystack.apify_dataset import ApifyDatasetFromActorCall, ApifyDatasetLoader

__all__ = ["ApifyDatasetLoader"]
__all__ = ["ApifyDatasetLoader", "ApifyDatasetFromActorCall", "ApifyDatasetFromActorCall"]
29 changes: 15 additions & 14 deletions src/apify_haystack/apify_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ def __init__(
httpx_client.headers["user-agent"] += f"; {HAYSTACK_ATTRIBUTE_USER_AGENT}"

@component.output_types(documents=list[Document])
def run(self): # type: ignore[no-untyped-def]
def run(self): # type: ignore[no-untyped-def] # noqa: ANN201
"""Load datasets produced by the `Apify Actors`.
Type-hint note: the output is not type-hinted, otherwise linting complains that `run` method is a component
Type-hint note: the output is not type-hinted, otherwise linting complains
that `run` method is not haystack a component
"""
dataset_items = self.client.dataset(self.dataset_id).list_items(clean=True).items
return {"documents": list(map(self.dataset_mapping_function, dataset_items))}
Expand Down Expand Up @@ -84,8 +85,7 @@ def __init__(
timeout_secs: int | None = None,
apify_api_token: str | None = None,
) -> None:
"""
Initialize the Apify Actor loader.
"""Initialize the Apify Actor loader.
Args:
actor_id (str): The ID or name of the Actor on the Apify platform.
Expand Down Expand Up @@ -119,10 +119,11 @@ def __init__(
httpx_client.headers["user-agent"] += f"; {HAYSTACK_ATTRIBUTE_USER_AGENT}"

@component.output_types(documents=list[Document])
def run(self): # type: ignore[no-untyped-def]
def run(self): # type: ignore[no-untyped-def] # noqa: ANN201
"""Run an Actor on the Apify platform and wait for results to be ready.
Type-hint note: the output is not type-hinted, otherwise linting complains that `run` method is a component
Type-hint note: the output is not type-hinted, otherwise linting complains
that `run` method is not haystack a component
"""
if not (
actor_call := self.client.actor(self.actor_id).call(
Expand Down Expand Up @@ -155,19 +156,18 @@ def __init__(
self,
task_id: str,
dataset_mapping_function: Callable[[dict], Document],
run_input: dict,
task_input: dict,
*,
build: str | None = None,
memory_mbytes: int | None = None,
timeout_secs: int | None = None,
apify_api_token: str | None = None,
) -> None:
"""
Initialize the Apify Actor loader.
"""Initialize the Apify Actor loader.
Args:
task_id (str): The ID or name of the Actor on the Apify platform.
run_input (Dict): The input object of the Actor that you're trying to run.
task_input (Dict): The input object of the Actor that you're trying to run.
dataset_mapping_function (Callable): A function that takes a single
dictionary (an Apify dataset item) and converts it to an
instance of the Document class.
Expand All @@ -180,7 +180,7 @@ def __init__(
"""
self.task_id = task_id
self.dataset_mapping_function = dataset_mapping_function
self.run_input = run_input
self.task_input = task_input
self.build = build
self.memory_mbytes = memory_mbytes
self.timeout_secs = timeout_secs
Expand All @@ -197,14 +197,15 @@ def __init__(
httpx_client.headers["user-agent"] += f"; {HAYSTACK_ATTRIBUTE_USER_AGENT}"

@component.output_types(documents=list[Document])
def run(self): # type: ignore[no-untyped-def]
def run(self): # type: ignore[no-untyped-def] # noqa: ANN201
"""Run an Actor on the Apify platform and wait for results to be ready.
Type-hint note: the output is not type-hinted, otherwise linting complains that `run` method is a component
Type-hint note: the output is not type-hinted, otherwise linting complains
that `run` method is not haystack a component
"""
if not (
actor_call := self.client.task(self.task_id).call(
run_input=self.run_input,
task_input=self.task_input,
build=self.build,
memory_mbytes=self.memory_mbytes,
timeout_secs=self.timeout_secs,
Expand Down
1 change: 0 additions & 1 deletion src/apify_haystack/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

# A custom user-agent for attribution and monitoring purposes
HAYSTACK_ATTRIBUTE_USER_AGENT = "Origin/haystack"
10 changes: 5 additions & 5 deletions src/apify_haystack/examples/apify_actor_call.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Call Apify Actor and load a dataset to convert it to Haystack Documents.
This script demonstrates how to use Apify's Website Content Crawler to scrape text content from a specified website and convert the
scraped data into Haystack Documents.
This script demonstrates how to use Apify's Website Content Crawler to scrape text content from a specified website
and convert the scraped data into Haystack Documents.
For example, if you want to crawl and get text content from https://haystack.deepset.ai/, you can use this script to call the Apify actor
and retrieve the data in a structured format.
For example, if you want to crawl and get text content from https://haystack.deepset.ai/, you can use this script
to call the Apify actor and retrieve the data in a structured format.
The script should produce the following output (an example of a single Document):
......
Expand All @@ -17,7 +17,7 @@
from dotenv import load_dotenv
from haystack import Document

from apify_dataset import ApifyDatasetFromActorCall
from apify_haystack import ApifyDatasetFromActorCall

# Sey APIFY-API-TOKEN here or load it from .env file
apify_token = "" or load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion src/apify_haystack/examples/crawl_and_process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from haystack.components.writers import DocumentWriter
from haystack.document_stores.in_memory import InMemoryDocumentStore

from apify_dataset import ApifyDatasetFromActorCall
from apify_haystack import ApifyDatasetFromActorCall

# Sey APIFY-API-TOKEN here or load it from .env file
apify_token = "" or load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion src/apify_haystack/examples/rag_with_crawled_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack.document_stores.in_memory import InMemoryDocumentStore

from apify_dataset import ApifyDatasetFromActorCall
from apify_haystack import ApifyDatasetFromActorCall

# Load OPENAI_API_KEY and APIFY_API_TOKEN from .env file
load_dotenv()
Expand Down

0 comments on commit dd9b75e

Please sign in to comment.