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

Overhaul docs, add pydoclint and custom formatter #1314

Merged
merged 63 commits into from
Aug 25, 2023
Merged

Conversation

haakonvt
Copy link
Contributor

@haakonvt haakonvt commented Aug 12, 2023

Description

Step 1: Add docstring linter
Step 2: Fix 1 million errors

Note

It seems the linter struggles with | (Union) in return annotations. I have raised an issue and is waiting for a response. jsh9/pydoclint#66

--> The maintainer fixed it 😄

Also awaiting an answer for a different fix than excluding a file through pre-commit for the with_ parameter for Query:
jsh9/pydoclint#73

--> The maintainer fixed this one as well ❤️

Last bug in pydoclint, currently awaiting response: jsh9/pydoclint#75

--> ...and fixed 🚀

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@haakonvt haakonvt mentioned this pull request Aug 12, 2023
@haakonvt haakonvt force-pushed the add-pydoclint branch 3 times, most recently from 1ef438b to b03fb56 Compare August 14, 2023 19:29
pyproject.toml Outdated Show resolved Hide resolved
@haakonvt haakonvt force-pushed the add-pydoclint branch 2 times, most recently from 9eec8c6 to 27f4564 Compare August 16, 2023 02:24
@haakonvt haakonvt marked this pull request as ready for review August 17, 2023 21:22
@haakonvt haakonvt requested review from a team as code owners August 17, 2023 21:22
@haakonvt
Copy link
Contributor Author

haakonvt commented Aug 17, 2023

Started out with 868 issues on master:

Counter({'DOC105': 267,
         'DOC203': 166,
         'DOC103': 93,
         'DOC101': 70,
         'DOC110': 54,
         'DOC501': 50,
         'DOC109': 44,
         'DOC201': 39,
         'DOC403': 28,
         'DOC104': 28,
         'DOC001': 11,
         'DOC102': 9,
         'DOC502': 3,
         'DOC301': 3,
         'DOC402': 2,
         'DOC401': 1})

...now down to 139:

Counter({'DOC501': 53,
         'DOC203': 25,
         'DOC201': 15,
         'DOC105': 9,
         'DOC109': 7,
         'DOC110': 6,
         'DOC103': 5,
         'DOC001': 4,
         'DOC101': 4,
         'DOC502': 3,
         'DOC301': 3,
         'DOC104': 2,
         'DOC403': 1,
         'DOC401': 1,
         'DOC402': 1}

...and finally, 0 🥳

@codecov
Copy link

codecov bot commented Aug 21, 2023

Codecov Report

Merging #1314 (0beb8fa) into master (c0c8942) will decrease coverage by 0.09%.
The diff coverage is 98.68%.

@@            Coverage Diff             @@
##           master    #1314      +/-   ##
==========================================
- Coverage   90.42%   90.34%   -0.09%     
==========================================
  Files         110      110              
  Lines       13515    13514       -1     
==========================================
- Hits        12221    12209      -12     
- Misses       1294     1305      +11     
Files Changed Coverage Δ
...ient/_api/data_modeling/_data_modeling_executor.py 81.25% <ø> (ø)
cognite/client/_api/transformations/schema.py 100.00% <ø> (ø)
cognite/client/data_classes/relationships.py 95.04% <ø> (ø)
cognite/client/data_classes/sequences.py 90.29% <ø> (ø)
cognite/client/data_classes/shared.py 94.91% <ø> (ø)
cognite/client/data_classes/templates.py 84.79% <ø> (ø)
cognite/client/data_classes/three_d.py 89.18% <ø> (ø)
cognite/client/data_classes/time_series.py 90.85% <ø> (ø)
...te/client/data_classes/transformations/__init__.py 88.35% <ø> (ø)
...nite/client/data_classes/transformations/common.py 93.02% <ø> (ø)
... and 87 more

@haakonvt
Copy link
Contributor Author

Should I bump version? Perhaps "massive" doc fixes is okay? 🤷

Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

Only a few minor comments.

@@ -739,11 +744,18 @@ def store_partial_result(self, res: DataPointListItem) -> Optional[List[Splittin
return self._split_self_into_new_subtasks_if_needed(last_ts)
return None

def _create_subtasks_idxs(self, n_new_tasks: int) -> Iterable[Tuple[float, ...]]:
def _create_subtasks_idxs(self, n_new_tasks: int) -> Generator[Tuple[float, ...], None, None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the type hint for generators is not very good, thus I think the old one should stay, if it is possible configure the linter to do so.

Note I am not alone https://stackoverflow.com/questions/42531143/how-to-type-hint-a-generator-in-python-3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used to agree with this, but was convinced otherwise by the maintainer of pydoclint: jsh9/pydoclint#68 (comment)

cognite/client/data_classes/data_modeling/instances.py Outdated Show resolved Hide resolved
cognite/client/data_classes/data_modeling/instances.py Outdated Show resolved Hide resolved
cognite/client/data_classes/data_modeling/instances.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints_subscriptions.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints_subscriptions.py Outdated Show resolved Hide resolved
cognite/client/testing.py Show resolved Hide resolved
scripts/custom_checks/docstrings.py Show resolved Hide resolved
Copy link
Collaborator

@erlendvollset erlendvollset left a comment

Choose a reason for hiding this comment

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

MASSIVE work 💪Docs just leveled up 💯

pyproject.toml Outdated
@@ -14,6 +14,18 @@ packages = [{ include="cognite", from="." }]
[tool.ruff.pyupgrade]
keep-runtime-typing = true

[tool.pydoclint]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we configure it using cmd line args in the pre-commit file instead? We prefer putting it there, only in here if that doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely 👌

@haakonvt haakonvt changed the title Add pydoclint Overhaul docs, add pydoclint and custom formatter Aug 22, 2023
Copy link
Collaborator

@erlendvollset erlendvollset left a comment

Choose a reason for hiding this comment

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

Some nitpicking

@@ -68,24 +64,25 @@

class APIClient:
_RESOURCE_PATH: str
_RETRYABLE_POST_ENDPOINT_REGEX_PATTERNS = frozenset(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This type of change is not well suited in a 6K line PR of formatting. cognite-sdk-experimental depends on adding regexes to this set, so we're potentially breaking them here depending on how exactly it's done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree it should probably be put in a separate PR; was a new version of ruff that started complaining about this not being a classvar (as set is ofc mutable).

I see that a "similar" issue has happened before 😉 https://github.com/cognitedata/cognite-sdk-python-experimental/pull/351/files

Conclusion: This change does not affect the experimental SDK, as it is doing s1 |= s2, which is just s1 = s1 + s2, i.e. not an in-place operation. The experimental SDK thus adopts this correction to frozenset without side effects (I've checked all releases back to the "happening" linked above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted the change and will move it to a separate PR 👍

cognite/client/_api/raw.py Outdated Show resolved Hide resolved
@@ -185,7 +178,7 @@ def iterate_data(
external_id: str,
start: str | None = None,
limit: int = DATAPOINT_SUBSCRIPTION_DATA_LIST_LIMIT_DEFAULT,
) -> Iterator[DatapointSubscriptionBatch]:
) -> Generator[DatapointSubscriptionBatch, None, None]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can stay an Iterator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but then we either need to drop pydoclint (you can't convince the maintainer on this one, unfortunately: https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html) or ignore all checks on return types. I think just using Generator is the easy solution here.

@haakonvt haakonvt merged commit 8a9beed into master Aug 25, 2023
7 checks passed
@haakonvt haakonvt deleted the add-pydoclint branch August 25, 2023 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants