Skip to content

Commit

Permalink
Add mdformat (#13)
Browse files Browse the repository at this point in the history
* add mdformat

* fix typo

* fix typo

* add hints how to lint
  • Loading branch information
mmacata authored Sep 2, 2023
1 parent 9da41dc commit 7c05e52
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
required: false
type: string
default: '2.17.4'
mdformat-version:
required: false
type: string
default: '0.7.17'

jobs:
flake8:
Expand Down Expand Up @@ -84,3 +88,17 @@ jobs:
- name: Check code style with Black
run: |
black --check --diff --line-length 79 .
mdformat:
name: mdformat
if: ${{ inputs.mdformat-version != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install pip dependencies
run: |
python -m pip install --upgrade pip
pip3 install mdformat==${{ inputs.mdformat-version }}
mdformat --version
- name: Check code style with mdformat
run: |
mdformat --check .
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY .github/workflows/linting.yml $WORKFLOW_LINTING_WORKFLOW
RUN echo black==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."black-version"'.default) >> /requirements.txt
RUN echo flake8==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."flake8-version"'.default) >> /requirements.txt
RUN echo pylint==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."pylint-version"'.default) >> /requirements.txt
RUN echo mdformat==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."mdformat-version"'.default) >> /requirements.txt
RUN pip install -r requirements.txt

# Copy script to be executed on docker startup
Expand Down
41 changes: 38 additions & 3 deletions pre_commit_hooks/linting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fi
RUN_BLACK=TRUE
RUN_FLAKE8=TRUE
RUN_PYLINT=TRUE
RUN_MDFORMAT=TRUE

####################################
# Overwrite linter versions if set #
Expand Down Expand Up @@ -83,6 +84,24 @@ else
echo "- pylint version not overwritten in code workflow"
fi

if [ $(yq '.jobs.lint.with | has("mdformat-version")' $CODE_LINTING_WORKFLOW) == true ]
then
DEFAULT_MDFORMAT_VERSION=$(cat /requirements.txt | grep mdformat== | cut -d "=" -f 3)
NEW_MDFORMAT_VERSION=$(yq '.jobs.lint.with."mdformat-version"' $CODE_LINTING_WORKFLOW)
if [ "$(echo $NEW_MDFORMAT_VERSION | tr '"' 'x')" = "xx" ]
then
RUN_MDFORMAT=FALSE
echo "- mdformat configured to be skipped (empty string)"
elif [ $DEFAULT_MDFORMAT_VERSION != $NEW_MDFORMAT_VERSION ]
then
# sed would fail with Permission denied
# sed -i "s+$DEFAULT_MDFORMAT_VERSION+$NEW_MDFORMAT_VERSION+g" /requirements.txt
echo "- Warning: overwritten mdformat version will not be installed!"
fi
else
echo "- mdformat version not overwritten in code workflow"
fi

echo

###################
Expand All @@ -94,6 +113,7 @@ echo
echo "flake8: `flake8 --version`"
echo "pylint: `pylint --version`"
echo "black: `black --version`"
echo "mdformat: `mdformat --version`"

########
# lint #
Expand Down Expand Up @@ -134,7 +154,7 @@ then
if [ $? -ne 0 ]
then
RETURNCODE=1
FAILINGSTEP="$FAILINGSTEP PYLINT"
FAILINGSTEP="$FAILINGSTEP PYLINT (run 'pylint .')"
fi

echo
Expand All @@ -150,7 +170,7 @@ then
pylint --rc-file=.pylintrc_allowed_to_fail .
else
echo
echo "PYLINT configured to be skipped"
echo "PYLINT configured to be skipped (run 'pylint --rc-file=.pylintrc_allowed_to_fail .')"
fi

if [ $RUN_BLACK != "FALSE" ]
Expand All @@ -161,13 +181,28 @@ then
if [ $? -ne 0 ]
then
RETURNCODE=1
FAILINGSTEP="$FAILINGSTEP BLACK"
FAILINGSTEP="$FAILINGSTEP BLACK (run 'black --check --diff --line-length 79 .')"
fi
else
echo
echo "BLACK configured to be skipped"
fi

if [ $RUN_MDFORMAT != "FALSE" ]
then
echo
echo "MDFORMAT:"
mdformat --check .
if [ $? -ne 0 ]
then
RETURNCODE=1
FAILINGSTEP="$FAILINGSTEP MDFORMAT (run 'mdformat --check .')"
fi
else
echo
echo "MDFORMAT configured to be skipped"
fi

if [ $RETURNCODE -ne 0 ]
then
echo "Failing steps: ${FAILINGSTEP}"
Expand Down

0 comments on commit 7c05e52

Please sign in to comment.