Skip to main content

Flexible source code style checking tool

Project description

BSD3 License GitHub release PyPI version Conda version GitHub merge testing

Stylist is a tool for checking code style. It implements a framework which supports multiple styles across multiple languages.

But aren’t there many such tools out there, why create a new one?

The simple reason is that few of them support Fortran, a language still in widespread use in the scientific computing domain. They can also tend towards the zealous when enforcing the “one true style” whereas long running science models tend to diverge quite radically in what they like, style-wise.

Large models also tend to be implemented using more than one language so a tool which is capable of understanding all of them would be welcomed by science developers.

This is the goal of Stylist development.

The project is still in its infancy so only a few rules have been implemented and only for Fortran. Stubs are provided to show how it might be extended to support C.

Find the project at <https://github.com/MetOffice/stylist>

Installation

Installation can be as simple as pip install stylist or conda install -c conda-forge stylist.

As always it is also possible to install from the project source using pip install --editable .. The source may be obtained by downloading a tarball or by cloning the repository.

Usage

Stylist provides a command-line tool stylist for normal use. It can also be used as a package if you want to integrate it with another tool. Documentation regarding this second option is maintained in the project wiki.

On the Command Line

The command-line tool is not complicated to use:

stylist [-help] [-verbose]
        [-configuration FILENAME]
        [-style NAME]
        FILE ...

The only required arguments are a configuration file and one or more filenames. These are the files which will be checked. If a directory is specified then the tool will automatically descend into it checking all files which it recognises by extension.

If you want a running commentary of what the tool is doing then use the -verbose argument.

A configuration file may specified with -configuration . This file should be formatted as documented below. There must be a configuration file which defines at least one style. While the fallback mechanism which allows for user and site configurations has not been implemented it must be specified with this argument.

The configuration may define several styles, in which case one can be chosen using the -style argument. If it is not then the first in the configuration file will be used.

Configuration File

The configuration file is a simple python script where variable definitions are used to define the configuration.

Stylist uses the concept of “File Pipes” to specify the series of steps needed to process a particular file type. They are defined by creating a FilePipe object and associated with a file extension by assignment to a variable.

For example:

from stylist.source import (FilePipe,
                            FortranSource,
                            PFUnitProcessor,
                            FortranPreprocessor)

pf = FilePipe(FortranSource, PFUnitProcessor, FortranPreprocessor)

Here a pipeline consisting the pFUnit processor followed by the Fortran preprocessor produces Fortran source. This pipeline should be used for all files with the .pf extension.

Styles are collections of rules and are defined in a similar way. The variable name is the style name and the object is constructed with the rules which make up the style.

An illustrative example:

from re import compile as recompile
from stylist.style import Style
from stylist.fortran import FortranCharacterset, KindPattern

simple = Style(FortranCharacterset(),
               KindPattern(integer=recompile(r'i_.+'),
                           real=recompile(r'r_.+')))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stylist-0.4.0.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

stylist-0.4.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file stylist-0.4.0.tar.gz.

File metadata

  • Download URL: stylist-0.4.0.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.0

File hashes

Hashes for stylist-0.4.0.tar.gz
Algorithm Hash digest
SHA256 dfddf3c7fb4ef29f350307f3f1cfda2516e6d0d5b01d75a3acfb7932effb7e8b
MD5 ee2df6fafa1be92ea71713e80cca3e61
BLAKE2b-256 436279c46c6bee94dac1b54a225199071f071939f5ddd9509669bba6e507e256

See more details on using hashes here.

File details

Details for the file stylist-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: stylist-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.0

File hashes

Hashes for stylist-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba4887885de9c9c49a4632475a79d09b42658c0177ae4a8d60def17dcb88490c
MD5 e2fdda02f8a5cd7da2b5626562ef0d7b
BLAKE2b-256 66dc992064238b31d9a716eca22118276f45bab454373193143b6a942debcf8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page