Skip to content

Commit

Permalink
Merge branch 'pseewald:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kohei-noda-qcrg authored Mar 31, 2023
2 parents 77053c1 + c177742 commit ac7a7b7
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 129 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ jobs:
python-version: "3.x"

- name: Build package
run: pipx run build
run: |
python -m pip install --upgrade pip
pip install build
python -m build
- name: Publish to Test PyPi
if: ${{ startsWith(github.ref, 'refs/tags') }}
Expand Down
66 changes: 8 additions & 58 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Create resource cache
id: cache
Expand All @@ -31,52 +31,6 @@ jobs:
run: |
.travis/prep_cron.sh
conda:
needs:
- resources
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ["3.7", "3.8", "3.9", "3.10"]

defaults:
run:
shell: "bash -l {0}"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Load resources
uses: actions/cache@v3
with:
path: ./fortran_tests/before/*/
key: resources-${{ github.event_name }}

- name: Install dependencies
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yml
extra-specs: |
python=${{ matrix.python }}
coveralls
- name: Install project
run: pip install .

- name: Run tests
run: |
coverage run --source=fprettify setup.py test
- name: Coverage upload
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ matrix.python }}
COVERALLS_PARALLEL: true

pip:
needs:
- resources
Expand All @@ -85,27 +39,24 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ["3.5", "3.6"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Load resources
uses: actions/cache@v3
with:
path: ./fortran_tests/before/*/
key: resources-${{ github.event_name }}

- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: pip install -r requirements.txt coveralls

- name: Install project
run: pip install .
- name: Install project & dependencies
run: pip install .[dev]

- name: Run tests
run: |
Expand All @@ -121,13 +72,12 @@ jobs:
coverage:
needs:
- pip
- conda
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: "3.x"

- name: Install dependencies
run: pip install coveralls
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ ENV/

# ctags
tags

# setuptools_scm autogeneated version
_version.py

# fortran temporary test files
fortran_tests/
77 changes: 45 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# fprettify

[![Build Status](https://travis-ci.com/pseewald/fprettify.svg?branch=master)](https://travis-ci.com/pseewald/fprettify) [![Coverage Status](https://coveralls.io/repos/github/pseewald/fprettify/badge.svg?branch=master)](https://coveralls.io/github/pseewald/fprettify?branch=master) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) [![PyPI version](https://badge.fury.io/py/fprettify.svg)](https://badge.fury.io/py/fprettify)
[![CI](https://github.com/pseewald/fprettify/actions/workflows/test.yml/badge.svg)](https://github.com/pseewald/fprettify/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/pseewald/fprettify/badge.svg?branch=master)](https://coveralls.io/github/pseewald/fprettify?branch=master)
![PyPI - License](https://img.shields.io/pypi/l/fprettify)
![PyPI](https://img.shields.io/pypi/v/fprettify)
[![Code Climate](https://codeclimate.com/github/pseewald/fprettify/badges/gpa.svg)](https://codeclimate.com/github/pseewald/fprettify)

fprettify is an auto-formatter for modern Fortran code that imposes strict whitespace formatting, written in Python.

**NOTE:** I'm looking for help to maintain this repository, see [#127](https://github.com/pseewald/fprettify/issues/127).


## Features

* Auto-indentation.
* Line continuations are aligned with the previous opening delimiter `(`, `[` or `(/` or with an assignment operator `=` or `=>`. If none of the above is present, a default hanging indent is applied.
* Consistent amount of whitespace around operators and delimiters.
* Removal of extraneous whitespace and consecutive blank lines.
* Change letter case (upper case / lower case conventions) of intrinsics
* Tested for editor integration.
* By default, fprettify causes whitespace changes only and thus preserves revision history.
* fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.

- Auto-indentation.
- Line continuations are aligned with the previous opening delimiter `(`, `[` or `(/` or with an assignment operator `=` or `=>`. If none of the above is present, a default hanging indent is applied.
- Consistent amount of whitespace around operators and delimiters.
- Removal of extraneous whitespace and consecutive blank lines.
- Change letter case (upper case / lower case conventions) of intrinsics
- Tested for editor integration.
- By default, fprettify causes whitespace changes only and thus preserves revision history.
- fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.

## Limitations

* Works only for modern Fortran (Fortran 90 upwards).
* Feature missing? Please create an issue.

- Works only for modern Fortran (Fortran 90 upwards).
- Feature missing? Please create an issue.

## Requirements

* Python 3 (Python 2.7 no longer supported)
* [ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file

- Python 3 (Python 2.7 no longer supported)
- [ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file

## Examples

Compare `examples/*before.f90` (original Fortran files) with `examples/*after.f90` (reformatted Fortran files) to see what fprettify does. A quick demonstration:

``` Fortran
```Fortran
program demo
integer :: endif,if,elseif
integer,DIMENSION(2) :: function
Expand All @@ -50,8 +50,10 @@ print*,endif
endif
end program
```

⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
``` Fortran

```Fortran
program demo
integer :: endif, if, elseif
integer, DIMENSION(2) :: function
Expand All @@ -67,65 +69,80 @@ program demo
end program
```


## Installation

The latest release can be installed using pip:
```

```sh
pip install --upgrade fprettify
```

Installation from source requires Python Setuptools:
```
./setup.py install

```sh
pip install .
```

For local installation, use `--user` option.

If you use the [Conda](https://docs.conda.io/) package manager, fprettify is available from the [conda-forge](https://conda-forge.org/) channel:

```sh
conda install -c conda-forge fprettify
```

## Command line tool

Autoformat file1, file2, ... inplace by
```

```sh
fprettify file1, file2, ...
```

The default indent is 3. If you prefer something else, use `--indent n` argument.

In order to apply fprettify recursively to an entire Fortran project instead of a single file, use the `-r` option.

For more options, read
```

```sh
fprettify -h
```


## Editor integration

For editor integration, use
```

```sh
fprettify --silent
```

For instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:

```vim
autocmd Filetype fortran setlocal formatprg=fprettify\ --silent
```


## Deactivation and manual formatting (experimental feature)

fprettify can be deactivated for selected lines: a single line followed by an inline comment starting with `!&` is not auto-formatted and consecutive lines that are enclosed between two comment lines `!&<` and `!&>` are not auto-formatted. This is useful for cases where manual alignment is preferred over auto-formatting. Furthermore, deactivation is necessary when non-standard Fortran syntax (such as advanced usage of preprocessor directives) prevents proper formatting. As an example, consider the following snippet of fprettify formatted code:

```fortran
A = [-1, 10, 0, &
0, 1000, 0, &
0, -1, 1]
```

In order to manually align the columns, fprettify needs to be deactivated by

```fortran
A = [-1, 10, 0, & !&
0, 1000, 0, & !&
0, -1, 1] !&
```

or, equivalently by

```fortran
!&<
A = [-1, 10, 0, &
Expand All @@ -134,10 +151,6 @@ A = [-1, 10, 0, &
!&>
```


## Contributing / Testing

The testing mechanism allows you to easily test fprettify with any Fortran project of your choice. Simply clone or copy your entire project into `fortran_tests/before` and run `python setup.py test`. The directory `fortran_tests/after` contains the test output (reformatted Fortran files). If testing fails, please submit an issue!


[![Code Climate](https://codeclimate.com/github/pseewald/fprettify/badges/gpa.svg)](https://codeclimate.com/github/pseewald/fprettify)
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ channels:
- conda-forge
dependencies:
- configargparse
- importlib-metadata
10 changes: 10 additions & 0 deletions fprettify/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
from importlib.metadata import PackageNotFoundError, version
except ModuleNotFoundError:
from importlib_metadata import PackageNotFoundError, version
try:
__version__ = version(__package__)
except PackageNotFoundError:
from setuptools_scm import get_version

__version__ = get_version(root="..", relative_to=__file__)
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build-system]
requires = [
"setuptools >= 45",
"wheel",
"setuptools_scm[toml] >= 6.2",
"setuptools_scm_git_archive",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "fprettify/_version.py"

[tool.isort]
profile = "black"
49 changes: 49 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[metadata]
name = fprettify
url = https://github.com/pseewald/fprettify
author = Patrick Seewald
author_email = [email protected]
description = auto-formatter for modern fortran source code
long_description = file: README.md
long_description_content_type = text/markdown
license = GPLv3
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Topic :: Software Development :: Quality Assurance
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Environment :: Console
Operating System :: OS Independent
keywords =
fortran
formatter
project_urls =
Tracker = https://github.com/pseewald/fprettify/issues
Source Code = https://github.com/pseewald/fprettify

[options]
packages = find:
python_requires = >= 3.6
install_requires =
configargparse
importlib-metadata; python_version < "3.8"

[options.entry_points]
console_scripts =
fprettify = fprettify.__init__:run

[options.extras_require]
dev =
black
isort
pre-commit
coveralls

[flake8]
max-line-length = 88
extend-ignore = E203, E722
Loading

0 comments on commit ac7a7b7

Please sign in to comment.