From dbdeb99d131901997e6e0905af1d0a2d422a1087 Mon Sep 17 00:00:00 2001 From: John Stilley <1831479+john-science@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:28:08 -0700 Subject: [PATCH] Moving .coveragerc info into pyproject.toml (#1692) --- .coveragerc | 35 ---------------------------- .github/workflows/coverage.yaml | 8 +++---- .github/workflows/unittests.yaml | 6 ++--- armi/cases/case.py | 21 +++++++---------- armi/cases/tests/test_cases.py | 5 +--- doc/release/0.3.rst | 1 + pyproject.toml | 39 ++++++++++++++++++++++++++++++++ 7 files changed, 56 insertions(+), 59 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index fd25fbcd3..000000000 --- a/.coveragerc +++ /dev/null @@ -1,35 +0,0 @@ -# Don't worry about coverage for the grid GUI (for now) -[run] -omit = - armi/cli/gridGui.py - armi/utils/gridEditor.py - armi/utils/tests/test_gridGui.py - venv/ -source = armi -# change default .coverage file to something that doesn't have a dot -# because the Windows file server can't handle dots. -data_file = coverage_results.cov - -[coverage:run] -parallel = true - -[report] -omit = - armi/cli/gridGui.py - armi/utils/gridEditor.py - */tests/* - -exclude_lines = - # Don't complain about missing debug-only code: - def __repr__ - if self\.debug - - # Don't complain if tests don't hit defensive assertion code: - raise AssertionError - raise KeyboardInterrupt - raise NotImplementedError - except ImportError - pass - - # Don't complain if non-runnable code isn't run: - if __name__ == .__main__.: diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index ba737fee3..b3cd8de03 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -30,10 +30,10 @@ jobs: pip install -e .[memprof,mpi,test] - name: Run Coverage run: | - coverage run --rcfile=.coveragerc -m pytest -n 4 --cov=armi --cov-config=.coveragerc --cov-report=lcov --ignore=venv armi - mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=.coveragerc -m pytest --cov=armi --cov-config=.coveragerc --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiFeatures.py || true - mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=.coveragerc -m pytest --cov=armi --cov-config=.coveragerc --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiParameters.py || true - coverage combine --rcfile=.coveragerc --keep -a + coverage run --rcfile=pyproject.toml -m pytest -n 4 --cov=armi --cov-config=pyproject.toml --cov-report=lcov --ignore=venv armi + mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=pyproject.toml -m pytest --cov=armi --cov-config=pyproject.toml --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiFeatures.py || true + mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=pyproject.toml -m pytest --cov=armi --cov-config=pyproject.toml --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiParameters.py || true + coverage combine --rcfile=pyproject.toml --keep -a - name: Publish to coveralls.io uses: coverallsapp/github-action@v1.1.2 with: diff --git a/.github/workflows/unittests.yaml b/.github/workflows/unittests.yaml index 8679712c6..15c0b2364 100644 --- a/.github/workflows/unittests.yaml +++ b/.github/workflows/unittests.yaml @@ -30,6 +30,6 @@ jobs: run: | pip install -e .[memprof,mpi,test] pytest -n 4 armi - mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=.coveragerc -m pytest --cov=armi --cov-config=.coveragerc --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiFeatures.py || true - mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=.coveragerc -m pytest --cov=armi --cov-config=.coveragerc --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiParameters.py || true - coverage combine --rcfile=.coveragerc --keep -a + mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=pyproject.toml -m pytest --cov=armi --cov-config=pyproject.toml --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiFeatures.py || true + mpiexec -n 2 --use-hwthread-cpus coverage run --rcfile=pyproject.toml -m pytest --cov=armi --cov-config=pyproject.toml --cov-report=lcov --cov-append --ignore=venv armi/tests/test_mpiParameters.py || true + coverage combine --rcfile=pyproject.toml --keep -a diff --git a/armi/cases/case.py b/armi/cases/case.py index dec8e69b4..3cafa4bea 100644 --- a/armi/cases/case.py +++ b/armi/cases/case.py @@ -30,10 +30,8 @@ import glob import os import pathlib -import platform import pstats import re -import shutil import sys import textwrap import time @@ -62,8 +60,8 @@ from armi.utils.directoryChangers import DirectoryChanger from armi.utils.directoryChangers import ForcedCreationDirectoryChanger -# change from default .coverage to help with Windows dotfile issues. -# Must correspond with data_file entry in `coveragerc`! +# Change from default .coverage to help with Windows dotfile issues. +# Must correspond with data_file entry in `pyproject.toml`! COVERAGE_RESULTS_FILE = "coverage_results.cov" @@ -444,6 +442,10 @@ def _getCoverageRcFile(userCovFile, makeCopy=False): """Helper to provide the coverage configuration file according to the OS. A user-supplied file will take precedence, and is not checked for a dot-filename. + Notes + ----- + ARMI replaced the ".coveragerc" file has been replaced by "pyproject.toml". + Parameters ---------- userCovFile : str @@ -455,21 +457,14 @@ def _getCoverageRcFile(userCovFile, makeCopy=False): Returns ------- covFile : str - path of coveragerc file + path of pyprojec.toml file """ # User-defined file takes precedence. if userCovFile: return os.path.abspath(userCovFile) covRcDir = os.path.abspath(context.PROJECT_ROOT) - covFile = os.path.join(covRcDir, ".coveragerc") - if platform.system() == "Windows": - covFileWin = os.path.join(covRcDir, "coveragerc") - if makeCopy is True: - # Make a copy of the file without the dot in the name - shutil.copy(covFile, covFileWin) - return covFileWin - return covFile + return os.path.join(covRcDir, "pyproject.toml") def _startProfiling(self): """Helper to the Case.run(): start the Python profiling, diff --git a/armi/cases/tests/test_cases.py b/armi/cases/tests/test_cases.py index 0483868fa..5d00da5fb 100644 --- a/armi/cases/tests/test_cases.py +++ b/armi/cases/tests/test_cases.py @@ -139,10 +139,7 @@ def test_getCoverageRcFile(self): covRcDir = os.path.abspath(context.PROJECT_ROOT) # Don't actually copy the file, just check the file paths match covRcFile = case._getCoverageRcFile(userCovFile="", makeCopy=False) - if platform.system() == "Windows": - self.assertEqual(covRcFile, os.path.join(covRcDir, "coveragerc")) - else: - self.assertEqual(covRcFile, os.path.join(covRcDir, ".coveragerc")) + self.assertEqual(covRcFile, os.path.join(covRcDir, "pyproject.toml")) userFile = "UserCovRc" covRcFile = case._getCoverageRcFile(userCovFile=userFile, makeCopy=False) diff --git a/doc/release/0.3.rst b/doc/release/0.3.rst index bb58d291d..fac431233 100644 --- a/doc/release/0.3.rst +++ b/doc/release/0.3.rst @@ -42,6 +42,7 @@ Bug Fixes Quality Work ------------ #. We now enforce a maximum line length of 120 characters, using ``ruff``. (`PR#1646 `_) +#. Move ``.coveragerc`` file information into ``pyproject.toml``. (`PR#1692 `_) #. TBD Changes that Affect Requirements diff --git a/pyproject.toml b/pyproject.toml index 7d7de0b0f..7adb18024 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -219,6 +219,45 @@ filterwarnings = [ "ignore: the matrix subclass is not the recommended way:PendingDeprecationWarning", ] +[tool.coverage.run] +exclude_also = [ + "armi/cli/gridGui.py", + "armi/utils/gridEditor.py", + "armi/utils/tests/test_gridGui.py", + "venv/", + ] +source = ["armi"] +parallel = true +# Change default .coverage file to something that doesn't have a dot +# because some Windows services can't handle dots. +data_file = "coverage_results.cov" + +[tool.coverage.report] +# Regexes for lines to exclude from consideration +omit = [ + "armi/cli/gridGui.py", + "armi/utils/gridEditor.py", + "*/tests/*", + ] + +exclude_also = [ + # Don't complain about missing debug-only code: + "def __repr__", + "if self\\.debug", + + # Don't complain if tests don't hit defensive assertion code: + "raise AssertionError", + "raise KeyboardInterrupt", + "raise NotImplementedError", + "except ImportError", + "pass", + + # Don't complain if non-runnable code isn't run: + "if __name__ == .__main__.:", + ] + +ignore_errors = true + ####################################################################### # DATA FILES TO BE INCLUDED WITH THE PROJECT #