Skip to content

docs: Add @docs_group decorator#655

Merged
vdusek merged 6 commits into
masterfrom
docs/group-by-decorator
Nov 11, 2024
Merged

docs: Add @docs_group decorator#655
vdusek merged 6 commits into
masterfrom
docs/group-by-decorator

Conversation

@barjin

@barjin barjin commented Nov 6, 2024

Copy link
Copy Markdown
Member

Adds support for the @docs_group decorator, which sets the symbol's group in the documentation.

Adds the decorators as per the list in #650 .

Hides the undecorated symbols under the project root (but keeps those in classes etc., so class / object methods + properties are still documented).

obrazek

Closes #650

@barjin
barjin requested review from janbuchar and vdusek November 6, 2024 08:19
@barjin barjin self-assigned this Nov 6, 2024
@github-actions github-actions Bot added this to the 102nd sprint - Tooling team milestone Nov 6, 2024
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 6, 2024
Comment thread src/crawlee/_utils/docs.py Outdated
@@ -0,0 +1,2 @@
def docs_group(group_name: str) -> None:
pass

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This likely breaks all the code and needs fixing.

All the "noop" decorator approaches (that work for both classes and functions) I found had way too many lines - definitely more than I'm comfortable with changing :)

Can one of you Python whizzes fix this please? (cc @vdusek @Pijukatel )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Something like this should work:

class docs_group:
  def __init__(self, group_name: str) -> None:
    pass

  def __call__(self, callable: Callable) -> Callable:
    return callable

You could also make a function that returns a function, but I tend to find that a class is more readable.

Comment thread src/crawlee/_autoscaling/autoscaled_pool.py
Comment thread src/crawlee/_utils/docs.py Outdated
@@ -0,0 +1,2 @@
def docs_group(group_name: str) -> None:
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Something like this should work:

class docs_group:
  def __init__(self, group_name: str) -> None:
    pass

  def __call__(self, callable: Callable) -> Callable:
    return callable

You could also make a function that returns a function, but I tend to find that a class is more readable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one is supposed to be used as a singleton:

from crawlee import service_container

client = service_container.get_storage_client()

But this will probably change soon anyway...

Comment thread website/transformDocs.js
function getGroupName(object) {
if (object.decorations?.some(d => d.name === 'docs_group')) {
return {
groupName: object.decorations.find(d => d.name === 'docs_group')?.args.slice(2,-2),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That slice is disturbing. But I guess AST parsing is overkill for this case.

@vdusek vdusek changed the title docs: @docs_group decorator docs: Add @docs_group decorator Nov 11, 2024
@vdusek
vdusek requested a review from janbuchar November 11, 2024 16:09

@vdusek vdusek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@vdusek
vdusek merged commit 9ce6e14 into master Nov 11, 2024
@vdusek
vdusek deleted the docs/group-by-decorator branch November 11, 2024 16:29
janbuchar pushed a commit to apify/apify-sdk-python that referenced this pull request Nov 20, 2024
Updates the `@apify/docusaurus-plugin-typedoc-api` plugin, which enables
us to use the unified Python documentation pipeline (instead of handling
it in each Python project separately).

Decorates the symbols to be documented with `@docs_group` and
`@docs_name` decorators (just like in
[crawlee-python](apify/crawlee-python#655)).
Those decorators could be moved up into some shared package (e.g.
`apify-shared`, which already has the `@ignore_docs` decorator).

Uses the new `reexports` feature of the plugin to load external API docs
(from `crawlee.dev/python`) and re-render them in the current
documentation instance.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering symbol groups in API docs

3 participants