-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03e22be
API doc string validation
sarfarazsiddiquii c8df61e
Enhancement in code
sarfarazsiddiquii 1a4cfac
error in ren-tests.sh
sarfarazsiddiquii 3f55494
resolving mojo doc
sarfarazsiddiquii e614d0c
added a script to check for warnings
sarfarazsiddiquii 411fd9a
Fixed check-licences.mojo
sarfarazsiddiquii 46cd39f
Resolved merge conflicts
sarfarazsiddiquii File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
# ===----------------------------------------------------------------------=== # | ||
# Copyright (c) 2024, Modular Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions: | ||
# https://llvm.org/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ===----------------------------------------------------------------------=== # | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description=( | ||
"Exits successfully if the file at the given path is empty or does" | ||
" not exist. Otherwise, prints the file's contents, then exits" | ||
" unsuccessfully." | ||
) | ||
) | ||
parser.add_argument("path") | ||
args = parser.parse_args() | ||
|
||
if not os.path.exists(args.path): | ||
return | ||
|
||
with open(args.path, "r") as f: | ||
content = f.read().strip() | ||
if content: | ||
print( | ||
f"error: '{args.path}' is not empty:\n{content}", | ||
file=sys.stderr, | ||
) | ||
exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:combined with
echo $?
which reports the exit code of0
.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 thischeck-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.