Skip to content

Commit

Permalink
Merge pull request #5 from docker/cm/pylint
Browse files Browse the repository at this point in the history
Pylint
  • Loading branch information
ColinMcNeil authored Aug 7, 2024
2 parents b2ee429 + 8d3de85 commit 5a7ca46
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions functions/pylint/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:alpine3.20

# Install pylint
RUN pip install pylint

# Install bash and jq
RUN apk add --no-cache bash jq

# Copy the lint script
COPY lint.sh /lint.sh
RUN chmod +x /lint.sh

COPY output_format.sh /output_format.sh
RUN chmod +x /output_format.sh

ENTRYPOINT [ "/lint.sh" ]
18 changes: 18 additions & 0 deletions functions/pylint/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

JSON_ARGS=$1

args=$(echo $JSON_ARGS | jq -r '.args')
output_format=$(echo $JSON_ARGS | jq -r '.output_format')

# If no args or args is "null"
if [ -z "$args" ] || [ "$args" == "null" ]; then
args="."
fi

# If no output_format or output_format is "null"
if [ -z "$output_format" ] || [ "$output_format" == "null" ]; then
output_format="summary"
fi

pylint --recursive=y --output-format=json $args | /output_format.sh "$output_format"
35 changes: 35 additions & 0 deletions functions/pylint/output_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

INPUT=$(cat)
FORMAT=$1

if [ "$FORMAT" == "json" ]; then
echo "$INPUT"
exit 0
fi

MESSAGES=$(echo "$INPUT" | jq -r -c '.[]')

if [ "$FORMAT" == "summary" ]; then

TOTAL_MESSAGES=$(echo "$MESSAGES" | wc -l)

TOTAL_AFFECTED_FILES=$(echo $INPUT | jq -r '.[].path' | sort | uniq | wc -l)
echo "Ran pylint and found $TOTAL_MESSAGES messages across $TOTAL_AFFECTED_FILES files."
exit
fi

for MESSAGE in $MESSAGES; do
MESSAGE_TYPE=$(echo "$MESSAGE" | jq -r '.type')
MESSAGE_LINE=$(echo "$MESSAGE" | jq -r '.line')
MESSAGE_COLUMN=$(echo "$MESSAGE" | jq -r '.column')
MESSAGE_PATH=$(echo "$MESSAGE" | jq -r '.path')
MESSAGE_FILE=$(echo "$MESSAGE" | jq -r '.file')
MESSAGE_SYMBOL=$(echo "$MESSAGE" | jq -r '.symbol')
MESSAGE_MESSAGE=$(echo "$MESSAGE" | jq -r '.message')
# If condensed
if [ "$FORMAT" == "condensed" ]; then
echo "$MESSAGE_TYPE: $MESSAGE_CODE"
continue
fi
done
1 change: 1 addition & 0 deletions prompts/pylint/010_system_prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You are an assistant who specializes in running pylint.
4 changes: 4 additions & 0 deletions prompts/pylint/020_user_prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Lint python files in my project using 'condensed' .

Report the response.
13 changes: 13 additions & 0 deletions prompts/pylint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
functions:
- name: pylint
description: Runs pylint against current project
parameters:
type: object
properties:
output_format:
type: string
description: The output level to use. `summary` | `json` | `condensed` | `complaints`
container:
image: vonwig/pylint:latest
---

0 comments on commit 5a7ca46

Please sign in to comment.