diff --git a/.github/workflows/all-lints.yml b/.github/workflows/all-lints.yml index d08d13c..cc58a34 100644 --- a/.github/workflows/all-lints.yml +++ b/.github/workflows/all-lints.yml @@ -14,3 +14,4 @@ jobs: use-check-manifest: false use-pyroma: false extra-rstcheck-options: "-r" + docformatter-version: "==1.5.0" diff --git a/Dockerfile b/Dockerfile index 1c97250..4cafb32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Container image that runs your code -FROM weibullguy/python-lint-image:1.10.0 +FROM python:3.10-alpine3.16 # Copies your code file from your action repository to the filesystem path `/` of the container COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index 4c1a310..f252fe0 100644 --- a/README.md +++ b/README.md @@ -31,16 +31,17 @@ recommended that the tools you use in this action be used in-line with your editor or IDE and/or as pre-commit hooks. This action just verifies you didn't forget to do that. -However, you could choose to have fixes applied by each tool. If you do, it's -recommended that the autoformatters come first, followed by the style checking -tools to verify the autoformatter results. After this, the type checkers and -linters can be run. - All tools are enabled by default with the exception of black and yapf. It's certainly your prerogative to use as many autoformatters as you'd like, but I recommend using only one. Which you choose should be enabled with the use-black or use-yapf input. +Each run of the action creates a virtual environment. Each of the enabled +tools is installed in this virtual environment before that tool is executed. +The default name of the virtual environment is ```python-lint-plus```, but you +can set it to whatever you'd like with the ```virtual-env``` option. +This can be helpful if your running a matrix of various versions of python. + ## Usage See [action.yml](action.yml) @@ -61,21 +62,37 @@ steps: - uses: weibullguy/python-lint-plus@master with: python-root-list: "tests" + virtual-env: "python-lint-plus" use-black: false + black-version: use-yapf: false + yapf-version: use-isort: false + isort-version: use-docformatter: false + docformatter-version: use-pycodestyle: false + pycodestyle-version: use-autopep8: false + autopep8-version: use-pydocstyle: false + pydocstyle-version: use-mypy: false + mypy-version: use-pylint: false + pylint-version: use-flake8: false + flake8-version: use-mccabe: false + mccabe-version: use-radon: false + radon-version: use-rstcheck: false + rstcheck-version: use-check-manifest: false + check-manifest-version: use-pyroma: false + pyroma-version: extra-black-options: "" extra-yapf-options: "" extra-isort-options: "" @@ -136,7 +153,8 @@ steps: - uses: actions/checkout@v2 - uses: weibullguy/python-lint-plus@master with: - python-root-list: "python_alelo tests" + python-root-list: "tests" + virtual-environment: "python-lint-plus" use-radon: true extra-radon-options: "cc -s" ``` @@ -144,9 +162,27 @@ steps: To run multiple radon checks, you'll need to add a step for each in your workflow file. -## Versions used +## Tool Versions Used -To identify the version used you must consult the [CHANGELOG.md](https://github.com/weibullguy/python-lint-image/blob/master/CHANGELOG.md) of the image used in the [Dockerfile](Dockerfile). +If the version input is left unset, the action will use the latest version of +the tool available on PyPi. In the following example action.yml, the +docformatter version used will be 1.5.0, the isort version used will be the +latest available on PyPi, and the pydocstyle version used will be the latest +available on PyPi with a version number greater than or equal to 6.1.0. + +```yml +steps: + - uses: actions/checkout@v2 + - uses: weibullguy/python-lint-plus@master + with: + python-root-list: "tests" + virtual-env: "python-lint-plus" + use-docformatter: true + docformatter-version: "==1.5.0" + use-isort: true + use-pydocstyle: true + pydocstyle-version: ">=6.1.0" +``` ## License diff --git a/action.yml b/action.yml index fc67d61..8506d5b 100644 --- a/action.yml +++ b/action.yml @@ -5,66 +5,130 @@ inputs: description: "A list of all paths to test" required: false default: "." + virtual-env: + description: "The name of the virtual environment to use for running the tools" + required: false + default: "python-lint-plus" use-black: description: "Use Black" required: false default: false + black-version: + description: "The version of black to use" + required: false + default: "" use-yapf: description: "Use yapf" required: false default: false + yapf-version: + description: "The version of yapf to use" + required: false + default: "" use-isort: description: "Use isort" required: false default: true + isort-version: + description: "The version of isort to use" + required: false + default: "" use-docformatter: description: "Use docformatter" required: false default: true + docformatter-version: + description: "The version of docformatter to use" + required: false + default: "" use-pycodestyle: description: "Use pycodestyle" required: false default: true + pycodestyle-version: + description: "The version of pycodestyle to use" + required: false + default: "" use-autopep8: description: "Use autopep8" required: false default: false + autopep8-version: + description: "The version of autope8 to use" + required: false + default: "" use-pydocstyle: description: "Use pydocstyle" required: false default: true + pydocstyle-version: + description: "The version of pydocstyle to use" + required: false + default: "" use-mypy: description: "Use mypy" required: false default: true + mypy-version: + description: "The version of mypy to use" + required: false + default: "" use-pylint: description: "Use Pylint" required: false default: true + pylint-version: + description: "The version of pylint to use" + required: false + default: "" use-flake8: description: "Use Flake8" required: false default: true + flake8-version: + description: "The version of flake8 to use" + required: false + default: "" use-mccabe: description: "Use mccabe" required: false default: false + mccabe-version: + description: "The version of mccabe to use" + required: false + default: "" use-radon: description: "Use radon" required: false default: false + radon-version: + description: "The version of radon to use" + required: false + default: "" use-rstcheck: description: "Use rstcheck" required: false default: true + rstcheck-version: + description: "The version of rstcheck to use" + required: false + default: "" use-check-manifest: description: "Use check-manifest" required: false default: true + check-manifest-version: + description: "The version of check-manifest to use" + required: false + default: "" use-pyroma: description: "Use pyroma" required: false default: true + pyroma-version: + description: "The version of pyroma to use" + required: false + default: "" extra-black-options: description: "Extra options: black --check $(extra-black-options) $(python-root-list)" required: false @@ -131,21 +195,37 @@ runs: image: "Dockerfile" args: - ${{ inputs.python-root-list }} + - ${{ inputs.virtual-env }} - ${{ inputs.use-black }} + - ${{ inputs.black-version }} - ${{ inputs.use-yapf }} + - ${{ inputs.yapf-version }} - ${{ inputs.use-isort }} + - ${{ inputs.isort-version }} - ${{ inputs.use-docformatter }} + - ${{ inputs.docformatter-version }} - ${{ inputs.use-pycodestyle }} + - ${{ inputs.pycodestyle-version }} - ${{ inputs.use-autopep8 }} + - ${{ inputs.autopep8-version }} - ${{ inputs.use-pydocstyle }} + - ${{ inputs.pydocstyle-version }} - ${{ inputs.use-mypy }} + - ${{ inputs.mypy-version }} - ${{ inputs.use-pylint }} + - ${{ inputs.pylint-version }} - ${{ inputs.use-flake8 }} + - ${{ inputs.flake8-version }} - ${{ inputs.use-mccabe }} + - ${{ inputs.mccabe-version }} - ${{ inputs.use-radon }} + - ${{ inputs.radon-version }} - ${{ inputs.use-rstcheck }} + - ${{ inputs.rstcheck-version }} - ${{ inputs.use-check-manifest }} + - ${{ inputs.check-manifest-version }} - ${{ inputs.use-pyroma }} + - ${{ inputs.pyroma-version }} - ${{ inputs.extra-black-options }} - ${{ inputs.extra-yapf-options }} - ${{ inputs.extra-isort-options }} diff --git a/entrypoint.sh b/entrypoint.sh index 9d6ee63..f1ca6fc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,43 +3,68 @@ # Parameters # # $1 - python-root-list -# $2 - use-black -# $3 - use-yapf -# $4 - use-isort -# $5 - use-docformatter -# $6 - use-pycodestyle -# #7 - use-autopep8 -# $8 - use-pydocstyle -# $9 - use-mypy -# $10 - use-pylint -# ${11} - use-flake8 -# ${12} - use mccabe -# ${13} - use radon -# ${14} - use-rstcheck -# ${15} - use-check-manifest -# ${16} - use-pyroma -# ${17} - extra-black-options -# ${18} - extra-yapf-options -# ${19} - extra-isort-options -# ${20} - extra-docformatter-options -# ${21} - extra-pycodestyle-options -# ${22} - extra-autopep8-options -# ${23} - extra-pydocstyle-options -# ${24} - extra-mypy-options -# ${25} - extra-pylint-options -# ${26} - extra-flake8-options -# ${27} - extra-mccabe-options -# ${28} - extra-radon-options -# ${29} - extra-rstcheck-options -# ${30} - extra-manifest-options -# ${31} - extra-pyroma-options +# $2 - virtual-env +# $3 - use-black +# $4 - black-version +# $5 - use-yapf +# $6 - yapf-version +# $7 - use-isort +# $8 - isort-version +# $9 - use-docformatter +# $10 - docformatter-version +# ${11} - use-pycodestyle +# ${12} - pycodestyle-version +# ${13} - use-autopep8 +# ${14} - autopep8-version +# ${15} - use-pydocstyle +# ${16} - pydocstyle-version +# ${17} - use-mypy +# ${18} - mypy-version +# ${19} - use-pylint +# ${20} - pylint-version +# ${21} - use-flake8 +# ${22} - flake8-version +# ${23} - use mccabe +# ${24} - mccabe-version +# ${25} - use radon +# ${26} - radon-version +# ${27} - use-rstcheck +# ${28} - rstcheck-version +# ${29} - use-check-manifest +# ${30} - check-manifest-version +# ${31} - use-pyroma +# ${32} - pyroma-version +# ${33} - extra-black-options +# ${34} - extra-yapf-options +# ${35} - extra-isort-options +# ${36} - extra-docformatter-options +# ${37} - extra-pycodestyle-options +# ${38} - extra-autopep8-options +# ${39} - extra-pydocstyle-options +# ${40} - extra-mypy-options +# ${41} - extra-pylint-options +# ${42} - extra-flake8-options +# ${43} - extra-mccabe-options +# ${44} - extra-radon-options +# ${45} - extra-rstcheck-options +# ${46} - extra-manifest-options +# ${47} - extra-pyroma-options + +# Create a virtual environment to run tools. +echo "Creating virtual environment: $2" +python3 -m venv $2 +echo "Activating virtual environment: $2" +source $2/bin/activate +pip install -U pip # Run the autoformatters first. -if [ "$2" = true ] ; then +if [ "$3" = true ] ; then - echo Running: black --check ${17} $1 + echo Running: black --check ${33} $1 - black --check ${17} $1 + pip install black$4 + + black --check ${33} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -51,11 +76,13 @@ if [ "$2" = true ] ; then fi -if [ "$3" = true ]; then +if [ "$5" = true ]; then + + echo Running: yapf ${34} $1 - echo Running: yapf ${18} $1 + pip install yapf$6 - yapf ${18} $1 + yapf ${34} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -67,27 +94,31 @@ if [ "$3" = true ]; then fi -if [ "$4" = true ] ; then +if [ "$7" = true ] ; then + + echo Running: isort ${35} $1 -c --diff - echo Running: isort ${19} $1 -c --diff + pip install isort$8 - isort ${19} $1 -c --diff + isort ${35} $1 -c --diff exit_code=$? if [ "$exit_code" = "0" ]; then echo "isort ok" else - echo "isort error" + echo "isort error $exit_code" exit $exit_code fi fi -if [ "$5" = true ] ; then +if [ "$9" = true ] ; then + + echo Running: docformatter -c --recursive ${36} $1 - echo Running: docformatter -c --recursive ${20} $1 + pip install docformatter${10} - docformatter -c --recursive ${20} $1 + docformatter -c --recursive ${36} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -101,11 +132,13 @@ if [ "$5" = true ] ; then fi # Then check the autoformatter results. -if [ "$6" = true ] ; then +if [ "${11}" = true ] ; then + + echo Running: pycodestyle ${37} $1 - echo Running: pycodestyle ${21} $1 + pip install pycodestyle${12} - pycodestyle ${21} $1 + pycodestyle ${37} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -117,11 +150,13 @@ if [ "$6" = true ] ; then fi -if [ "$7" = true ] ; then +if [ "${13}" = true ] ; then - echo Running: autopep8 ${22} $1 + echo Running: autopep8 ${38} $1 - autopep8 ${22} $1 + pip install autopep8${14} + + autopep8 ${38} $1 exit_code=$? if [ "$exit_code" = 0 ]; then @@ -133,11 +168,13 @@ if [ "$7" = true ] ; then fi -if [ "$8" = true ] ; then +if [ "${15}" = true ] ; then + + echo Running: pydocstyle ${39} $1 - echo Running: pydocstyle ${23} $1 + pip install pydocstyle${16} - pydocstyle ${23} $1 + pydocstyle ${39} $1 exit_code=$? if [ "$exit_code" = 0 ]; then @@ -149,11 +186,13 @@ if [ "$8" = true ] ; then fi # Next type check everything. -if [ "$9" = true ] ; then +if [ "${17}" = true ] ; then + + echo Running: mypy ${40} $1 - echo Running: mypy ${24} $1 + pip install mypy${18} - mypy ${24} $1 + mypy ${40} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -166,11 +205,13 @@ if [ "$9" = true ] ; then fi # Finally, lint the code. -if [ "${10}" = true ] ; then +if [ "${19}" = true ] ; then + + echo Running: pylint ${41} $1 - echo Running: pylint ${25} $1 + pip install pylint${20} - pylint ${25} $1 + pylint ${41} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -182,11 +223,13 @@ if [ "${10}" = true ] ; then fi -if [ "${11}" = true ] ; then +if [ "${21}" = true ] ; then + + echo Running: flake8 ${42} $1 - echo Running: flake8 ${26} $1 + pip install flake8${22} - flake8 ${26} $1 + flake8 ${42} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -199,11 +242,13 @@ if [ "${11}" = true ] ; then fi # Check code maintainability -if [ "${12}" = true ]; then +if [ "${23}" = true ]; then - echo Running: mccabe ${27} $1 + echo Running: mccabe ${43} $1 - python -m mccabe ${27} $1 + pip install mccabe${24} + + python -m mccabe ${43} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -214,11 +259,13 @@ if [ "${12}" = true ]; then fi fi -if [ "${13}" = true ]; then +if [ "${25}" = true ]; then + + echo Running: radon ${44} $1 - echo Running: radon ${28} $1 + pip install radon${26} - radon ${28} $1 + radon ${44} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -230,11 +277,13 @@ if [ "${13}" = true ]; then fi # Check rst files -if [ "${14}" = true ]; then +if [ "${27}" = true ]; then + + echo Running: rstcheck ${45} $1 - echo Running: rstcheck ${29} $1 + pip install rstcheck${28} - rstcheck ${29} $1 + rstcheck ${45} $1 exit_code=$? if [ "$exit_code" = "0" ]; then @@ -246,11 +295,13 @@ if [ "${14}" = true ]; then fi # Check packaging -if [ "${15}" = true ]; then +if [ "${29}" = true ]; then - echo Running: check-manifest ${30} . + echo Running: check-manifest ${46} . - check-manifest ${30} . + pip install check-manifest${30} + + check-manifest ${46} . exit_code=$? if [ "$exit_code" = "0" ]; then @@ -261,11 +312,13 @@ if [ "${15}" = true ]; then fi fi -if [ "${16}" = true ]; then +if [ "${31}" = true ]; then + + echo Running: pyroma ${47} . - echo Running: pyroma ${31} . + pip install pyroma${32} - pyroma ${31} . + pyroma ${47} . exit_code=$? if [ "$exit_code" = "0" ]; then