From 7cf8bc228e71600b0f50f203babd7192925bf7e5 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:14:54 -0600 Subject: [PATCH 01/11] Updated styleguide with black. --- docs/source/devguide/styleguide.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/devguide/styleguide.rst b/docs/source/devguide/styleguide.rst index b266f5f0222..3428b692a00 100644 --- a/docs/source/devguide/styleguide.rst +++ b/docs/source/devguide/styleguide.rst @@ -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 @@ -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 From 95804f6ce99b3fb75fdcd1646f25cf17234b6f12 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:12:38 -0600 Subject: [PATCH 02/11] Added black checking CI step. --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5973c3cd48d..abe191159b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,6 +158,18 @@ jobs: run: | cpp-coveralls -i src -i include -e src/external --exclude-pattern "/usr/*" --dump cpp_cov.json coveralls --merge=cpp_cov.json --service=github + 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 finish: needs: main From 55c5966a0ee9141f18346419264fca12a6ca424e Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:12:19 -0600 Subject: [PATCH 03/11] Added black as dependency. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index d0419d550f4..9595847d170 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,7 @@ docs = [ test = ["packaging", "pytest", "pytest-cov", "colorama", "openpyxl"] ci = ["cpp-coveralls", "coveralls"] vtk = ["vtk"] +format = ["black"] [project.urls] Homepage = "https://openmc.org" From 3fe472ae8e0f1f75dd6b1cb56913a8b284f405f7 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:32:32 -0600 Subject: [PATCH 04/11] Revert "Added black checking CI step." This reverts commit 95804f6ce99b3fb75fdcd1646f25cf17234b6f12. THis was the wrong file for this. --- .github/workflows/ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abe191159b8..5973c3cd48d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,18 +158,6 @@ jobs: run: | cpp-coveralls -i src -i include -e src/external --exclude-pattern "/usr/*" --dump cpp_cov.json coveralls --merge=cpp_cov.json --service=github - 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 finish: needs: main From 3a65382a68f01cb6b769fbc28d8226fcde88aa2a Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:33:05 -0600 Subject: [PATCH 05/11] Moved python format check to right workflow file. --- .github/workflows/format-check.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index cef14ca2c8c..2bc793f14b2 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -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 From d3ac6203cc4eda09c205858fa887cbbfc9dbd297 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:33:30 -0600 Subject: [PATCH 06/11] Made optional dependency for developers. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9595847d170..e6501d8e012 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ test = ["packaging", "pytest", "pytest-cov", "colorama", "openpyxl"] ci = ["cpp-coveralls", "coveralls"] vtk = ["vtk"] format = ["black"] +develop = ["openmc[test,format]"] [project.urls] Homepage = "https://openmc.org" From d9435c93cca77523e985656a7ebef96e13e93884 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Fri, 13 Dec 2024 16:58:00 -0600 Subject: [PATCH 07/11] Made CI workflow flow name more generic. --- .github/workflows/format-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index 2bc793f14b2..92b3989449d 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -1,4 +1,4 @@ -name: C++ Format Check +name: Format Check on: # allow workflow to be run manually From d701dcb42ae4f242a73a52cb277af2a223dd8dfc Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 14 Dec 2024 20:50:36 -0600 Subject: [PATCH 08/11] Added black to PR template. --- .github/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 68a6e692a46..1f8fa6f835f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -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) From bf786626176dd87950b040f391e1f02b10d903ae Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 14 Dec 2024 20:53:45 -0600 Subject: [PATCH 09/11] Added black badge. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6539ec3c7c5..43f92d18789 100644 --- a/README.md +++ b/README.md @@ -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, From 573b4f9e9248e06820dd7491f39b4c8b8486b3a6 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 14 Dec 2024 21:02:29 -0600 Subject: [PATCH 10/11] Added black options to pyproject. --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e6501d8e012..c9c5469ce80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,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" From 09c3c49084c486424edcaac8a9778f0af2f16a1f Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 14 Dec 2024 21:04:01 -0600 Subject: [PATCH 11/11] Pinned black to specific version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c9c5469ce80..6ffdbe3aa6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ docs = [ test = ["packaging", "pytest", "pytest-cov", "colorama", "openpyxl"] ci = ["cpp-coveralls", "coveralls"] vtk = ["vtk"] -format = ["black"] +format = ["black~=24.8"] develop = ["openmc[test,format]"] [project.urls]