Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laid out infrastructure for switching to black formatting all code. #3222

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Fixes # (issue)

- [ ] I have performed a self-review of my own code
- [ ] I have run [clang-format](https://docs.openmc.org/en/latest/devguide/styleguide.html#automatic-formatting) (version 15) on any C++ source files (if applicable)
- [ ] I have run [black](https://black.readthedocs.io/en/stable/index.html) on any Python source files (if applicable)
- [ ] I have followed the [style guidelines](https://docs.openmc.org/en/latest/devguide/styleguide.html#python) for Python source files (if applicable)
- [ ] I have made corresponding changes to the documentation (if applicable)
- [ ] I have added tests that prove my fix is effective or that my feature works (if applicable)
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: C++ Format Check
name: Format Check

on:
# allow workflow to be run manually
Expand Down Expand Up @@ -30,3 +30,16 @@ jobs:
- name: Failure Check
if: steps.linter.outputs.checks-failed > 0
run: echo "Some files failed the formatting check! See job summary and file annotations for more info" && exit 1

python-format-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: pip install .[format]
name: install black
- run: black --check openmc/ tests/
name: Check if anything needs to be black formatted
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![dockerhub-publish-develop-dagmc](https://github.com/openmc-dev/openmc/workflows/dockerhub-publish-develop-dagmc/badge.svg)](https://github.com/openmc-dev/openmc/actions?query=workflow%3Adockerhub-publish-develop-dagmc)
[![dockerhub-publish-develop](https://github.com/openmc-dev/openmc/workflows/dockerhub-publish-develop/badge.svg)](https://github.com/openmc-dev/openmc/actions?query=workflow%3Adockerhub-publish-develop)
[![conda-pacakge](https://anaconda.org/conda-forge/openmc/badges/version.svg)](https://anaconda.org/conda-forge/openmc)
[![black-style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

The OpenMC project aims to provide a fully-featured Monte Carlo particle
transport code based on modern methods. It is a constructive solid geometry,
Expand Down
5 changes: 3 additions & 2 deletions docs/source/devguide/styleguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ Doxygen commands, e.g., ``\brief`` instead of ``@brief``.
Python
------

Style for Python code should follow PEP8_.
Style for Python code should follow PEP8_, and be formatted with black_.

Docstrings for functions and methods should follow numpydoc_ style.

Python code should work with Python 3.8+.
Python code should work with Python 3.11+.

Use of third-party Python packages should be limited to numpy_, scipy_,
matplotlib_, pandas_, and h5py_. Use of other third-party packages must be
Expand All @@ -167,3 +167,4 @@ represent a filesystem path should work with both strings and Path_ objects.
.. _pathlib: https://docs.python.org/3/library/pathlib.html
.. _os: https://docs.python.org/3/library/os.html
.. _Path: https://docs.python.org/3/library/pathlib.html#pathlib.Path
.. _black: https://black.readthedocs.io/en/stable/index.html
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ docs = [
test = ["packaging", "pytest", "pytest-cov", "colorama", "openpyxl"]
ci = ["cpp-coveralls", "coveralls"]
vtk = ["vtk"]
format = ["black~=24.8"]
develop = ["openmc[test,format]"]

[project.urls]
Homepage = "https://openmc.org"
Expand All @@ -67,6 +69,10 @@ exclude = ['tests*']
"openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"]
"openmc.lib" = ["libopenmc.dylib", "libopenmc.so"]

[tool.black]
target-version = ["py311", "py312", "py313"]
line-length = 88

[project.scripts]
openmc-ace-to-hdf5 = "scripts.openmc_ace_to_hdf5:main"
openmc-plot-mesh-tally = "scripts.openmc_plot_mesh_tally:main"
Expand Down
Loading