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
Conversation
Hey @sarfarazsiddiquii, thanks for the contribution! Do you mind running |
I also think it would be nice to run the API doc string validation in mojo/stdlib/scripts/build-stdlib.sh Line 40 in 20737dc
stdlib.mojopkg (and before we run the tests). What do you think?
I think we should incorporate this |
@JoeLoser Thanks for the feedback, according to your request i have made changes in the codebase and the documentation as well. |
@JoeLoser i am still getting errors ( here - |
stdlib/scripts/run-tests.sh
Outdated
@@ -23,6 +23,12 @@ mkdir -p "${BUILD_DIR}" | |||
|
|||
source "${SCRIPT_DIR}"/build-stdlib.sh | |||
|
|||
echo "Validating API documentation strings in the Standard Library." |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stdlib/docs/style-guide.md
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
stdlib/docs/style-guide.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> 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
stdlib/scripts/build-stdlib.sh
Outdated
@@ -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}" || { |
There was a problem hiding this comment.
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.
stdlib/scripts/run-tests.sh
Outdated
@@ -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" || { |
There was a problem hiding this comment.
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.)
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. |
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 |
292f72d
to
c72738a
Compare
Done. |
- name: Validate documentation strings | ||
run: | | ||
mojo doc -warn-missing-doc-strings -o /dev/null stdlib/src/ | ||
if [ $? -ne 0 ]; then |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stdlib/scripts/run-tests.sh
Outdated
@@ -23,6 +23,12 @@ mkdir -p "${BUILD_DIR}" | |||
|
|||
source "${SCRIPT_DIR}"/build-stdlib.sh | |||
|
|||
echo "Validating API documentation strings in the Standard Library." |
There was a problem hiding this comment.
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.
df44cc8
to
5a2fd67
Compare
@JoeLoser In the commit, I restored the code in the file This commit caused license issue can you help me with it, and also review if the changes i made are correct? |
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>
5a2fd67
to
e614d0c
Compare
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 |
Sure I can do that. In the meantime, you can remove the shebang and just call the script with |
@JoeLoser I did what you suggested however the problem is not yet resolved. |
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. |
Great :) #2444 was opened I think you can close this PR |
This PR solves the issue (ref #2331).
The warnings from
stdlib/src/
have been resolved and integrated into CI.