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

Implement Python type checking and docstring validation checks #73

Merged
merged 8 commits into from
Apr 17, 2024

Conversation

maxachis
Copy link
Collaborator

Fixes

  • #213 - This is from data-sources-app, but can be equally applied here.

Description

  • Implemented docstring checks through pydocstyle and added Python checks in Github Actions.
  • The Python checks include running mypy and pydocstyle on modified Python files and commenting the output on the associated pull request.
  • It is designed to only run on files that have been modified in the pull request.

Testing

Testing has already been demonstrated in the following PRs:

  • This PR, which (after a few modifications) showcases how it would work on a PR
  • This other PR, which shows it functioning again, but now only on the new file I've created. The other file, despite not being corrected, is not checked -- it only runs these checks on files that have been modified.

Performance

  • This Github action is quite light, consistently running in under 30 seconds.

Added a Github Action and corresponding script to validate the use of docstrings and type hints in Python code. This action will be triggered on any pull request and it posts information about missing docstrings or type hints directly on the PR. The validation is performed by mypy and pydocstyle. This feature is intended to improve code quality and promote good coding practices.
Copy link

Type Hinting and Docstring Checks

mypy

Success: no issues found in 1 source file

pydocstyle


Copy link
Contributor

@josh-chamberlain josh-chamberlain left a comment

Choose a reason for hiding this comment

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

@maxachis thank you! one thing just occurred to me: what if we made these part of the checks which are pass/fail on PRs? One less comment/notification per PR, seems worth it to me—and I don't believe it prevents you pushing commits/opening PRs

Screen Shot 2024-04-15 at 2 16 45 PM

This commit deletes the script responsible for automatically commenting on Pull Requests with the results of 'mypy' and 'pydocstyle' checks. Additionally, references to this script have been removed from the 'python_checks.yml' GitHub workflow file. As a result, the GitHub actions workflow now only performs the checks without posting comments, simplifying the review process and reducing unnecessary noise in the PR discussion.
This commit simplifies the method of detecting modified Python files in the GitHub Actions workflow file 'python_checks.yml'. Instead of writing the output of 'git diff' command to the environment variable 'MODIFIED_FILES' using multiple lines, it now does so in a single line, thereby improving readability and maintaining cleanliness in the code.
The Python checks in the Github action workflow for mypy and pydocstyle have been updated to capture their respective exit codes. An additional step has been included to observe and react to those exit codes, terminating the workflow with a failure status if any errors are detected in either of the checks.
The python_checks.yml workflow has been updated to continue on error for mypy and pydocstyle checks. This ensures other steps in the workflow continue executing, even if these checks fail, enabling a complete overview of all potential issues.
@maxachis
Copy link
Collaborator Author

maxachis commented Apr 16, 2024

@josh-chamberlain Done. Because I made changes, I won't also perform the merge, so you get to press the fun green button should you find the changes satisfactory✅

@mbodeantor
Copy link
Contributor

@maxachis looks like there is an error in checks still

A condition has been added to the 'Check errors' operation in the Python Checks workflow. This guarantees that the operation will only run if there have been changes to files in the environment, preventing unnecessary execution.
@maxachis
Copy link
Collaborator Author

@maxachis looks like there is an error in checks still

@mbodeantor Thanks for the catch. I needed to make sure it checks for errors only if files have been modified. That's been resolved.

@mbodeantor mbodeantor merged commit 50b102f into main Apr 17, 2024
2 checks passed
@maxachis maxachis deleted the mc_add_pr_type_checking_and_linting branch April 17, 2024 15:51
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