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

Actually Black format everything #3223

Open
wants to merge 12 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
10 changes: 5 additions & 5 deletions openmc/_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ def clean_indentation(element, level=0, spaces_per_level=2, trailing_indent=True
Whether or not to add indentation after closing the element

"""
i = "\n" + level*spaces_per_level*" "
i = "\n" + level * spaces_per_level * " "

# ensure there's always some tail for the element passed in
if not element.tail:
element.tail = ""

if len(element):
if not element.text or not element.text.strip():
element.text = i + spaces_per_level*" "
element.text = i + spaces_per_level * " "
if trailing_indent and (not element.tail or not element.tail.strip()):
element.tail = i
for sub_element in element:
# `trailing_indent` is intentionally not forwarded to the recursive
# call. Any child element of the topmost element should add
# indentation at the end to ensure its parent's indentation is
# correct.
clean_indentation(sub_element, level+1, spaces_per_level)
clean_indentation(sub_element, level + 1, spaces_per_level)
if not sub_element.tail or not sub_element.tail.strip():
sub_element.tail = i
else:
Expand Down Expand Up @@ -82,7 +82,7 @@ def reorder_attributes(root):


def get_elem_tuple(elem, name, dtype=int):
'''Helper function to get a tuple of values from an elem
"""Helper function to get a tuple of values from an elem

Parameters
----------
Expand All @@ -97,7 +97,7 @@ def get_elem_tuple(elem, name, dtype=int):
-------
tuple of dtype
Data read from the tuple
'''
"""
subelem = elem.find(name)
if subelem is not None:
return tuple([dtype(x) for x in subelem.text.split()])
Loading
Loading