-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programming exercises: Add static code analysis for Python exercises …
…with integrated code lifecycle (#9573)
- Loading branch information
Showing
14 changed files
with
468 additions
and
13 deletions.
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
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
15 changes: 15 additions & 0 deletions
15
...cit/aet/artemis/programming/service/localci/scaparser/strategy/sarif/RuffCategorizer.java
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,15 @@ | ||
package de.tum.cit.aet.artemis.programming.service.localci.scaparser.strategy.sarif; | ||
|
||
import java.util.Map; | ||
|
||
import de.tum.cit.aet.artemis.programming.service.localci.scaparser.format.sarif.PropertyBag; | ||
import de.tum.cit.aet.artemis.programming.service.localci.scaparser.format.sarif.ReportingDescriptor; | ||
|
||
public class RuffCategorizer implements RuleCategorizer { | ||
|
||
@Override | ||
public String categorizeRule(ReportingDescriptor rule) { | ||
Map<String, Object> properties = rule.getOptionalProperties().map(PropertyBag::additionalProperties).orElseGet(Map::of); | ||
return properties.getOrDefault("kind", "Unknown").toString(); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/resources/templates/aeolus/python/default_static.sh
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,30 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
export AEOLUS_INITIAL_DIRECTORY=${PWD} | ||
static_code_analysis () { | ||
echo '⚙️ executing static_code_analysis' | ||
ruff check --config=ruff-student.toml --output-format=sarif --output-file=ruff.sarif --exit-zero "${studentParentWorkingDirectoryName}" | ||
} | ||
|
||
build_and_test_the_code () { | ||
echo '⚙️ executing build_and_test_the_code' | ||
python3 -m compileall . -q || error=true | ||
if [ ! $error ] | ||
then | ||
pytest --junitxml=test-reports/results.xml | ||
fi | ||
} | ||
|
||
main () { | ||
if [[ "${1}" == "aeolus_sourcing" ]]; then | ||
return 0 # just source to use the methods in the subshell, no execution | ||
fi | ||
local _script_name | ||
_script_name=${BASH_SOURCE[0]:-$0} | ||
cd "${AEOLUS_INITIAL_DIRECTORY}" | ||
bash -c "source ${_script_name} aeolus_sourcing; static_code_analysis" | ||
cd "${AEOLUS_INITIAL_DIRECTORY}" | ||
bash -c "source ${_script_name} aeolus_sourcing; build_and_test_the_code" | ||
} | ||
|
||
main "${@}" |
21 changes: 21 additions & 0 deletions
21
src/main/resources/templates/aeolus/python/default_static.yaml
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,21 @@ | ||
api: v0.0.1 | ||
actions: | ||
- name: static_code_analysis | ||
script: ruff check --config=ruff-student.toml --output-format=sarif --output-file=ruff.sarif --exit-zero "${studentParentWorkingDirectoryName}" | ||
results: | ||
- name: ruff | ||
path: ruff.sarif | ||
type: sca | ||
- name: build_and_test_the_code | ||
script: |- | ||
python3 -m compileall . -q || error=true | ||
if [ ! $error ] | ||
then | ||
pytest --junitxml=test-reports/results.xml | ||
fi | ||
runAlways: false | ||
results: | ||
- name: junit_test-reports/*results.xml | ||
path: test-reports/*results.xml | ||
type: junit | ||
before: true |
35 changes: 35 additions & 0 deletions
35
src/main/resources/templates/python/staticCodeAnalysis/test/ruff-student.toml
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,35 @@ | ||
[lint] | ||
select = [ | ||
# Pyflakes | ||
"F", | ||
# pycodestyle | ||
"E", "W", | ||
# isort | ||
"I", | ||
# flake8-async | ||
"ASYNC", | ||
# flake8-bugbear | ||
"B", | ||
# flake8-comprehensions | ||
"C4", | ||
# flake8-pie | ||
"PIE", | ||
# flake8-return | ||
"RET", | ||
# flake8-self | ||
"SLF", | ||
# flake8-simplify | ||
"SIM", | ||
# flake8-unused-arguments | ||
"ARG", | ||
# pandas-vet | ||
"PD", | ||
# Pylint | ||
"PL", | ||
# NumPy-specific rules | ||
"NPY", | ||
# refurb | ||
"FURB", | ||
# Ruff-specific rules | ||
"RUF", | ||
] |
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.