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

Programming exercises: Add static code analysis for Python exercises with integrated code lifecycle #9573

Merged
merged 36 commits into from
Dec 20, 2024

Conversation

magaupp
Copy link
Contributor

@magaupp magaupp commented Oct 23, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I documented the Java code using JavaDoc style.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).

Motivation and Context

Static Code Analysis is currently not supported for Python.

Description

This PR adds the Ruff static code analysis tool for Python.
Each issue is categorized according to its Ruff tool.

The PR also enables file overrides for static code analysis in exercise templates.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Course
  1. Navigate to the exercise creation page
  2. Switch to advanced mode
  3. Select Python as the language
  4. Enable the check box for Enable Static Code Analysis
  5. Fill out the rest of the required fields
  6. Verify that the builds finish without errors
  7. Click on the Solution result
  8. Verify that 4 Code Issue warnings are displayed
  9. Close the feedback window
  10. Scroll to the top and click the Grading button
  11. Click the Code Analysis tab
  12. Verify that categories for each Ruff tool are shown

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Server

Class/File Line Coverage Confirmation (assert/expect)
StaticCodeAnalysisConfigurer.java 99%
StaticCodeAnalysisTool.java 100%
ProgrammingExerciseRepositoryService.java 86%
LocalCIProgrammingLanguageFeatureService.java 100%
ParserPolicy.java 89%
RuffCategorizer.java 100%

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced support for Python-specific static code analysis using the "RUFF" tool.
    • Added a new script for static code analysis and testing in Python projects.
    • Enhanced repository setup to include static code analysis resources.
    • Implemented a new categorization strategy for the "RUFF" tool.
  • Bug Fixes

    • Improved handling of static code analysis reports and parsing for the "RUFF" tool.
  • Tests

    • Added unit tests for the "RUFF" parser to ensure accurate report handling.
  • Documentation

    • New JSON and SARIF files added to provide structured analysis results from the "RUFF" tool.

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) config-change Pull requests that change the config in a way that they require a deployment via Ansible. template buildagent Pull requests that affect the corresponding module core Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module labels Oct 23, 2024
@magaupp magaupp changed the title Programming exercises: Add Ruff SCA for Python Programming exercises: Add Ruff SCA for Python to LocalCI Oct 23, 2024
@magaupp magaupp force-pushed the feature/programming-exercises/python-sca branch from 41becc3 to 9802cae Compare October 23, 2024 20:48
Copy link

coderabbitai bot commented Oct 23, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 pmd (7.7.0)
src/test/java/de/tum/cit/aet/artemis/programming/StaticCodeAnalysisParserUnitTest.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

Walkthrough

The pull request introduces enhancements to support Python-specific static code analysis within the existing framework. Key additions include the RUFF static code analysis tool, new category definitions for Python, and modifications to various services and configurations to integrate these changes. A new Bash script for static analysis operations is also included, alongside updates to unit tests and expected results for the RUFF tool.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/core/config/StaticCodeAnalysisConfigurer.java Added support for Python static code analysis with new categories and a method to create default categories.
src/main/java/de/tum/cit/aet/artemis/programming/domain/StaticCodeAnalysisTool.java Introduced RUFF tool to the static analysis tools enum and updated the programming language mapping.
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseRepositoryService.java Enhanced repository service to manage static code analysis resources and updated the record structure.
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/LocalCIProgrammingLanguageFeatureService.java Modified configuration for Python programming language features.
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/strategy/ParserPolicy.java Updated to handle RUFF in the parsing strategy for static code analysis.
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/strategy/sarif/RuffCategorizer.java Introduced RuffCategorizer class for categorizing rules from RUFF.
src/main/resources/templates/aeolus/python/default_static.sh Added a new Bash script for static analysis and testing of Python projects.
src/test/java/de/tum/cit/aet/artemis/programming/StaticCodeAnalysisParserUnitTest.java Added a test for the RUFF parser functionality.
src/test/java/de/tum/cit/aet/artemis/programming/util/ProgrammingExerciseFactory.java Updated to handle RUFF in static code analysis issue generation.
src/test/resources/test-data/static-code-analysis/expected/ruff.json Introduced a new JSON file with static code analysis results from RUFF.
src/test/resources/test-data/static-code-analysis/reports/ruff.sarif Added a SARIF report detailing errors identified by the RUFF tool.

Possibly related PRs

Suggested labels

client, documentation, bugfix

Suggested reviewers

  • SimonEntholzer
  • az108
  • JohannesStoehr
  • b-fein
  • krusche

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between abce358 and 60d5164.

📒 Files selected for processing (1)
  • src/test/java/de/tum/cit/aet/artemis/programming/StaticCodeAnalysisParserUnitTest.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/de/tum/cit/aet/artemis/programming/StaticCodeAnalysisParserUnitTest.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@magaupp magaupp force-pushed the feature/programming-exercises/python-sca branch from 9802cae to 9d809ef Compare October 27, 2024 12:35
@magaupp magaupp changed the base branch from develop to feature/programming-exercises/sarif-parser October 27, 2024 12:39
@magaupp magaupp added the stacked-pr PR that depends on another PR label Oct 27, 2024
@magaupp magaupp mentioned this pull request Oct 27, 2024
13 tasks
Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

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

Tested on Ts1, works as expected

Copy link
Member

@BBesrour BBesrour left a comment

Choose a reason for hiding this comment

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

Tested on TS2, Solution shows 4 warnings. Successfully fixed some of them.

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

Tested on TS2. Works as described

Screenshot 2024-12-18 224415
Screenshot 2024-12-18 224429
Screenshot 2024-12-18 224513

@magaupp magaupp requested a review from a team as a code owner December 19, 2024 12:23
@AjayvirS AjayvirS self-requested a review December 19, 2024 17:59
Copy link
Contributor

@AjayvirS AjayvirS left a comment

Choose a reason for hiding this comment

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

code

Copy link
Contributor

@coolchock coolchock left a comment

Choose a reason for hiding this comment

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

code lgtm

@krusche krusche changed the title Programming exercises: Add Ruff SCA for Python to LocalCI Programming exercises: Add static code analysis for Python exercises with integrated code lifecycle Dec 20, 2024
@krusche krusche added this to the 7.8.0 milestone Dec 20, 2024
@krusche krusche merged commit c46a670 into develop Dec 20, 2024
32 of 35 checks passed
@krusche krusche deleted the feature/programming-exercises/python-sca branch December 20, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config-change Pull requests that change the config in a way that they require a deployment via Ansible. core Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!) template tests
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants