Skip to content

Commit 5a7ca46

Browse files
authored
Merge pull request #5 from docker/cm/pylint
Pylint
2 parents b2ee429 + 8d3de85 commit 5a7ca46

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

functions/pylint/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:alpine3.20
2+
3+
# Install pylint
4+
RUN pip install pylint
5+
6+
# Install bash and jq
7+
RUN apk add --no-cache bash jq
8+
9+
# Copy the lint script
10+
COPY lint.sh /lint.sh
11+
RUN chmod +x /lint.sh
12+
13+
COPY output_format.sh /output_format.sh
14+
RUN chmod +x /output_format.sh
15+
16+
ENTRYPOINT [ "/lint.sh" ]

functions/pylint/lint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
JSON_ARGS=$1
4+
5+
args=$(echo $JSON_ARGS | jq -r '.args')
6+
output_format=$(echo $JSON_ARGS | jq -r '.output_format')
7+
8+
# If no args or args is "null"
9+
if [ -z "$args" ] || [ "$args" == "null" ]; then
10+
args="."
11+
fi
12+
13+
# If no output_format or output_format is "null"
14+
if [ -z "$output_format" ] || [ "$output_format" == "null" ]; then
15+
output_format="summary"
16+
fi
17+
18+
pylint --recursive=y --output-format=json $args | /output_format.sh "$output_format"

functions/pylint/output_format.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
INPUT=$(cat)
4+
FORMAT=$1
5+
6+
if [ "$FORMAT" == "json" ]; then
7+
echo "$INPUT"
8+
exit 0
9+
fi
10+
11+
MESSAGES=$(echo "$INPUT" | jq -r -c '.[]')
12+
13+
if [ "$FORMAT" == "summary" ]; then
14+
15+
TOTAL_MESSAGES=$(echo "$MESSAGES" | wc -l)
16+
17+
TOTAL_AFFECTED_FILES=$(echo $INPUT | jq -r '.[].path' | sort | uniq | wc -l)
18+
echo "Ran pylint and found $TOTAL_MESSAGES messages across $TOTAL_AFFECTED_FILES files."
19+
exit
20+
fi
21+
22+
for MESSAGE in $MESSAGES; do
23+
MESSAGE_TYPE=$(echo "$MESSAGE" | jq -r '.type')
24+
MESSAGE_LINE=$(echo "$MESSAGE" | jq -r '.line')
25+
MESSAGE_COLUMN=$(echo "$MESSAGE" | jq -r '.column')
26+
MESSAGE_PATH=$(echo "$MESSAGE" | jq -r '.path')
27+
MESSAGE_FILE=$(echo "$MESSAGE" | jq -r '.file')
28+
MESSAGE_SYMBOL=$(echo "$MESSAGE" | jq -r '.symbol')
29+
MESSAGE_MESSAGE=$(echo "$MESSAGE" | jq -r '.message')
30+
# If condensed
31+
if [ "$FORMAT" == "condensed" ]; then
32+
echo "$MESSAGE_TYPE: $MESSAGE_CODE"
33+
continue
34+
fi
35+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You are an assistant who specializes in running pylint.

prompts/pylint/020_user_prompt.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Lint python files in my project using 'condensed' .
3+
4+
Report the response.

prompts/pylint/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
functions:
3+
- name: pylint
4+
description: Runs pylint against current project
5+
parameters:
6+
type: object
7+
properties:
8+
output_format:
9+
type: string
10+
description: The output level to use. `summary` | `json` | `condensed` | `complaints`
11+
container:
12+
image: vonwig/pylint:latest
13+
---

0 commit comments

Comments
 (0)