{"id":18840152,"url":"https://github.com/fortran-lang/fprettify","last_synced_at":"2025-12-11T22:46:19.095Z","repository":{"id":37849556,"uuid":"66675377","full_name":"fortran-lang/fprettify","owner":"fortran-lang","description":"auto-formatter for modern fortran source code","archived":false,"fork":false,"pushed_at":"2025-08-11T20:50:32.000Z","size":1133,"stargazers_count":409,"open_issues_count":77,"forks_count":81,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-08-25T05:55:34.887Z","etag":null,"topics":["auto-formatter","coding-style","developer-tools","fortran"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/fprettify","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortran-lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-26T19:52:37.000Z","updated_at":"2025-08-23T19:02:15.000Z","dependencies_parsed_at":"2022-07-12T17:02:32.840Z","dependency_job_id":"f0568d37-37d5-4749-9fa4-1f59af1ca83b","html_url":"https://github.com/fortran-lang/fprettify","commit_stats":{"total_commits":381,"total_committers":16,"mean_commits":23.8125,"dds":"0.22834645669291342","last_synced_commit":"ee0cf1b1890fee615942df00075cf2134c709542"},"previous_names":["fortran-lang/fprettify","pseewald/fprettify"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/fortran-lang/fprettify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortran-lang%2Ffprettify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortran-lang%2Ffprettify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortran-lang%2Ffprettify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortran-lang%2Ffprettify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortran-lang","download_url":"https://codeload.github.com/fortran-lang/fprettify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortran-lang%2Ffprettify/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27672008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-formatter","coding-style","developer-tools","fortran"],"created_at":"2024-11-08T02:45:13.072Z","updated_at":"2025-12-11T22:46:19.089Z","avatar_url":"https://github.com/fortran-lang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fprettify\n\n[![CI](https://github.com/pseewald/fprettify/actions/workflows/test.yml/badge.svg)](https://github.com/pseewald/fprettify/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/pseewald/fprettify/badge.svg?branch=master)](https://coveralls.io/github/pseewald/fprettify?branch=master)\n![PyPI - License](https://img.shields.io/pypi/l/fprettify)\n![PyPI](https://img.shields.io/pypi/v/fprettify)\n[![Code Climate](https://codeclimate.com/github/pseewald/fprettify/badges/gpa.svg)](https://codeclimate.com/github/pseewald/fprettify)\n\nfprettify is an auto-formatter for modern Fortran code that imposes strict whitespace formatting, written in Python.\n\n**NOTE:** I'm looking for help to maintain this repository, see [#127](https://github.com/pseewald/fprettify/issues/127).\n\n## Features\n\n- Auto-indentation.\n- Line continuations are aligned with the previous opening delimiter `(`, `[` or `(/` or with an assignment operator `=` or `=\u003e`. If none of the above is present, a default hanging indent is applied.\n- Consistent amount of whitespace around operators and delimiters.\n- Removal of extraneous whitespace and consecutive blank lines.\n- Change letter case (upper case / lower case conventions) of intrinsics\n- Tested for editor integration.\n- By default, fprettify causes whitespace changes only and thus preserves revision history.\n- fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.\n\n## Limitations\n\n- Works only for modern Fortran (Fortran 90 upwards).\n- Feature missing? Please create an issue.\n\n## Requirements\n\n- Python 3 (Python 2.7 no longer supported)\n- [ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file\n\n## Examples\n\nCompare `examples/*before.f90` (original Fortran files) with `examples/*after.f90` (reformatted Fortran files) to see what fprettify does. A quick demonstration:\n\n```Fortran\nprogram demo\ninteger :: endif,if,elseif\ninteger,DIMENSION(2) :: function\nendif=3;if=2\nif(endif==2)then\nendif=5\nelseif=if+4*(endif+\u0026\n2**10)\nelseif(endif==3)then\nfunction(if)=endif/elseif\nprint*,endif\nendif\nend program\n```\n\n⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩\n\n```Fortran\nprogram demo\n   integer :: endif, if, elseif\n   integer, DIMENSION(2) :: function\n   endif = 3; if = 2\n   if (endif == 2) then\n      endif = 5\n      elseif = if + 4*(endif + \u0026\n                       2**10)\n   elseif (endif == 3) then\n      function(if) = endif/elseif\n      print *, endif\n   endif\nend program\n```\n\n## Installation\n\nThe latest release can be installed using pip:\n\n```sh\npip install --upgrade fprettify\n```\n\nInstallation from source requires Python Setuptools:\n\n```sh\npip install .\n```\n\nFor local installation, use `--user` option.\n\nIf you use the [Conda](https://docs.conda.io/) package manager, fprettify is available from the [conda-forge](https://conda-forge.org/) channel:\n\n```sh\nconda install -c conda-forge fprettify\n```\n\n## Command line tool\n\nAutoformat file1, file2, ... inplace by\n\n```sh\nfprettify file1, file2, ...\n```\n\nThe default indent is 3. If you prefer something else, use `--indent n` argument.\n\nIn order to apply fprettify recursively to an entire Fortran project instead of a single file, use the `-r` option.\n\nFor more options, read\n\n```sh\nfprettify -h\n```\n\n## Editor integration\n\nFor editor integration, use\n\n```sh\nfprettify --silent\n```\n\nFor instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:\n\n```vim\nautocmd Filetype fortran setlocal formatprg=fprettify\\ --silent\n```\n\n## Deactivation and manual formatting (experimental feature)\n\nfprettify can be deactivated for selected lines: a single line followed by an inline comment starting with `!\u0026` is not auto-formatted and consecutive lines that are enclosed between two comment lines `!\u0026\u003c` and `!\u0026\u003e` 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:\n\n```fortran\nA = [-1, 10, 0, \u0026\n     0, 1000, 0, \u0026\n     0, -1, 1]\n```\n\nIn order to manually align the columns, fprettify needs to be deactivated by\n\n```fortran\nA = [-1,   10, 0, \u0026 !\u0026\n      0, 1000, 0, \u0026 !\u0026\n      0,   -1, 1]   !\u0026\n```\n\nor, equivalently by\n\n```fortran\n!\u0026\u003c\nA = [-1,   10, 0, \u0026\n      0, 1000, 0, \u0026\n      0,   -1, 1]\n!\u0026\u003e\n```\n\n## Contributing / Testing\n\nWhen contributing new features by opening a pull request, testing is essential\nto verify that the new features behave as intended, and that there are no\nunwanted side effects. It is expected that before merging a pull request:\n1. one or more unit tests are added which test formatting of small Fortran code\n   snippets, covering all relevant aspects of the added features.\n2. if the changes lead to failures of existing tests, these test failures\n   should be carefully examined. Only if the test failures are due to\n   intended changes of `fprettify` defaults, or because of bug fixes, the\n   expected test results can be updated.\n\n\n### How to add a unit test\n\nCan the new feature be reasonably covered by small code snippets (\u003c 10 lines)?\n- **Yes**: add a test by starting from the following skeleton, and by adding the code to the file `fprettify/tests/unittests.py`:\n\n```python\n    def test_something(self):\n        \"\"\"short description\"\"\"\n\n        in = \"Some Fortran code\"\n        out = \"Same Fortran code after fprettify formatting\"\n\n        # selected fprettify command line arguments, as documented in \"fprettify.py -h\":\n        opt = [\"arg 1\", \"value for arg 1\", \"arg2\", ...] \n\n        # helper function checking that fprettify output is equal to \"out\":\n        self.assert_fprettify_result(opt, in, out)\n```\n\n  Then run `./run_tests.py -s unittests` and check in the output that the newly added unit test passes.\n\n\n- **No**: add a test by adding an example Fortran source file: Add the Fortran file\n  to `examples/in`, and the reformatted `fprettify` output to `examples/out`.\n  If the test requires non-default `fprettify` options, specify these options\n  as an annotation `! fprettify:` followed by the command-line arguments at the\n  beginning of the Fortran file. Then you'll need to manually remove\n  `fortran_tests/test_code/examples` to make sure that the test configuration\n  will be updated with the changes from `examples`.\n\nThen run `./run_tests.py -s builtin`, and check that the output mentions the\nnewly added example with `checksum new ok`. Check that a new line containing\nthe checksum for this example has been added to the file\n`fortran_tests/test_results/expected_results`, and commit this change along\nwith your example. Rerun `./run_tests.py -s builtin` and check that the\noutput mentions the newly added example with `checksum ok`.\n\n\n### How to add integration tests\n\nThis is a mechanism to add external code bases (such as entire git repositories\ncontaining Fortran code) as test cases. In order to add a new code base as an\nintegration test suite, add a new section to\n[testsuites.config](fortran_tests/testsuites.config), adhering to the following\nformat:\n\n``INI\n[...]        # arbitrary unique section name identifying test code\nobtain: ...  # Python command to obtain test code base\npath: ...    # relative path pointing to test code location\nsuite: ...   # which suite this test code should belong to\n`` \n\nFor `suite`, you should pick one of the following test suites:\n- `regular`: for small code bases (executed for every pull request)\n- `cron`: for larger code bases (executed nightly)\n\n\n### How to locally run all unit and integration tests:\n\n- unit tests: `./run_tests.py -s unittests`\n- builtin examples integration tests: `./run_tests.py -s builtin`\n- `regular`: integration test suite: `./run_tests.py -s regular`\n- `cron`: integration test suite (optional, takes a long time to execute): `./run_tests.py -s cron`\n- `custom`: a dedicated test suite for quick testing, shouldn't be committed.\n\n\n### How to locally run selected unit or integration tests:\n\n- unit tests: run\n    `python -m unittest -v fprettify.tests.unittests.FprettifyUnitTestCase.test_xxx`\n    (replacing `test_xxx` with the actual name of the test method)\n- integration tests: run\n    - a specific suite (`unittests`, `builtin`, `regular`, `cron` or `custom`)\n      `./run_tests.py -s ...`\n    - tests belonging to a config section (see [testsuites.config](fortran_tests/testsuites.config)):\n      `./run_tests.py -n ...`\n      \n\n### How to deal with test failures\n\nTest failures are always due to fprettify-formatted code being different than\nexpected. To examine what has changed, proceed as follows:\n- Unit tests: failures should be rather easy to understand because the test\n  output shows the diff of the actual vs. expected result. \n- Integration tests: we don't store the expected version of Fortran code,\n  instead we compare SHA256 checksums of the actual vs. expected result. The\n  test output shows the diff of the actual result vs. the *previous* version of\n  the code (that is, the version before `fprettify` was applied). Thus, in\n  order to obtain the diff of the actual vs. the *expected* result, the\n  following steps need to be executed:\n\n  1. Run `./run_tests.py -s` followed by the name of the failed test suite. Check\n     the test output for lines mentioning test failures such as: \n     `Test top-level-dir/subdir/file.f (fprettify.tests.fortrantests.FprettifyIntegrationTestCase) ... checksum FAIL`.\n  2. Check out the reference version of `fprettify` for which the test passes (normally, `develop` branch).\n  3. Run the integration test(s) via `./run_tests.py -n top-level-dir` (replacing\n     `top-level-dir` with the actual directory mentioned in the test output).\n  4. Check out the version of `fprettify` for which the test failed and run the integration tests again.\n  5. Now the `diff` shown in the test output shows the exact changes which caused the test to fail.\n\nIf you decide to accept the changes as new test references, proceed as follows:\n- Unit tests: update the expected test result within the respective test method (third argument to function `self.assert_fprettify_result`)\n- Integration tests: run `./run_tests.py ... -r` and commit the updated `fortran_tests/test_results/expected_results`. Then\n  run `./run_tests.py ...` and check that tests are passing now.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortran-lang%2Ffprettify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortran-lang%2Ffprettify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortran-lang%2Ffprettify/lists"}