https://github.com/matthalex/fortran-project-template
An opinionated one-stop shop for new and old Fortran projects, offering seamless compiling, building, packaging, linting, formatting, and more, with modern tools like FPM, pre-commit, fprettify, and ford.
https://github.com/matthalex/fortran-project-template
fortran fortran-package-manager python template
Last synced: 4 months ago
JSON representation
An opinionated one-stop shop for new and old Fortran projects, offering seamless compiling, building, packaging, linting, formatting, and more, with modern tools like FPM, pre-commit, fprettify, and ford.
- Host: GitHub
- URL: https://github.com/matthalex/fortran-project-template
- Owner: MatthAlex
- License: mit
- Created: 2024-06-12T15:10:35.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-18T14:42:50.000Z (9 months ago)
- Last Synced: 2025-04-05T05:51:13.425Z (7 months ago)
- Topics: fortran, fortran-package-manager, python, template
- Language: Fortran
- Homepage: https://github.com/MatthAlex/fortran-project-template
- Size: 36.1 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fortran Project Template
Modern Fortran development made simple - an opinionated, batteries-included project template that brings contemporary development practices to Fortran projects.
- [Why This Template?](#why-this-template)
- [Getting Started](#getting-started)
- [Style Guide and Best Practices](#style-guide-and-best-practices)
- [Development Tools](#development-tools)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)
- [Appendix](#appendix)
## Why This Template?
Fortran remains a crucial language in scientific computing, engineering, and high-performance computing. However, while the language has modernized significantly, the development workflow often lags behind contemporary software engineering practices. This template bridges that gap by providing:
- modern development features like code completion, automated testing, and documentation generation out of the box.
- seamless integration of Fortran codebases with modern DevOps practices, including continuous integration, code quality checks, and automated documentation.
- IDE-like tooling integration with VS Code and extensions.
### Key Benefits
- 🚀 **Instant Modern Setup**: Get a fully configured development environment in minutes, not days
- 🔍 **Code Intelligence**: Real-time error detection, code completion, and refactoring support via VS Code integration
- 📊 **Quality Assurance**: Automated testing, formatting, and linting integrated with git workflow
- 📚 **Automated Documentation**: Generate professional documentation from your code comments
- 🛠️ **Best Practices Built-in**: Pre-configured tools enforce consistent code style and quality
- 🔄 **Modern Workflow**: Brings git-based workflow, dependency management, and automated builds to Fortran
### Traditional vs Modern Fortran Development
| Aspect | Traditional Approach | With This Template |
|--------|---------------------|-------------------|
| Setup Time | Hours/days configuring tools | Minutes with pre-configured environment |
| Error Detection | At compile time | Real-time as you type |
| Code Style | Manual enforcement | Automated formatting and checks |
| Documentation | Manual maintenance | Generated from code comments |
| Testing | Often manual or ad-hoc | Automated with each commit |
| Dependencies | Manual management | Handled by package manager |
## Getting Started
### Prerequisites
- Linux OS or WSL2 via Windows
- GFortran or oneAPI Fortran compiler
#### Optional
- VS Code installation
- Modern Fortran extension installation
### Step-by-step instructions
0. Load compiler modules (if on a compute cluster):
```sh
module load gcc
# or
module load intel
```
1. Create and activate a Python environment:
```sh
python3 -m venv .venv
source .venv/bin/activate
```
Remember to activate your enviroment before runtime or development tasks.
2. Install the runtime and development packages:
```sh
pip3 install . # Install runtime dependencies from pyproject.toml
pip3 install .[dev] # Install development dependencies
```
3. Run the tests and main program:
```sh
fpm test # by default it uses gcc/gfortran to compile and run
fpm run
```
4. Migrate your project:
See a step-by-step guide on how to [migrate your project](./docs/MIGRATION.md).
## Style Guide and Best Practices
The integrated tooling has been configured to automatically conform the code to a set of prescribed rules.
These rules are roughly outlined in the [STYLE_GUIDE.md](./docs/STYLE_GUIDE.md).
## Development Tools
The template includes preconfigured development tools and settings for Modern Fortran development, with configurations for:
- VS Code integration with Modern Fortran extension
- Language server features with `fortls`
- Code formatting with `fprettify`
- Automated testing with `fpm test`
- Package management with `fpm`
For detailed setup instructions and tool configurations, see [TOOLING.md](./docs/TOOLING.md).
### Profiling
For information on profiling, see [PROFILING.md](./docs/PROFILING.md).
## Documentation
Automated documentation is generated by using the [ford](https://github.com/Fortran-FOSS-Programmers/ford) package. For example config files and usage, see [here](https://forddocs.readthedocs.io/en/latest/index.html).
To generate dcoumentation for this sample project, and then view it on the browser, run:
```sh
ford ford.md
firefox docs/ford/index.html # Alternatively, use your preferred browser
```
## Contributing
Contributions from the community are welcome. To contribute, consider opening an issue or pull request with changes and suggestions.
## License
The project is operating under an [MIT](./LICENSE) license. You are free to use, modify, and distribute the code as needed for your project. Feel free to adapt and customize it to suit your requirements.
## Appendix
### Project Directory Structure
```sh
$ tree -Ia '__pycache__|.git|.pytest_cache|.venv|build|.gen*|ford'
.
├── app # The main program driver(s) resides here
│ └── main.f90
├── docs
│ ├── MIGRATION.md
│ ├── PROFILING.md
│ ├── STYLE_GUIDE.md
│ └── TOOLING.md
├── .editorconfig
├── ford.md # FORD config file
├── .fortls # VSCode Modern Fortran config file
├── fpm.rsp
├── fpm.toml # Fortran Package Manager config file
├── .fprettify.rc # fprettify config file
├── .gitignore # Git ignore list of files and directories
├── LICENSE
├── .pre-commit-config.yaml # pre-commit config file
├── profiling
│ └── template_mpi.json
├── pyproject.toml # config file
├── README.md # you are here!
├── src # All source code files are placed in here, except main driver
│ └── first_steps.f90
├── test # All tests are placed in here
│ └── check.f90
└── .vscode # Holds VSCode configs and runtime/debugging tasks
├── extensions.json # simply populates the "Recommended" Extensions tab
└── settings.json # also referred to as "Workspace Settings (JSON)"
```
### References and Links
This repository takes a lot of inspiration (and actual code) from [easy](https://github.com/urbanjost/easy).
- [`fpm`](https://github.com/fortran-lang/fpm)
- [Modern Fortran extension](https://github.com/fortran-lang/vscode-fortran-support)
- [`fortls`](https://github.com/fortran-lang/fortls)
- [`fprettify`](https://github.com/pseewald/fprettify)
- [`pre-commit`](https://pre-commit.com/)
- [`ford`](https://github.com/Fortran-FOSS-Programmers/ford)
- [`uv`](https://github.com/astral-sh/uv)