Skip to main content

Extensible code style checker currently supporting Fortran, PSyclone DSL, etc

Project description

BSD3 License GitHub release PyPI 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 by running python setup.py. 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(FortranCharactersest(),
               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.3.1.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

stylist-0.3.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stylist-0.3.1.tar.gz
Algorithm Hash digest
SHA256 14d1a63806336499ff087e9b8263f29d60a077ab9f4b9cd14c211286e581152c
MD5 986d7e5d81d9346b0666b7e7d09d8553
BLAKE2b-256 f841f07cb5b51f4d904810304133985ee4b6e067bd8b9dda9620388dbc6e40cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stylist-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d54fd8de6e2418a60d73d824cf137997fd4677964d5dc74518c9a6026e80f65
MD5 b91e883be65d61436d5e3dc5083f2af1
BLAKE2b-256 e2f3e4a3a489b2f1ff1708e80d39c0546cefcb256365cdf6750eaeb853ce6dde

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