Skip to content

Commit ac7a7b7

Browse files
Merge branch 'pseewald:master' into master
2 parents 77053c1 + c177742 commit ac7a7b7

File tree

10 files changed

+149
-129
lines changed

10 files changed

+149
-129
lines changed

.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
8+
- package-ecosystem: "pip"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"

.github/workflows/release.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ jobs:
1818
python-version: "3.x"
1919

2020
- name: Build package
21-
run: pipx run build
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install build
24+
python -m build
2225
2326
- name: Publish to Test PyPi
2427
if: ${{ startsWith(github.ref, 'refs/tags') }}

.github/workflows/test.yml

+8-58
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Create resource cache
1818
id: cache
@@ -31,52 +31,6 @@ jobs:
3131
run: |
3232
.travis/prep_cron.sh
3333
34-
conda:
35-
needs:
36-
- resources
37-
runs-on: ${{ matrix.os }}
38-
strategy:
39-
fail-fast: false
40-
matrix:
41-
os: [ubuntu-latest]
42-
python: ["3.7", "3.8", "3.9", "3.10"]
43-
44-
defaults:
45-
run:
46-
shell: "bash -l {0}"
47-
48-
steps:
49-
- name: Checkout code
50-
uses: actions/checkout@v2
51-
52-
- name: Load resources
53-
uses: actions/cache@v3
54-
with:
55-
path: ./fortran_tests/before/*/
56-
key: resources-${{ github.event_name }}
57-
58-
- name: Install dependencies
59-
uses: mamba-org/provision-with-micromamba@main
60-
with:
61-
environment-file: environment.yml
62-
extra-specs: |
63-
python=${{ matrix.python }}
64-
coveralls
65-
66-
- name: Install project
67-
run: pip install .
68-
69-
- name: Run tests
70-
run: |
71-
coverage run --source=fprettify setup.py test
72-
73-
- name: Coverage upload
74-
run: coveralls --service=github
75-
env:
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
COVERALLS_FLAG_NAME: ${{ matrix.python }}
78-
COVERALLS_PARALLEL: true
79-
8034
pip:
8135
needs:
8236
- resources
@@ -85,27 +39,24 @@ jobs:
8539
fail-fast: false
8640
matrix:
8741
os: [ubuntu-latest]
88-
python: ["3.5", "3.6"]
42+
python: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
8943

9044
steps:
9145
- name: Checkout code
92-
uses: actions/checkout@v2
46+
uses: actions/checkout@v3
9347

9448
- name: Load resources
9549
uses: actions/cache@v3
9650
with:
9751
path: ./fortran_tests/before/*/
9852
key: resources-${{ github.event_name }}
9953

100-
- uses: actions/setup-python@v3
54+
- uses: actions/setup-python@v4
10155
with:
10256
python-version: ${{ matrix.python }}
10357

104-
- name: Install dependencies
105-
run: pip install -r requirements.txt coveralls
106-
107-
- name: Install project
108-
run: pip install .
58+
- name: Install project & dependencies
59+
run: pip install .[dev]
10960

11061
- name: Run tests
11162
run: |
@@ -121,13 +72,12 @@ jobs:
12172
coverage:
12273
needs:
12374
- pip
124-
- conda
12575
runs-on: ubuntu-latest
12676

12777
steps:
128-
- uses: actions/setup-python@v3
78+
- uses: actions/setup-python@v4
12979
with:
130-
python-version: '3.x'
80+
python-version: "3.x"
13181

13282
- name: Install dependencies
13383
run: pip install coveralls

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ ENV/
9191

9292
# ctags
9393
tags
94+
95+
# setuptools_scm autogeneated version
96+
_version.py
97+
98+
# fortran temporary test files
99+
fortran_tests/

README.md

+45-32
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
# fprettify
22

3-
[![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)
3+
[![CI](https://github.com/pseewald/fprettify/actions/workflows/test.yml/badge.svg)](https://github.com/pseewald/fprettify/actions/workflows/test.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/pseewald/fprettify/badge.svg?branch=master)](https://coveralls.io/github/pseewald/fprettify?branch=master)
5+
![PyPI - License](https://img.shields.io/pypi/l/fprettify)
6+
![PyPI](https://img.shields.io/pypi/v/fprettify)
7+
[![Code Climate](https://codeclimate.com/github/pseewald/fprettify/badges/gpa.svg)](https://codeclimate.com/github/pseewald/fprettify)
48

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

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

9-
1013
## Features
1114

12-
* Auto-indentation.
13-
* 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.
14-
* Consistent amount of whitespace around operators and delimiters.
15-
* Removal of extraneous whitespace and consecutive blank lines.
16-
* Change letter case (upper case / lower case conventions) of intrinsics
17-
* Tested for editor integration.
18-
* By default, fprettify causes whitespace changes only and thus preserves revision history.
19-
* fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.
20-
15+
- Auto-indentation.
16+
- 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.
17+
- Consistent amount of whitespace around operators and delimiters.
18+
- Removal of extraneous whitespace and consecutive blank lines.
19+
- Change letter case (upper case / lower case conventions) of intrinsics
20+
- Tested for editor integration.
21+
- By default, fprettify causes whitespace changes only and thus preserves revision history.
22+
- fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.
2123

2224
## Limitations
2325

24-
* Works only for modern Fortran (Fortran 90 upwards).
25-
* Feature missing? Please create an issue.
26-
26+
- Works only for modern Fortran (Fortran 90 upwards).
27+
- Feature missing? Please create an issue.
2728

2829
## Requirements
2930

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

3434
## Examples
3535

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

38-
``` Fortran
38+
```Fortran
3939
program demo
4040
integer :: endif,if,elseif
4141
integer,DIMENSION(2) :: function
@@ -50,8 +50,10 @@ print*,endif
5050
endif
5151
end program
5252
```
53+
5354
⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
54-
``` Fortran
55+
56+
```Fortran
5557
program demo
5658
integer :: endif, if, elseif
5759
integer, DIMENSION(2) :: function
@@ -67,65 +69,80 @@ program demo
6769
end program
6870
```
6971

70-
7172
## Installation
7273

7374
The latest release can be installed using pip:
74-
```
75+
76+
```sh
7577
pip install --upgrade fprettify
7678
```
7779

7880
Installation from source requires Python Setuptools:
79-
```
80-
./setup.py install
81+
82+
```sh
83+
pip install .
8184
```
8285

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

88+
If you use the [Conda](https://docs.conda.io/) package manager, fprettify is available from the [conda-forge](https://conda-forge.org/) channel:
89+
90+
```sh
91+
conda install -c conda-forge fprettify
92+
```
8593

8694
## Command line tool
8795

8896
Autoformat file1, file2, ... inplace by
89-
```
97+
98+
```sh
9099
fprettify file1, file2, ...
91100
```
101+
92102
The default indent is 3. If you prefer something else, use `--indent n` argument.
93103

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

96106
For more options, read
97-
```
107+
108+
```sh
98109
fprettify -h
99110
```
100111

101-
102112
## Editor integration
103113

104114
For editor integration, use
105-
```
115+
116+
```sh
106117
fprettify --silent
107118
```
119+
108120
For instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:
121+
109122
```vim
110123
autocmd Filetype fortran setlocal formatprg=fprettify\ --silent
111124
```
112125

113-
114126
## Deactivation and manual formatting (experimental feature)
115127

116128
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:
129+
117130
```fortran
118131
A = [-1, 10, 0, &
119132
0, 1000, 0, &
120133
0, -1, 1]
121134
```
135+
122136
In order to manually align the columns, fprettify needs to be deactivated by
137+
123138
```fortran
124139
A = [-1, 10, 0, & !&
125140
0, 1000, 0, & !&
126141
0, -1, 1] !&
127142
```
143+
128144
or, equivalently by
145+
129146
```fortran
130147
!&<
131148
A = [-1, 10, 0, &
@@ -134,10 +151,6 @@ A = [-1, 10, 0, &
134151
!&>
135152
```
136153

137-
138154
## Contributing / Testing
139155

140156
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!
141-
142-
143-
[![Code Climate](https://codeclimate.com/github/pseewald/fprettify/badges/gpa.svg)](https://codeclimate.com/github/pseewald/fprettify)

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ channels:
33
- conda-forge
44
dependencies:
55
- configargparse
6+
- importlib-metadata

fprettify/version.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
from importlib.metadata import PackageNotFoundError, version
3+
except ModuleNotFoundError:
4+
from importlib_metadata import PackageNotFoundError, version
5+
try:
6+
__version__ = version(__package__)
7+
except PackageNotFoundError:
8+
from setuptools_scm import get_version
9+
10+
__version__ = get_version(root="..", relative_to=__file__)

pyproject.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[build-system]
2+
requires = [
3+
"setuptools >= 45",
4+
"wheel",
5+
"setuptools_scm[toml] >= 6.2",
6+
"setuptools_scm_git_archive",
7+
]
8+
build-backend = "setuptools.build_meta"
9+
10+
[tool.setuptools_scm]
11+
write_to = "fprettify/_version.py"
12+
13+
[tool.isort]
14+
profile = "black"

setup.cfg

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[metadata]
2+
name = fprettify
3+
url = https://github.com/pseewald/fprettify
4+
author = Patrick Seewald
5+
author_email = patrick.seewald@gmail.com
6+
description = auto-formatter for modern fortran source code
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
license = GPLv3
10+
classifiers =
11+
Development Status :: 5 - Production/Stable
12+
Intended Audience :: Developers
13+
Topic :: Software Development :: Quality Assurance
14+
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
15+
Programming Language :: Python :: 3
16+
Programming Language :: Python :: 3.6
17+
Programming Language :: Python :: 3.7
18+
Programming Language :: Python :: 3.8
19+
Programming Language :: Python :: 3.9
20+
Environment :: Console
21+
Operating System :: OS Independent
22+
keywords =
23+
fortran
24+
formatter
25+
project_urls =
26+
Tracker = https://github.com/pseewald/fprettify/issues
27+
Source Code = https://github.com/pseewald/fprettify
28+
29+
[options]
30+
packages = find:
31+
python_requires = >= 3.6
32+
install_requires =
33+
configargparse
34+
importlib-metadata; python_version < "3.8"
35+
36+
[options.entry_points]
37+
console_scripts =
38+
fprettify = fprettify.__init__:run
39+
40+
[options.extras_require]
41+
dev =
42+
black
43+
isort
44+
pre-commit
45+
coveralls
46+
47+
[flake8]
48+
max-line-length = 88
49+
extend-ignore = E203, E722

0 commit comments

Comments
 (0)