Skip to content

Commit 7c05e52

Browse files
authored
Add mdformat (#13)
* add mdformat * fix typo * fix typo * add hints how to lint
1 parent 9da41dc commit 7c05e52

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

.github/workflows/linting.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
required: false
1616
type: string
1717
default: '2.17.4'
18+
mdformat-version:
19+
required: false
20+
type: string
21+
default: '0.7.17'
1822

1923
jobs:
2024
flake8:
@@ -84,3 +88,17 @@ jobs:
8488
- name: Check code style with Black
8589
run: |
8690
black --check --diff --line-length 79 .
91+
mdformat:
92+
name: mdformat
93+
if: ${{ inputs.mdformat-version != '' }}
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v3
97+
- name: Install pip dependencies
98+
run: |
99+
python -m pip install --upgrade pip
100+
pip3 install mdformat==${{ inputs.mdformat-version }}
101+
mdformat --version
102+
- name: Check code style with mdformat
103+
run: |
104+
mdformat --check .

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COPY .github/workflows/linting.yml $WORKFLOW_LINTING_WORKFLOW
1414
RUN echo black==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."black-version"'.default) >> /requirements.txt
1515
RUN echo flake8==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."flake8-version"'.default) >> /requirements.txt
1616
RUN echo pylint==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."pylint-version"'.default) >> /requirements.txt
17+
RUN echo mdformat==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."mdformat-version"'.default) >> /requirements.txt
1718
RUN pip install -r requirements.txt
1819

1920
# Copy script to be executed on docker startup

pre_commit_hooks/linting.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fi
2424
RUN_BLACK=TRUE
2525
RUN_FLAKE8=TRUE
2626
RUN_PYLINT=TRUE
27+
RUN_MDFORMAT=TRUE
2728

2829
####################################
2930
# Overwrite linter versions if set #
@@ -83,6 +84,24 @@ else
8384
echo "- pylint version not overwritten in code workflow"
8485
fi
8586

87+
if [ $(yq '.jobs.lint.with | has("mdformat-version")' $CODE_LINTING_WORKFLOW) == true ]
88+
then
89+
DEFAULT_MDFORMAT_VERSION=$(cat /requirements.txt | grep mdformat== | cut -d "=" -f 3)
90+
NEW_MDFORMAT_VERSION=$(yq '.jobs.lint.with."mdformat-version"' $CODE_LINTING_WORKFLOW)
91+
if [ "$(echo $NEW_MDFORMAT_VERSION | tr '"' 'x')" = "xx" ]
92+
then
93+
RUN_MDFORMAT=FALSE
94+
echo "- mdformat configured to be skipped (empty string)"
95+
elif [ $DEFAULT_MDFORMAT_VERSION != $NEW_MDFORMAT_VERSION ]
96+
then
97+
# sed would fail with Permission denied
98+
# sed -i "s+$DEFAULT_MDFORMAT_VERSION+$NEW_MDFORMAT_VERSION+g" /requirements.txt
99+
echo "- Warning: overwritten mdformat version will not be installed!"
100+
fi
101+
else
102+
echo "- mdformat version not overwritten in code workflow"
103+
fi
104+
86105
echo
87106

88107
###################
@@ -94,6 +113,7 @@ echo
94113
echo "flake8: `flake8 --version`"
95114
echo "pylint: `pylint --version`"
96115
echo "black: `black --version`"
116+
echo "mdformat: `mdformat --version`"
97117

98118
########
99119
# lint #
@@ -134,7 +154,7 @@ then
134154
if [ $? -ne 0 ]
135155
then
136156
RETURNCODE=1
137-
FAILINGSTEP="$FAILINGSTEP PYLINT"
157+
FAILINGSTEP="$FAILINGSTEP PYLINT (run 'pylint .')"
138158
fi
139159

140160
echo
@@ -150,7 +170,7 @@ then
150170
pylint --rc-file=.pylintrc_allowed_to_fail .
151171
else
152172
echo
153-
echo "PYLINT configured to be skipped"
173+
echo "PYLINT configured to be skipped (run 'pylint --rc-file=.pylintrc_allowed_to_fail .')"
154174
fi
155175

156176
if [ $RUN_BLACK != "FALSE" ]
@@ -161,13 +181,28 @@ then
161181
if [ $? -ne 0 ]
162182
then
163183
RETURNCODE=1
164-
FAILINGSTEP="$FAILINGSTEP BLACK"
184+
FAILINGSTEP="$FAILINGSTEP BLACK (run 'black --check --diff --line-length 79 .')"
165185
fi
166186
else
167187
echo
168188
echo "BLACK configured to be skipped"
169189
fi
170190

191+
if [ $RUN_MDFORMAT != "FALSE" ]
192+
then
193+
echo
194+
echo "MDFORMAT:"
195+
mdformat --check .
196+
if [ $? -ne 0 ]
197+
then
198+
RETURNCODE=1
199+
FAILINGSTEP="$FAILINGSTEP MDFORMAT (run 'mdformat --check .')"
200+
fi
201+
else
202+
echo
203+
echo "MDFORMAT configured to be skipped"
204+
fi
205+
171206
if [ $RETURNCODE -ne 0 ]
172207
then
173208
echo "Failing steps: ${FAILINGSTEP}"

0 commit comments

Comments
 (0)