From b53eb48bdf977f8ef5837be9f208e3942fd17f67 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Tue, 4 Oct 2022 12:15:58 -0700 Subject: [PATCH] Add pylint as part of CI --- .github/workflows/ci.yml | 3 ++ .gitignore | 1 + .pre-commit-config.yaml | 13 +++++++ .pylintrc | 13 +++++++ README.md | 64 ++++++++++++++++++++++++++++++----- cicd/push-release-tag-ghub.sh | 4 +-- mypy.ini | 35 ------------------- setup.cfg | 43 +++++++++++++++++++++-- 8 files changed, 128 insertions(+), 48 deletions(-) create mode 100644 .pylintrc delete mode 100644 mypy.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55ebb81e..641b2636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,9 @@ jobs: with: python-version: ${{ matrix.python }} + - name: Install Pylint + run: pip install pylint + # https://github.com/pre-commit/action - name: Run pre-commit hooks uses: pre-commit/action@v3.0.0 diff --git a/.gitignore b/.gitignore index e42449db..1ddc54b3 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ venv* .idea env .venv* +pylint-results.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abace822..df86e736 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,16 @@ repos: - id: mypy exclude: (?x)(docs/|tests/) args: [--no-strict-optional, --ignore-missing-imports] + +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "--rcfile=.pylintrc", + "--exit-zero" # Always return a 0 (non-error) status code, even if lint errors are found. This is primarily useful in continuous integration scripts. + ] diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..7ebe9898 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,13 @@ +[MAIN] + +# Specify a score threshold under which the program will exit with error. +fail-under=5.86 + +[REPORTS] +# Tells whether to display a full report or only the messages. +reports=yes + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +output-format=colorized diff --git a/README.md b/README.md index 9e49bd3e..313293f4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ HyperNetX ========= ![Passing?](https://github.com/pnnl/HyperNetX/actions/workflows/ci.yml/badge.svg) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint) The HNX library provides classes and methods for modeling the entities and relationships found in complex networks as hypergraphs, the natural models for multi-dimensional network data. @@ -234,8 +235,8 @@ License Released under the 3-Clause BSD license (see License.rst) -Continuous Integration/Continuous Deployment --------------------------------------------- +Continuous Integration +---------------------- This project runs Continuous Integration (CI) using GitHub Actions. Normally, CI runs on pull requests, pushes to certain branches, and other events. @@ -253,12 +254,8 @@ gh workflow run ci.yml --repo pnnl/HyperNetX --ref make commit-docs ``` + + +# Development + +## Code Quality + +HyperNetX uses a number of tools to maintain code quality: + +* Pylint +* Black + +### Pylint + +[Pylint](https://pylint.pycqa.org/en/latest/index.html) is a static code analyzer for Python-based projects. From the [Pylint docs](https://pylint.pycqa.org/en/latest/index.html#what-is-pylint): + +> Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored. Pylint can infer actual values from your code using its internal code representation (astroid). If your code is import logging as argparse, Pylint will know that argparse.error(...) is in fact a logging call and not an argparse call. + +Before using this tool, ensure that you install Pylint in your environment: + +```commandline +pip install -e .['auto-testing'] +``` + +We have a Pylint configuration file, `.pylintrc`, located at the root of this project. +To run Pylint and view the results of Pylint, run the following command: + +```commandline +pylint hypernetx --rcfile=.pylintrc +``` + +You can also run Pylint on the command line to generate a report on the quality of the codebase and save it to a file named "pylint-results.txt": + +```commandline +pylint hypernetx --output=pylint-results.txt +``` + +For more information on configuration, see https://pylint.pycqa.org/en/latest/user_guide/configuration/index.html + +### Black + +[Black](https://black.readthedocs.io/en/stable/) is a PEP 8 compliant formatter for Python-based project. This tool is highly opinionated about how Python should be formatted and will automagically reformat your code. + +Before using this tool, ensure that you install Pylint in your environment: + +```commandline +pip install -e .['auto-testing'] +``` + +```commandline +black hypernetx +``` diff --git a/cicd/push-release-tag-ghub.sh b/cicd/push-release-tag-ghub.sh index c6309353..afb92933 100644 --- a/cicd/push-release-tag-ghub.sh +++ b/cicd/push-release-tag-ghub.sh @@ -17,7 +17,7 @@ git checkout "${current_tag}" echo "${current_tag}" > tempbranch.txt cat tempbranch.txt -# log the branch, remotes, and last commit for forsensics +# log the branch, remotes, and last commit for forensics git branch -vv git remote -vv git --no-pager show --name-only @@ -30,7 +30,7 @@ git --no-pager show --name-only # to access the HyperNetX Github repo git remote add gh-origin "https://${bamboo.GITHUB_USERNAME}:${bamboo.GHUB_PAT_PASSWORD}@github.com/pnnl/HyperNetX.git" -# log the remotes for forsensics +# log the remotes for forensics git remote -vv # Push the latest tag branch to HyperNetX repo on Github diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 061a6959..00000000 --- a/mypy.ini +++ /dev/null @@ -1,35 +0,0 @@ - -[mypy] -python_version = 3.7 -exclude = (?x)( - tests/ # test directory - ) -pretty = True - -# Per-module options: -[mypy-igraph] -ignore_missing_imports = True - -[mypy-decorator] -ignore_missing_imports = True - -[mypy-celluloid] -ignore_missing_imports = True - -[mypy-matplotlib.*] -ignore_missing_imports = True - -[mypy-networkx.*] -ignore_missing_imports = True - -[mypy-sklearn.*] -ignore_missing_imports = True - -[mypy-scipy.*] -ignore_missing_imports = True - -[mypy-nwhy] -ignore_missing_imports = True - -[mypy-pandas] -ignore_missing_imports = True diff --git a/setup.cfg b/setup.cfg index d718580e..9ea840aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,10 +10,44 @@ allow_dirty = True [bumpversion:file:setup.py] - [mypy-setup.py] ignore_errors = True +[mypy] +python_version = 3.7 +exclude = (?x)( + tests/ # test directory + ) +pretty = True + +# Per-module options: +[mypy-igraph] +ignore_missing_imports = True + +[mypy-decorator] +ignore_missing_imports = True + +[mypy-celluloid] +ignore_missing_imports = True + +[mypy-matplotlib.*] +ignore_missing_imports = True + +[mypy-networkx.*] +ignore_missing_imports = True + +[mypy-sklearn.*] +ignore_missing_imports = True + +[mypy-scipy.*] +ignore_missing_imports = True + +[mypy-nwhy] +ignore_missing_imports = True + +[mypy-pandas] +ignore_missing_imports = True + [metadata] python_requires = '>=3.7' description_file = README.md @@ -51,8 +85,11 @@ install_requires = releases = bump2version>=1.0.1 auto-testing = - tox>=3.25.1 - pre-commit>=2.20.0 + tox>=3.25.1 + pre-commit>=2.20.0 + pylint>=2.15.3 + pylint-exit>=1.2.0 + black>=22.8.0 testing = pytest>=4.0 pytest-cov>=3.0.0