Skip to content

feat: Handle request list user input#326

Merged
janbuchar merged 21 commits into
masterfrom
handle-request-list-user-input
Nov 20, 2024
Merged

feat: Handle request list user input#326
janbuchar merged 21 commits into
masterfrom
handle-request-list-user-input

Conversation

@Pijukatel

@Pijukatel Pijukatel commented Nov 18, 2024

Copy link
Copy Markdown
Contributor

Add helper function to handle request list inputs.

Closes: #310

@github-actions github-actions Bot added this to the 103rd sprint - Tooling team milestone Nov 18, 2024
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Nov 18, 2024

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Pull Request Tookit has failed!

Pull request is neither linked to an issue or epic nor labeled as adhoc!

Comment thread tests/unit/actor/test_actor_create_request_list.py Outdated
Comment thread tests/unit/actor/test_actor_create_request_list.py Outdated
Comment thread src/apify/_actor.py Outdated
@Pijukatel Pijukatel changed the title Handle request list user input feat: Handle request list user input Nov 18, 2024
@Pijukatel
Pijukatel marked this pull request as ready for review November 18, 2024 17:28
@Pijukatel
Pijukatel requested a review from janbuchar November 18, 2024 17:28
Comment thread src/apify/storages/_known_actor_input_keys.py Outdated
@vdusek
vdusek self-requested a review November 19, 2024 09:36
Comment thread pyproject.toml
Comment thread src/apify/storages/_known_actor_input_keys.py Outdated
Comment thread src/apify/_platform_event_manager.py
@janbuchar
janbuchar self-requested a review November 19, 2024 09:50
Comment thread src/apify/storages/_known_actor_input_keys.py Outdated
Comment thread src/apify/storages/_actor_inputs.py Outdated
Comment thread src/apify/storages/_actor_inputs.py Outdated
Comment thread src/apify/storages/_actor_inputs.py Outdated
Finalize tests.
Split to its own file.
Fix typing issues

WIP
TODO: Finish test for it.
WIP
Add test for checking all genrated request properties.
Add helper class for input keys
Add top level Input class for handling actor inputs.
Add few more tests for regex
It had too many assumptions that users might not be interested in.
Users should create such Input helper classes based on their specific inputs and their names.
Update TCH001, TCH002, TCH003 uses.
@Pijukatel
Pijukatel force-pushed the handle-request-list-user-input branch from c237c66 to 6ff9e90 Compare November 19, 2024 12:59
@Pijukatel

Copy link
Copy Markdown
Contributor Author

Sorry for the force-push. Due to my previous mainly Gerrit-based experience I was expecting this Rebase button in Github to do something more clean in the log...

Comment thread pyproject.toml
inline-quotes = "single"

[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel", "crawlee.configuration.Configuration"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though crawlee.configuration.Configuration inherits from pydantic_settings.BaseSettings and that one from pydantic.BaseModel, ruff has some issues in following inheritance hierarchy too far. So until that changes, some models will have to be explicitly mentioned even though they inherit from pydantic.BaseModel.
See closed issue where this is described as known limitation to certain degree:
astral-sh/ruff#8725

@janbuchar janbuchar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good! Just a bunch of nits to iron out...

Comment thread src/apify/storages/request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
Comment thread tests/unit/actor/test_request_list.py
Comment thread tests/unit/actor/test_request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
Comment thread src/apify/storages/_request_list.py Outdated
Comment thread src/apify/storages/_request_list.py Outdated
Comment thread src/apify/storages/_request_list.py Outdated
Comment thread tests/unit/actor/test_request_list.py Outdated
Comment thread src/apify/storages/request_list.py Outdated
headers=request_input.headers,
user_data=request_input.user_data,
)
for request_input in simple_url_inputs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw thinking about this class reminded me of this: apify/crawlee#2466

Basically, in JS Crawlee, we used to instantiate all the requests at the beginning (like here), but that ate up much more memory than just keeping the POJO objects (I guess dicts in Python) and instantiating the Request class only once we really need it. Maybe Python handles this better (has slimmer class instances).

It was at that time we learned that users love to make >1.000.000 requests long RLs 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a valid point, but I think it will be done later in apify/crawlee-python#99 as the current class is openly not as mature as the JS version:

https://github.com/apify/crawlee-python/blob/master/src/crawlee/storages/_request_list.py#L23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's make sure the SDK supports everything the platform can offer first, then we can optimize.

@Pijukatel
Pijukatel requested a review from janbuchar November 20, 2024 12:23

@janbuchar janbuchar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last suggestion 🙂

Comment thread src/apify/storages/_request_list.py Outdated
Comment thread src/apify/storages/_request_list.py Outdated
url_input_adapter = TypeAdapter(list[Union[_RequestsFromUrlInput, _SimpleUrlInput]])


# @docs_group('Classes') # Not yet available in crawlee

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR here #328

Comment thread src/apify/storages/request_list.py Outdated
headers=request_input.headers,
user_data=request_input.user_data,
)
for request_input in simple_url_inputs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's make sure the SDK supports everything the platform can offer first, then we can optimize.

Comment thread src/apify/storages/_request_list.py Outdated
@janbuchar
janbuchar self-requested a review November 20, 2024 16:04
@janbuchar
janbuchar merged commit c14fb9a into master Nov 20, 2024
@janbuchar
janbuchar deleted the handle-request-list-user-input branch November 20, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle request list and proxy configuration inputs in a user-friendly way

5 participants