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

[tools] Fix API doc string validation #2344

Closed

Conversation

sarfarazsiddiquii
Copy link

This PR solves the issue (ref #2331).

The warnings from stdlib/src/ have been resolved and integrated into CI.

@sarfarazsiddiquii sarfarazsiddiquii requested a review from a team as a code owner April 19, 2024 22:40
@JoeLoser JoeLoser changed the title Fix: API doc string validation [tools] Fix API doc string validation Apr 19, 2024
@JoeLoser
Copy link
Collaborator

Hey @sarfarazsiddiquii, thanks for the contribution! Do you mind running mojo format stdlib/src/collections/optional.mojo to fix the CI error here? I think it would also be great to mention the API doc string validation in the contributing or style guide, maybe somewhere after this section.

@JoeLoser JoeLoser requested a review from modocache April 19, 2024 23:37
@JoeLoser
Copy link
Collaborator

I also think it would be nice to run the API doc string validation in

mojo package "${STDLIB_PATH}" -o "${FULL_STDLIB_PACKAGE_PATH}"
for example after we build the stdlib.mojopkg (and before we run the tests). What do you think?

I think we should incorporate this mojo doc validate command in our scripts in some shape or form so developers are notified of any issues before CI fails. WDYT @ConnorGray?

@sarfarazsiddiquii
Copy link
Author

@JoeLoser Thanks for the feedback, according to your request i have made changes in the codebase and the documentation as well.

@sarfarazsiddiquii
Copy link
Author

sarfarazsiddiquii commented Apr 20, 2024

@JoeLoser i am still getting errors ( here -
Standard Library tests and examples / test-examples) after new changes, can you help me?

stdlib/scripts/build-stdlib.sh Outdated Show resolved Hide resolved
@@ -23,6 +23,12 @@ mkdir -p "${BUILD_DIR}"

source "${SCRIPT_DIR}"/build-stdlib.sh

echo "Validating API documentation strings in the Standard Library."
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, testing the docstrings is more something to do when a PR is nearly done. Something like a pre-commit.
Contributors might want to run tests without checking the docstrings first.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree this is more akin to mojo format sort of thing - something needed to be fixed up prior to landing a PR. After this lands, do you have any interest in exploring hooking this up with the pre-commit things you've set up recently? I think that would be great.

@@ -59,6 +59,15 @@ pre-commit install
```
and that's it!

#### API Doc String Validation

Mojo provides a command line utility, `mojo doc validate`, to validate the API doc strings in your code. This ensures that your doc strings are correctly formatted and consistent with the Mojo style guidelines.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Mojo provides a command line utility, `mojo doc validate`, to validate the API doc strings in your code. This ensures that your doc strings are correctly formatted and consistent with the Mojo style guidelines.
Mojo provides a command line utility, `mojo doc`, to validate the API doc strings in your code. This ensures that your doc strings are correctly formatted and consistent with the Mojo style guidelines.

Mojo provides a command line utility, `mojo doc validate`, to validate the API doc strings in your code. This ensures that your doc strings are correctly formatted and consistent with the Mojo style guidelines.

```bash
> mojo doc validate example.mojo
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
> mojo doc validate example.mojo
> mojo doc -warn-missing-doc-strings -o /dev/null example.mojo

mojo doc validate doesn't exist. It's mojo doc

@@ -39,4 +39,11 @@ STDLIB_PACKAGE_NAME="stdlib.mojopkg"
FULL_STDLIB_PACKAGE_PATH="${BUILD_DIR}"/"${STDLIB_PACKAGE_NAME}"
mojo package "${STDLIB_PATH}" -o "${FULL_STDLIB_PACKAGE_PATH}"

echo "Validating API documentation strings in the Standard Library."

mojo doc validate "${STDLIB_PATH}" || {
Copy link
Contributor

Choose a reason for hiding this comment

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

mojo doc validate doesn't exist, it's mojo doc. This is what causes the CI to fail.

@@ -23,6 +23,12 @@ mkdir -p "${BUILD_DIR}"

source "${SCRIPT_DIR}"/build-stdlib.sh

echo "Validating API documentation strings in the Standard Library."
mojo doc validate "${REPO_ROOT}/stdlib/src" || {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, mojo doc validate doesn't exist. It's mojo doc, this is why the CI Doesn't understand what is going on (but I think the error message is not correct, mojo doc should output that the directory validate doesn't exist.)

@sarfarazsiddiquii
Copy link
Author

Thank you, @gabrieldemarmiesse, for pointing out the issues in my previous commits. I have resolved all the errors as suggested, and everything seems to be working as expected. Please let me know if there are any other changes required in this PR.

@gabrieldemarmiesse
Copy link
Contributor

Looks good! The only thing missing is the DCO. Take a look at the instructions here: https://github.com/modularml/mojo/pull/2344/checks?check_run_id=24070604633

@sarfarazsiddiquii
Copy link
Author

Looks good! The only thing missing is the DCO. Take a look at the instructions here: https://github.com/modularml/mojo/pull/2344/checks?check_run_id=24070604633

Done.

- name: Validate documentation strings
run: |
mojo doc -warn-missing-doc-strings -o /dev/null stdlib/src/
if [ $? -ne 0 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion Unfortunately, this won't work as you hope since the above command still exits with exit code 0 since it produces warnings (not errors). You can verify this locally:

 mojo doc -warn-missing-doc-strings -o /dev/null stdlib/src/
Included from /Users/joe/dev/mojo/stdlib/src/collections/__init__.mojo:1:
/Users/joe/dev/mojo/stdlib/src/collections/dict.mojo:49:7: warning: public symbol 'StringableKeyElement' is missing a doc string
trait StringableKeyElement(KeyElement, Stringable):
      ^
Included from /Users/joe/dev/mojo/stdlib/src/os/__init__.mojo:1:
/Users/joe/dev/mojo/stdlib/src/os/os.mojo:274:4: warning: function takes parameters, but no 'Parameters' in doc string
fn remove[pathlike: os.PathLike](path: pathlike) raises:
   ^
Included from /Users/joe/dev/mojo/stdlib/src/os/__init__.mojo:1:
/Users/joe/dev/mojo/stdlib/src/os/os.mojo:298:4: warning: function takes parameters, but no 'Parameters' in doc string
fn unlink[pathlike: os.PathLike](path: pathlike) raises:
   ^
Included from /Users/joe/dev/mojo/stdlib/src/testing/__init__.mojo:1:
/Users/joe/dev/mojo/stdlib/src/testing/testing.mojo:115:4: warning: function takes parameters, but no 'Parameters' in doc string
fn assert_equal[T: Testable](lhs: T, rhs: T, msg: String = "") raises:
   ^
Included from /Users/joe/dev/mojo/stdlib/src/testing/__init__.mojo:1:
/Users/joe/dev/mojo/stdlib/src/testing/testing.mojo:175:4: warning: function takes parameters, but no 'Parameters' in doc string
fn assert_not_equal[T: Testable](lhs: T, rhs: T, msg: String = "") raises:

combined with echo $? which reports the exit code of 0.

To "fix" this problem, you can use the check-file-is-empty.py script from #2118 that got removed (just bring it back for this PR).

Longer term, I think we should file a GitHub issue and have a discussion with @River707 and @modocache on their take on this command. The current structure of producing warnings for invalid API doc strings and exiting with an exit code of 0, in my opinion, pushes complexity to every user (such as with this check-file-is-empty.py script). I'd rather have some option (even if it's -error-missing-doc-strings or name to be bikeshedded) which would give me a non-zero exit code if there are any invalid doc strings. I think that will be the common use case for users of this command.

Copy link
Author

Choose a reason for hiding this comment

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

That is correct, i will look into it and make changes accordingly by looking at the mentioned file.

@@ -23,6 +23,12 @@ mkdir -p "${BUILD_DIR}"

source "${SCRIPT_DIR}"/build-stdlib.sh

echo "Validating API documentation strings in the Standard Library."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree this is more akin to mojo format sort of thing - something needed to be fixed up prior to landing a PR. After this lands, do you have any interest in exploring hooking this up with the pre-commit things you've set up recently? I think that would be great.

@sarfarazsiddiquii
Copy link
Author

sarfarazsiddiquii commented Apr 21, 2024

@JoeLoser In the commit, I restored the code in the file check-file-is-empty.py, and integrated it into Standard Library tests and examples which will check if the file warnings.txt contains any warnings. If the file is not empty, meaning it has warnings, the test will fail.

This commit caused license issue can you help me with it, and also review if the changes i made are correct?
Thank you.

Signed-off-by: sarfaraz siddiqui <sarfarazsiddiqui199@gmail.com>
Signed-off-by: sarfaraz siddiqui <sarfarazsiddiqui199@gmail.com>
Signed-off-by: sarfaraz siddiqui <sarfarazsiddiqui199@gmail.com>
Signed-off-by: sarfaraz siddiqui <sarfarazsiddiqui199@gmail.com>
Signed-off-by: sarfaraz siddiqui <sarfarazsiddiqui199@gmail.com>
@JoeLoser
Copy link
Collaborator

@JoeLoser In the commit, I restored the code in the file check-file-is-empty.py, and integrated it into Standard Library tests and examples which will check if the file warnings.txt contains any warnings. If the file is not empty, meaning it has warnings, the test will fail.

This commit caused license issue can you help me with it, and also review if the changes i made are correct? Thank you.

Hey! Sorry for the delay in response — I was on PTO earlier this week. The CI failure here is trying to tell you that we need to add the license part at the top of the file of stdlib/scripts/check-file-is-empty.py. However, you already have the license, so I suspect this is an issue with the license file checker itself. Specifically, this line assumes the first line will be the beginning of the license itself. However, in your case, it's a shebang, meaning the check won't pass, pedantically. To fix this, one approach would be to do a little bit of parsing (see if it starts with ! and if so, skip that line (when you hit a newline character)) and assume the rest of the file is license + rest. Then you can keep the same startswith logic for the license, etc. Thoughts, @gabrieldemarmiesse?

@gabrieldemarmiesse
Copy link
Contributor

Sure I can do that. In the meantime, you can remove the shebang and just call the script with python3 path_to_script.py that should do the trick

@sarfarazsiddiquii sarfarazsiddiquii requested a review from a team as a code owner April 28, 2024 15:24
@sarfarazsiddiquii
Copy link
Author

@JoeLoser I did what you suggested however the problem is not yet resolved.
Can you help me with it.

@gabrieldemarmiesse
Copy link
Contributor

Hi, I took at look at the pull request and saw that if we incorporated it in the pre-commit hook, it should make things much simpler. I pulled your commits and modified the code a bit more and arrived at this result: nightly...gabrieldemarmiesse:mojo:include_to_pre_commit

@sarfarazsiddiquii Do you think I should open a new PR with my branch? Or do you want to pull my commits to your branch maybe? It's as you wish. If I make a new PR with my branch, since your commits are there, you'll still be credited as one of the authors.

@sarfarazsiddiquii
Copy link
Author

Hi, I took at look at the pull request and saw that if we incorporated it in the pre-commit hook, it should make things much simpler. I pulled your commits and modified the code a bit more and arrived at this result: nightly...gabrieldemarmiesse:mojo:include_to_pre_commit

@sarfarazsiddiquii Do you think I should open a new PR with my branch? Or do you want to pull my commits to your branch maybe? It's as you wish. If I make a new PR with my branch, since your commits are there, you'll still be credited as one of the authors.

Thanks @gabrieldemarmiesse for helping me on this issue. I think you should open a new PR since it has both our contributions.

@gabrieldemarmiesse
Copy link
Contributor

Great :) #2444 was opened I think you can close this PR

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.

None yet

4 participants