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

Validate docstring examples #384

Merged
merged 2 commits into from
May 16, 2023

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented May 10, 2023

  • Add module to validate ``` python wrapped code examples in docstrings
  • Make all examples validate correctly

fixes #81

@Marenz Marenz requested a review from a team as a code owner May 10, 2023 11:07
@Marenz Marenz requested a review from shsms May 10, 2023 11:07
@github-actions github-actions bot added part:actor Affects an actor ot the actors utilities (decorator, etc.) part:data-pipeline Affects the data pipeline part:power-management Affects the management of battery power and distribution part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels May 10, 2023
@Marenz Marenz force-pushed the validate_docstring_examples branch 3 times, most recently from eeb75ed to abf9358 Compare May 10, 2023 12:56
@Marenz Marenz self-assigned this May 10, 2023
@Marenz Marenz force-pushed the validate_docstring_examples branch from abf9358 to 961b8f6 Compare May 10, 2023 13:07
@Marenz Marenz added this to the v0.21.0 milestone May 10, 2023
@Marenz
Copy link
Contributor Author

Marenz commented May 10, 2023

@leandro-lucarella-frequenz I tried having the script in another file/dir than src/conftest.py but it seems to be more involved, so I left it for now.

@leandro-lucarella-frequenz leandro-lucarella-frequenz changed the title validate docstring examples Validate docstring examples May 11, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a few minor things.

src/conftest.py Show resolved Hide resolved
src/conftest.py Outdated Show resolved Hide resolved
src/conftest.py Outdated Show resolved Hide resolved
src/conftest.py Outdated Show resolved Hide resolved
src/frequenz/sdk/actor/_decorator.py Outdated Show resolved Hide resolved
Comment on lines +84 to 85
# pylint: disable=import-error
import polars as pl

Choose a reason for hiding this comment

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

There is still the question about what to do about this. @matthias-wende-frequenz do you think we can avoid using polars in the example? Or is it very important for polars to be used here? I don't think it is terrible to have a pylint: disable=xxx in an example, but if we can avoid it, much better.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we remove polars we can remove the whole example. So the discussion is more about do we need the example and my feeling is, that removing an example to make a tool work is not the best practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see, although the discussion is not if we need the example or not. I think we all agree we want the example, I just thought maybe it was possible to do some example/demonstration just using numpy that was equivalent (since we already have it as a dependency). This is just exposing my ignorance about pandas/numpy if I'm not making any sense, but I didn't wanted to remove examples to adapt to the tool :)

In any case I think we need to strike a balance, because also adding obscure # pylint: disable=import-error (that could be carried out blinding by users) is also not great.

Adding support to specify dependencies in code examples is also quite a bit of work and will make running this examples much slower. An alternative could be to offload examples needing external libraries to examples/, where it should be easier to specify dependencies for example, but I agree in this case that defeats the whole purpose of having a quick small example embedded.

In any case, I agree that for now if there is no consensus about this, the best approach is to leave the # pylint: disable=import-error, but I think the goal should be to somehow remove it in the future. I will create a discussion about this so it's not forgotten.

Choose a reason for hiding this comment

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

@Marenz Marenz force-pushed the validate_docstring_examples branch from 961b8f6 to 6c94354 Compare May 12, 2023 15:01
Copy link
Contributor

Choose a reason for hiding this comment

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

Found one error in the examples undetected by pylint.

src/frequenz/sdk/actor/_decorator.py Outdated Show resolved Hide resolved
src/frequenz/sdk/actor/_decorator.py Outdated Show resolved Hide resolved
src/frequenz/sdk/actor/_decorator.py Outdated Show resolved Hide resolved
@Marenz Marenz force-pushed the validate_docstring_examples branch from 6c94354 to ce34f7a Compare May 15, 2023 12:15
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@Marenz Marenz added this pull request to the merge queue May 16, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 16, 2023
@Marenz Marenz added this pull request to the merge queue May 16, 2023
Merged via the queue into frequenz-floss:v0.x.x with commit fe4727c May 16, 2023
@Marenz Marenz deleted the validate_docstring_examples branch May 16, 2023 09:25
@Marenz Marenz mentioned this pull request Jun 26, 2023
6 tasks
llucax added a commit to llucax/frequenz-repo-config-python that referenced this pull request Aug 15, 2023
This commit adds a module with an utility function to be able to easily
collect and lint code examples in docstrings.

It also add an optional dependency to easily pull the dependencies
needed to do this linting and ignores any optional dependency starting
with `extra-` in the tests checking if new repo types were added, as
optional dependencies starting with `extra-` are not really repository
types.

This is based on the work on the SDK:
frequenz-floss/frequenz-sdk-python#384

Signed-off-by: Leandro Lucarella <[email protected]>
llucax added a commit to llucax/frequenz-repo-config-python that referenced this pull request Aug 15, 2023
This commit adds a module with an utility function to be able to easily
collect and lint code examples in docstrings.

It also add an optional dependency to easily pull the dependencies
needed to do this linting and ignores any optional dependency starting
with `extra-` in the tests checking if new repo types were added, as
optional dependencies starting with `extra-` are not really repository
types.

This is based on the work on the SDK:
frequenz-floss/frequenz-sdk-python#384

Signed-off-by: Leandro Lucarella <[email protected]>
llucax added a commit to llucax/frequenz-repo-config-python that referenced this pull request Aug 15, 2023
This commit adds a module with an utility function to be able to easily
collect and lint code examples in docstrings.

It also add an optional dependency to easily pull the dependencies
needed to do this linting and ignores any optional dependency starting
with `extra-` in the tests checking if new repo types were added, as
optional dependencies starting with `extra-` are not really repository
types.

This is based on the work on the SDK:
frequenz-floss/frequenz-sdk-python#384

Signed-off-by: Leandro Lucarella <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:actor Affects an actor ot the actors utilities (decorator, etc.) part:data-pipeline Affects the data pipeline part:power-management Affects the management of battery power and distribution part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)
Projects
Development

Successfully merging this pull request may close these issues.

Fix broken examples in docstrings
3 participants