1. Coding Standards

  • Python code style outlined in PEP8

  • Python section of the NCEP Coding Standards

  • NCO WCOSS Implementation Standards for directory structure and script naming conventions

  • Doxygen, Python docstrings, and Sphinx for documentation

  • NOTE: Please do not use f-strings in the run_metplus.py file so that the Python version check can notify the user of the incorrect version. Using Python 3.5 or earlier will output the SyntaxError from the f-string instead of the useful error message.

1.1. Python Code Analysis Tools

1.1.1. Static Tools

1.1.1.1. pylint

pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells.

To install pylint the following can be run:

pip install pylint

or

conda install pylint

To check for errors as well as PEP-8 style code, run:

pylint pep8 <code-to-analyze>

replacing <code-to-analyze> with the name of the file to analyze.

1.1.1.2. pyflakes

pyflakes is a simple program which checks Python source files for errors. Pyflakes analyzes programs and detects various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It’s also much faster.

To install pyflakes the following can be run:

pip install pyflakes

or

conda install pyflakes

flake8 is wrapper to pyflakes, performs PEP-8 style checking in addition to error checking.

1.1.1.3. vulture

vulture finds unused code in Python programs and is useful for cleaning up and finding errors in large code bases. It checks for unused imports, variables, methods, and classes.

To install vulture the following can be run:

pip install vulture

or

conda install vulture

1.1.2. Dynamic (run-time) Tools

1.1.2.1. Code Coverage Analysis

Code coverage analysis tools are useful when running unit tests to determine whether tests are executing all possible branches, loops, etc.

Examples:

Coverage.py: A free tool for monitoring the coverage of your Python apps, monitoring every bit of your code to find what was executed and what was not.

pytest-cov: A free language plug-in to produce a coverage report of your app.

figleaf: A code coverage analysis tool intended to be to be a minimal replacement of ‘coverage.py’ that supports more configurable coverage gathering and reporting.