# 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.
## Limitations
- 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
## Examples
Compare `examples/*before.f90` (original Fortran files) with `examples/*after.f90` (reformatted Fortran files) to see what fprettify does. A quick demonstration:
```Fortran
program demo
integer :: endif,if,elseif
integer,DIMENSION(2) :: function
endif=3;if=2
if(endif==2)then
endif=5
elseif=if+4*(endif+&
2**10)
elseif(endif==3)then
function(if)=endif/elseif
print*,endif
endif
end program
```
⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
```Fortran
program demo
integer :: endif, if, elseif
integer, DIMENSION(2) :: function
endif = 3; if = 2
if (endif == 2) then
endif = 5
elseif = if + 4*(endif + &
2**10)
elseif (endif == 3) then
function(if) = endif/elseif
print *, endif
endif
end program
```
## Installation
The latest release can be installed using pip:
```sh
pip install --upgrade fprettify
```
Installation from source requires Python Setuptools:
```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, &
0, 1000, 0, &
0, -1, 1]
!&>
```
## 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!
没有合适的资源?快使用搜索试试~ 我知道了~
现代Fortran源代码的自动格式化程序_Python_Fortran_下载.zip
共44个文件
f90:14个
yml:7个
py:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 195 浏览量
2023-04-22
16:14:59
上传
评论
收藏 174KB ZIP 举报
温馨提示
现代Fortran源代码的自动格式化程序_Python_Fortran_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
现代Fortran源代码的自动格式化程序_Python_Fortran_下载.zip (44个子文件)
fprettify-master
fprettify
__init__.py 85KB
version.py 343B
tests
__init__.py 37KB
fparse_utils.py 10KB
run_tests.py 2KB
.travis.yml 1KB
setup.py 60B
.github
dependabot.yml 206B
workflows
test.yml 2KB
release.yml 949B
LICENSE 716B
examples
example_after.f90 34B
example_before.f90 35B
.travis
prep_cp2k.sh 249B
prep_rosetta.sh 261B
prep_cron.sh 41B
prep_flap.sh 228B
prep_regular.sh 91B
prep_wannier90.sh 243B
fortran_tests
after
test_invalid.f90 2KB
example_swapcase.f90 8KB
where_forall.f90 680B
example.f90 6KB
test_fypp.f90 9KB
test_namelist_block_select.f90 1005B
example_swapcase.f90-enabled 7KB
test_results
expected_results 248KB
before
test_invalid.f90 2KB
example_swapcase.f90 7KB
where_forall.f90 670B
example.f90 6KB
test_fypp.f90 7KB
test_namelist_block_select.f90 1KB
.pre-commit-hooks.yaml 211B
environment.yml 94B
pyproject.toml 266B
requirements.txt 26B
.codeclimate.yml 331B
fprettify.py 1KB
MANIFEST.in 34B
.gitignore 1KB
setup.cfg 1KB
README.md 5KB
hooks.yml 22B
共 44 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功