From f488d48a8e222f95eecee6abb192f755e78c074b Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 10:24:15 -0600 Subject: [PATCH 01/94] Made dev version. --- montepy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/__init__.py b/montepy/__init__.py index ac195ceb..ace5030b 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -23,7 +23,7 @@ from montepy.universe import Universe import sys -__version__ = "0.2.5" +__version__ = "0.3.0dev1" # enable deprecated warnings for users if not sys.warnoptions: From a917c409fd5312510ec5edeeae21b2310ddcdccb Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 10:45:39 -0600 Subject: [PATCH 02/94] Added MCNP_InputFile to documentation. --- doc/source/api/montepy.input_parser.input_file.rst | 9 +++++++++ doc/source/api/montepy.input_parser.rst | 1 + 2 files changed, 10 insertions(+) create mode 100644 doc/source/api/montepy.input_parser.input_file.rst diff --git a/doc/source/api/montepy.input_parser.input_file.rst b/doc/source/api/montepy.input_parser.input_file.rst new file mode 100644 index 00000000..03cccada --- /dev/null +++ b/doc/source/api/montepy.input_parser.input_file.rst @@ -0,0 +1,9 @@ +montepy.input\_parser.input\_file module +======================================== + + +.. automodule:: montepy.input_parser.input_file + :members: + :undoc-members: + :show-inheritance: + :private-members: _convert_to_int, _convert_to_enum diff --git a/doc/source/api/montepy.input_parser.rst b/doc/source/api/montepy.input_parser.rst index 5ffd32e2..72bcd1b4 100644 --- a/doc/source/api/montepy.input_parser.rst +++ b/doc/source/api/montepy.input_parser.rst @@ -16,6 +16,7 @@ Submodules montepy.input_parser.block_type montepy.input_parser.cell_parser montepy.input_parser.data_parser + montepy.input_parser.input_file montepy.input_parser.input_reader montepy.input_parser.input_syntax_reader montepy.input_parser.mcnp_input From 225fe0e6c242406d3a4fecfbe0a754511b55b268 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 10:45:59 -0600 Subject: [PATCH 03/94] Made pass-through option to set encoding. --- montepy/input_parser/input_file.py | 12 +++++++++++- montepy/input_parser/input_reader.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/montepy/input_parser/input_file.py b/montepy/input_parser/input_file.py index c69bf8af..00c60952 100644 --- a/montepy/input_parser/input_file.py +++ b/montepy/input_parser/input_file.py @@ -57,7 +57,7 @@ def lineno(self): """ pass - def open(self, mode): + def open(self, mode, encoding="ascii"): """ Opens the underlying file, and returns self. @@ -65,8 +65,18 @@ def open(self, mode): For this reason, a ``close`` functional is intentionally not provided. + + .. Note:: + For different encoding schemes see the available list + `here `_. + + CP1252 is commonly referred to as "extended-ASCII". + You may have success with this encoding for working with special characters. + :param mode: the mode to open the file in :type mode: str + :param encoding: The encoding scheme to use. + :type encoding: str :returns: self """ self._fh = open(self.path, mode, encoding="ascii") diff --git a/montepy/input_parser/input_reader.py b/montepy/input_parser/input_reader.py index 3d32245b..12baa629 100644 --- a/montepy/input_parser/input_reader.py +++ b/montepy/input_parser/input_reader.py @@ -3,17 +3,26 @@ from montepy.constants import DEFAULT_VERSION -def read_input(input_file, mcnp_version=DEFAULT_VERSION): +def read_input(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): """ Reads the specified MCNP Input file. The MCNP version must be a three component tuple e.g., (6, 2, 0) and (5, 1, 60). + .. Note:: + For different encoding schemes see the available list + `here `_. + + CP1252 is commonly referred to as "extended-ASCII". + You may have success with this encoding for working with special characters. + :param input_file: the path to the input file to read. :type input_file: str :param mcnp_version: The version of MCNP that the input is intended for. :type mcnp_version: tuple :returns: The MCNP_Problem instance representing this file. + :param encoding: The encoding scheme to use. + :type encoding: str :rtype: MCNP_Problem :raises UnsupportedFeature: If an input format is used that MontePy does not support. :raises MalformedInputError: If an input has a broken syntax. From dbf51330e4c96db15f8f58e6daa4e464e6180434 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 10:58:16 -0600 Subject: [PATCH 04/94] Actually propogated option through full stack. --- montepy/input_parser/input_reader.py | 2 +- montepy/input_parser/input_syntax_reader.py | 11 ++++++++++- montepy/mcnp_problem.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/montepy/input_parser/input_reader.py b/montepy/input_parser/input_reader.py index 12baa629..0be4ae07 100644 --- a/montepy/input_parser/input_reader.py +++ b/montepy/input_parser/input_reader.py @@ -32,5 +32,5 @@ def read_input(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): """ problem = mcnp_problem.MCNP_Problem(input_file) problem.mcnp_version = mcnp_version - problem.parse_input() + problem.parse_input(encoding=encoding) return problem diff --git a/montepy/input_parser/input_syntax_reader.py b/montepy/input_parser/input_syntax_reader.py index 540164a0..290d93d6 100644 --- a/montepy/input_parser/input_syntax_reader.py +++ b/montepy/input_parser/input_syntax_reader.py @@ -15,7 +15,7 @@ reading_queue = [] -def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION): +def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): """ Creates a generator function to return a new MCNP input for every new one that is encountered. @@ -25,11 +25,20 @@ def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION): The version must be a three component tuple e.g., (6, 2, 0) and (5, 1, 60). + .. Note:: + For different encoding schemes see the available list + `here `_. + + CP1252 is commonly referred to as "extended-ASCII". + You may have success with this encoding for working with special characters. + :param input_file: the path to the input file to be read :type input_file: MCNP_InputFile :param mcnp_version: The version of MCNP that the input is intended for. :type mcnp_version: tuple + :param encoding: The encoding scheme to use. + :type encoding: str :returns: a generator of MCNP_Object objects :rtype: generator """ diff --git a/montepy/mcnp_problem.py b/montepy/mcnp_problem.py index 7e4d8f3e..802b8d5d 100644 --- a/montepy/mcnp_problem.py +++ b/montepy/mcnp_problem.py @@ -232,10 +232,19 @@ def transforms(self): """ return self._transforms - def parse_input(self, check_input=False): + def parse_input(self, check_input=False, encoding="ascii"): """ Semantically parses the MCNP file provided to the constructor. + .. Note:: + For different encoding schemes see the available list + `here `_. + + CP1252 is commonly referred to as "extended-ASCII". + You may have success with this encoding for working with special characters. + + :param encoding: The encoding scheme to use. + :type encoding: str :param check_input: If true, will try to find all errors with input and collect them as warnings to log. :type check_input: bool """ From 1ffdc81ad2ff68c9b0ce46b6d2789ab91d1e6d05 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 11:18:48 -0600 Subject: [PATCH 05/94] Actually complete full stack chain(hopefully) --- montepy/input_parser/input_syntax_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/input_parser/input_syntax_reader.py b/montepy/input_parser/input_syntax_reader.py index 290d93d6..4c32f098 100644 --- a/montepy/input_parser/input_syntax_reader.py +++ b/montepy/input_parser/input_syntax_reader.py @@ -44,7 +44,7 @@ def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii" """ global reading_queue reading_queue = deque() - with input_file.open("r") as fh: + with input_file.open("r", encoding=encoding) as fh: yield from read_front_matters(fh, mcnp_version) yield from read_data(fh, mcnp_version) From 15cfb10b9be24fd226177f6b8c417a91d52f552b Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 11:54:03 -0600 Subject: [PATCH 06/94] Added test for poorly encoded file. --- tests/constants.py | 1 + tests/inputs/bad_encoding.imcnp | 52 +++++++++++++++++++++++++++++++++ tests/test_integration.py | 5 ++++ 3 files changed, 58 insertions(+) create mode 100644 tests/inputs/bad_encoding.imcnp diff --git a/tests/constants.py b/tests/constants.py index 27875fa8..66c4f706 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -21,4 +21,5 @@ "testReadRec2.imcnp", "testReadRec3.imcnp", "testReadTarget.imcnp", + "bad_encoding.imcnp" } diff --git a/tests/inputs/bad_encoding.imcnp b/tests/inputs/bad_encoding.imcnp new file mode 100644 index 00000000..7094afc7 --- /dev/null +++ b/tests/inputs/bad_encoding.imcnp @@ -0,0 +1,52 @@ +MESSAGE: this is a message +it should show up at the beginning +foo +Note: this file in encoded in "extended ascii": "CP-1252" + +MCNP Test Model for MOAA +C cells +c +1 1 20 + -1000 $ dollar comment + imp:n,p=1 U=350 trcl=5 +2 2 8 + -1005 + imp:n=1 + imp:p=0.5 +3 3 -1 + 1000 1005 -1010 + imp:n,p=1 +99 0 + 1010 + imp:n,p=0 +5 0 + #99 + imp:n,p=3 fill=350 (1 0 0 ) +c foo end comment + +C surfaces +1000 SO 1 +1005 RCC 0 1.5 -0.5 0 0 1 0.25 +1010 SO 3 + +C data +C materials +C UO2 5 atpt enriched +m1 92235.80c 5 & +92238.80c 95 +C Iron +m2 26054.80c 5.85 + 26056.80c 91.75 + 26057.80c 2.12 + 26058.80c 0.28 +C water +C foo +m3 1001.80c 2 + 8016.80c 1 +MT3 lwtr.23t h-zr.20t h/zr.28t +C execution +ksrc 0 0 0 +kcode 100000 1.000 50 1050 +phys:p j 1 2j 1 +mode n p +vol NO 2J 1 1.5 J diff --git a/tests/test_integration.py b/tests/test_integration.py index a43836b5..1da29c91 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1031,3 +1031,8 @@ def test_expansion_warning_crash(self): os.remove(out) except FileNotFoundError: pass + + def test_alternate_encoding(self): + with self.assertRaises(UnicodeDecodeError): + problem = montepy.read_input(os.path.join("tests", "inputs", "bad_encoding.imcnp")) + problem = montepy.read_input(os.path.join("tests", "inputs", "bad_encoding.imcnp"), encoding="cp1252") From 0dc5656a5a24500bcf99f9077c7b11554fead91a Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 12:01:10 -0600 Subject: [PATCH 07/94] Actually propogated encoding through. --- montepy/input_parser/input_file.py | 2 +- montepy/mcnp_problem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/montepy/input_parser/input_file.py b/montepy/input_parser/input_file.py index 00c60952..461306aa 100644 --- a/montepy/input_parser/input_file.py +++ b/montepy/input_parser/input_file.py @@ -79,7 +79,7 @@ def open(self, mode, encoding="ascii"): :type encoding: str :returns: self """ - self._fh = open(self.path, mode, encoding="ascii") + self._fh = open(self.path, mode, encoding=encoding) return self def __enter__(self): diff --git a/montepy/mcnp_problem.py b/montepy/mcnp_problem.py index 802b8d5d..9984a2d6 100644 --- a/montepy/mcnp_problem.py +++ b/montepy/mcnp_problem.py @@ -261,7 +261,7 @@ def parse_input(self, check_input=False, encoding="ascii"): try: for i, input in enumerate( input_syntax_reader.read_input_syntax( - self._input_file, self.mcnp_version + self._input_file, self.mcnp_version, encoding=encoding ) ): self._original_inputs.append(input) From 2e4edb1837a56e0e995c5bb4505ee36c39b3584b Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 12:07:01 -0600 Subject: [PATCH 08/94] Reformmated tests with black. --- tests/constants.py | 2 +- tests/test_integration.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/constants.py b/tests/constants.py index 66c4f706..2f4712b6 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -21,5 +21,5 @@ "testReadRec2.imcnp", "testReadRec3.imcnp", "testReadTarget.imcnp", - "bad_encoding.imcnp" + "bad_encoding.imcnp", } diff --git a/tests/test_integration.py b/tests/test_integration.py index 1da29c91..229ab40b 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1034,5 +1034,9 @@ def test_expansion_warning_crash(self): def test_alternate_encoding(self): with self.assertRaises(UnicodeDecodeError): - problem = montepy.read_input(os.path.join("tests", "inputs", "bad_encoding.imcnp")) - problem = montepy.read_input(os.path.join("tests", "inputs", "bad_encoding.imcnp"), encoding="cp1252") + problem = montepy.read_input( + os.path.join("tests", "inputs", "bad_encoding.imcnp") + ) + problem = montepy.read_input( + os.path.join("tests", "inputs", "bad_encoding.imcnp"), encoding="cp1252" + ) From 6119f8289f24d8271f9eb7a36fe0ce9103ad408d Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jan 2024 17:14:05 -0600 Subject: [PATCH 09/94] Started simple utility to convert to ascii. --- scripts/change_to_ascii.py | 63 ++++++++++++++++++++++++++++++++++++++ tests/inputs/unicode.imcnp | 52 +++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 scripts/change_to_ascii.py create mode 100644 tests/inputs/unicode.imcnp diff --git a/scripts/change_to_ascii.py b/scripts/change_to_ascii.py new file mode 100644 index 00000000..7a841611 --- /dev/null +++ b/scripts/change_to_ascii.py @@ -0,0 +1,63 @@ +import argparse +import sys + + +def define_args(args): + parser = argparse.ArgumentParser( + prog="Change_to_ascii", + description="Change the encoding of a file to strict ASCII. Everything not compliant will be removed.", + ) + parser.add_argument( + "-d", + "--delete", + dest="delete", + action="store_true", + help="Delete any non-ascii characters", + default=True, + ) + parser.add_argument( + "-w", + "--whitespace", + dest="whitespace", + action="store_true", + help="Replace non-ascii characters with a space.", + ) + parser.add_argument("in_file", nargs=1, help="The input file to convert") + parser.add_argument("out_file", nargs=1, help="The input file to convert") + args = parser.parse_args(args) + return args + + +def strip_characters(args): + if "whitespace" in args: + replacer = " " + elif "delete" in args: + replacer = "" + with open(args.in_file[0], "rb") as in_fh, open(args.out_file[0], "w") as out_fh: + for line in in_fh: + utf8_line = line.decode(encoding="utf8", errors="replace") + utf8_line = utf8_line.replace("�", replacer) + try: + out_fh.write( + utf8_line.encode(encoding="ascii", errors="strict").decode() + ) + except UnicodeError as e: + new_line = [] + # find the bad characters character by character + for char in utf8_line: + if ord(char) > 128: + new_line.append(replacer) + else: + new_line.append(char) + out_fh.write( + "".join(new_line).encode(encoding="ascii", errors="strict").decode() + ) + + +def main(args): + args = define_args(args) + strip_characters(args) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/tests/inputs/unicode.imcnp b/tests/inputs/unicode.imcnp new file mode 100644 index 00000000..7b7f09ba --- /dev/null +++ b/tests/inputs/unicode.imcnp @@ -0,0 +1,52 @@ +MESSAGE: this is a message +it should show up at the beginning +foo + +MCNP Test Model for MOAA +C cells 🔴⚪🐍 MontePy is great +c +1 1 20 + -1000 $ dollar comment + imp:n,p=1 U=350 trcl=5 +2 2 8 + -1005 + imp:n=1 + imp:p=0.5 +3 3 -1 + 1000 1005 -1010 + imp:n,p=1 +99 0 + 1010 + imp:n,p=0 +5 0 + #99 + imp:n,p=3 fill=350 (1 0 0 ) +c foo end comment + +C surfaces +1000 SO 1 +1005 RCC 0 1.5 -0.5 0 0 1 0.25 +1010 SO 3 + +C data +C materials +C UO2 5 atpt enriched +m1 92235.80c 5 & +92238.80c 95 +C Iron +m2 26054.80c 5.85 + 26056.80c 91.75 + 26057.80c 2.12 + 26058.80c 0.28 +C water +C foo +m3 1001.80c 2 + 8016.80c 1 +MT3 lwtr.23t h-zr.20t h/zr.28t +C execution +ksrc 0 0 0 +kcode 100000 1.000 50 1050 +phys:p j 1 2j 1 +mode n p +vol NO 2J 1 1.5 J + From eafeb8e4eb33394958820f096ddb2d4fc2522aa7 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 07:24:17 -0600 Subject: [PATCH 10/94] Ignored unicode input file. --- tests/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/constants.py b/tests/constants.py index 2f4712b6..505f113e 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -22,4 +22,5 @@ "testReadRec3.imcnp", "testReadTarget.imcnp", "bad_encoding.imcnp", + "unicode.imcnp", } From c837aa16b68b752ade252ccd43f40d73721b31e6 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 07:41:59 -0600 Subject: [PATCH 11/94] Made arguments mutually exclusive and corrected defaults. -Also changed to binary modes. --- scripts/change_to_ascii.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/change_to_ascii.py b/scripts/change_to_ascii.py index 7a841611..86d3a18a 100644 --- a/scripts/change_to_ascii.py +++ b/scripts/change_to_ascii.py @@ -7,15 +7,15 @@ def define_args(args): prog="Change_to_ascii", description="Change the encoding of a file to strict ASCII. Everything not compliant will be removed.", ) - parser.add_argument( + group = parser.add_mutually_exclusive_group() + group.add_argument( "-d", "--delete", dest="delete", action="store_true", - help="Delete any non-ascii characters", - default=True, + help="Delete any non-ascii characters. This is the default.", ) - parser.add_argument( + group.add_argument( "-w", "--whitespace", dest="whitespace", @@ -33,14 +33,16 @@ def strip_characters(args): replacer = " " elif "delete" in args: replacer = "" - with open(args.in_file[0], "rb") as in_fh, open(args.out_file[0], "w") as out_fh: + # default to delete + else: + replacer = "" + with open(args.in_file[0], "rb") as in_fh, open(args.out_file[0], "wb") as out_fh: for line in in_fh: utf8_line = line.decode(encoding="utf8", errors="replace") utf8_line = utf8_line.replace("�", replacer) + try: - out_fh.write( - utf8_line.encode(encoding="ascii", errors="strict").decode() - ) + out_fh.write(utf8_line.encode(encoding="ascii", errors="strict")) except UnicodeError as e: new_line = [] # find the bad characters character by character @@ -50,7 +52,7 @@ def strip_characters(args): else: new_line.append(char) out_fh.write( - "".join(new_line).encode(encoding="ascii", errors="strict").decode() + "".join(new_line).encode(encoding="ascii", errors="strict") ) From c4f84634465a085baff691812e0198bb9b8b13c6 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 07:43:23 -0600 Subject: [PATCH 12/94] Correctly checked if an argument was there. --- scripts/change_to_ascii.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/change_to_ascii.py b/scripts/change_to_ascii.py index 86d3a18a..1f8ae81b 100644 --- a/scripts/change_to_ascii.py +++ b/scripts/change_to_ascii.py @@ -29,9 +29,9 @@ def define_args(args): def strip_characters(args): - if "whitespace" in args: + if args.whitespace: replacer = " " - elif "delete" in args: + elif args.delete: replacer = "" # default to delete else: From 7517d8f6401a078b9ed0933567ef7ce69782241e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 08:49:57 -0600 Subject: [PATCH 13/94] Wrote tests for scripts. --- tests/constants.py | 5 +++ tests/test_scripts.py | 83 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/test_scripts.py diff --git a/tests/constants.py b/tests/constants.py index 505f113e..7398f7e4 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -24,3 +24,8 @@ "bad_encoding.imcnp", "unicode.imcnp", } + +BAD_ENCODING_FILES = { + "bad_encoding.imcnp", + "unicode.imcnp", +} diff --git a/tests/test_scripts.py b/tests/test_scripts.py new file mode 100644 index 00000000..88b9d8c4 --- /dev/null +++ b/tests/test_scripts.py @@ -0,0 +1,83 @@ +import itertools +from unittest import TestCase +from tests import constants +import os +import subprocess + + +class TestChangeAsciiScript(TestCase): + @classmethod + def setUpClass(cls): + new_files = {} + for input_file in constants.BAD_ENCODING_FILES: + new_files[input_file] = {} + for flag in {"-w", "-d"}: + new_file = f"{input_file}{flag}.imcnp" + cls.run_script( + [flag, os.path.join("tests", "inputs", input_file), new_file] + ) + new_files[input_file][flag] = new_file + cls.files = new_files + + @classmethod + def tearDownClass(cls): + for group in cls.files.values(): + for file_name in group.values(): + try: + os.remove(file_name) + except FileNotFoundError: + pass + + @staticmethod + def run_script(args): + return subprocess.run( + ["python", os.path.join("scripts", "change_to_ascii.py")] + args + ) + + def test_delete_bad(self): + for in_file in self.files: + with open(os.path.join("tests", "inputs", in_file), "rb") as in_fh, open( + self.files[in_file]["-d"], "rb" + ) as out_fh: + for in_line, out_line in zip(in_fh, out_fh): + try: + in_line.decode("ascii") + self.assertEqual(in_line, out_line) + except UnicodeError: + new_line = [] + for char in in_line: + if char <= 128: + new_line.append(chr(char)) + self.assertEqual("".join(new_line), out_line.decode("ascii")) + + def test_whitespace_bad(self): + for in_file in self.files: + with open(os.path.join("tests", "inputs", in_file), "rb") as in_fh, open( + self.files[in_file]["-w"], "rb" + ) as out_fh: + for in_line, out_line in zip(in_fh, out_fh): + try: + in_line.decode("ascii") + self.assertEqual(in_line, out_line) + except UnicodeError: + try: + print(in_line.decode()) + except UnicodeError: + pass + new_line = [] + for char in in_line: + if char <= 128: + new_line.append(chr(char)) + else: + new_line.append(" ") + self.assertEqual("".join(new_line), out_line.decode("ascii")) + + def test_bad_arguments(self): + ret_code = self.run_script( + [ + "-w", + "-d", + os.path.join("tests", "inputs", "bad_encode.imcnp", "foo.imcnp"), + ] + ) + self.assertNotEqual(ret_code.returncode, 0) From c92a5d4213dbcd0f8defccd7cca29ef9140d3da7 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 09:53:08 -0600 Subject: [PATCH 14/94] Updated test to handle going in and out of UTF-8 --- tests/test_scripts.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 88b9d8c4..6ba01bd9 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -60,16 +60,21 @@ def test_whitespace_bad(self): in_line.decode("ascii") self.assertEqual(in_line, out_line) except UnicodeError: + new_line = [] try: - print(in_line.decode()) + # try to change to utf-8 + for char in in_line.decode(): + if ord(char) <= 128: + new_line.append(char) + else: + new_line.append(" ") except UnicodeError: - pass - new_line = [] - for char in in_line: - if char <= 128: - new_line.append(chr(char)) - else: - new_line.append(" ") + # try to go bit by bit + for char in in_line: + if char <= 128: + new_line.append(chr(char)) + else: + new_line.append(" ") self.assertEqual("".join(new_line), out_line.decode("ascii")) def test_bad_arguments(self): From 1a2b3aae2eacabc150bd97ba224c995d58639634 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 09:58:56 -0600 Subject: [PATCH 15/94] Updated pyproject to expose script, and test it. --- .github/workflows/main.yml | 2 ++ pyproject.toml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d635a22b..37c21ab9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,8 @@ jobs: - run: pip install . - run: pip uninstall -y montepy - run: pip install --user dist/*.whl + # run scripts + - run: change_to_ascii -h - run: pip uninstall -y montepy - run: pip install --user dist/*.tar.gz - run: pip install --user montepy[test] diff --git a/pyproject.toml b/pyproject.toml index 6dd48dad..61405dc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,9 @@ Repository = "https://github.com/idaholab/montepy.git" Documentation = "https://idaholab.github.io/MontePy/index.html" "Bug Tracker" = "https://github.com/idaholab/MontePy/issues" +[project.scripts] +"change_to_ascii" = "scripts.change_to_ascii:main" + [build-system] requires = ["setuptools >= 61.0.0"] build-backend = "setuptools.build_meta" From 89a29f13a0cf710b124276e76ac940b6498fb291 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 10:25:54 -0600 Subject: [PATCH 16/94] Fixed scripts system to actually work. --- montepy/_scripts/__init__.py | 0 {scripts => montepy/_scripts}/change_to_ascii.py | 4 +++- pyproject.toml | 2 +- tests/test_scripts.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 montepy/_scripts/__init__.py rename {scripts => montepy/_scripts}/change_to_ascii.py (96%) diff --git a/montepy/_scripts/__init__.py b/montepy/_scripts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/change_to_ascii.py b/montepy/_scripts/change_to_ascii.py similarity index 96% rename from scripts/change_to_ascii.py rename to montepy/_scripts/change_to_ascii.py index 1f8ae81b..a9bd86fb 100644 --- a/scripts/change_to_ascii.py +++ b/montepy/_scripts/change_to_ascii.py @@ -56,7 +56,9 @@ def strip_characters(args): ) -def main(args): +def main(args=None): + if args is None: + args = sys.argv[1:] args = define_args(args) strip_characters(args) diff --git a/pyproject.toml b/pyproject.toml index 61405dc5..122589bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ Documentation = "https://idaholab.github.io/MontePy/index.html" "Bug Tracker" = "https://github.com/idaholab/MontePy/issues" [project.scripts] -"change_to_ascii" = "scripts.change_to_ascii:main" +"change_to_ascii" = "montepy._scripts.change_to_ascii:main" [build-system] requires = ["setuptools >= 61.0.0"] diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 6ba01bd9..aa68de76 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -31,7 +31,7 @@ def tearDownClass(cls): @staticmethod def run_script(args): return subprocess.run( - ["python", os.path.join("scripts", "change_to_ascii.py")] + args + ["python", os.path.join("montepy", "_scripts", "change_to_ascii.py")] + args ) def test_delete_bad(self): From 522820cc8adb6d4a0bdf62176ce8ba7e5d4b7f96 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 16:24:47 -0600 Subject: [PATCH 17/94] Added doc strings. --- montepy/_scripts/change_to_ascii.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/montepy/_scripts/change_to_ascii.py b/montepy/_scripts/change_to_ascii.py index a9bd86fb..0f056d7e 100644 --- a/montepy/_scripts/change_to_ascii.py +++ b/montepy/_scripts/change_to_ascii.py @@ -3,6 +3,14 @@ def define_args(args): + """ + Parses the arguments from the command line. + + :param args: the arguments from the command line. + :type args: list + :returns: the parsed arguments (with argparse) + :rtype: argparse.Namespace + """ parser = argparse.ArgumentParser( prog="Change_to_ascii", description="Change the encoding of a file to strict ASCII. Everything not compliant will be removed.", @@ -29,6 +37,12 @@ def define_args(args): def strip_characters(args): + """ + Strips non-ascii characters from the input file, and writes out the output file. + + :param args: the parsed command line arguments. + :type args: argparse.Namespace + """ if args.whitespace: replacer = " " elif args.delete: @@ -57,6 +71,12 @@ def strip_characters(args): def main(args=None): + """ + Main runner function. + + :param args: The arguments passed from the command line. + :type args: list + """ if args is None: args = sys.argv[1:] args = define_args(args) From 99b8ae4b7d0683e61fdf05812e411a37546de6b2 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Thu, 18 Jan 2024 17:06:21 -0600 Subject: [PATCH 18/94] Added utilities and FAQ. --- doc/source/faq.rst | 2 + doc/source/index.rst | 4 ++ doc/source/utilities.rst | 111 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 doc/source/faq.rst create mode 100644 doc/source/utilities.rst diff --git a/doc/source/faq.rst b/doc/source/faq.rst new file mode 100644 index 00000000..d738b9cd --- /dev/null +++ b/doc/source/faq.rst @@ -0,0 +1,2 @@ +Frequently Asked Questions +========================== diff --git a/doc/source/index.rst b/doc/source/index.rst index be171a76..9998c239 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -12,8 +12,12 @@ Welcome to MontePy's documentation! starting + utilities + tricks + faq + developing api/modules diff --git a/doc/source/utilities.rst b/doc/source/utilities.rst new file mode 100644 index 00000000..03a4abd2 --- /dev/null +++ b/doc/source/utilities.rst @@ -0,0 +1,111 @@ +Utility Scripts +=============== + +Package Level Execution Options +------------------------------- +.. code-block:: console + + usage: montepy [-h] [-c [input_file ...]] + + Tool for editing and working with MCNP input files. + + options: + -h, --help show this help message and exit + -c [input_file ...], --check [input_file ...] + Check the given input file(s) for errors. Accepts globs, and multiple arguments. + +Checking Input Files for Errors +------------------------------- +MontePy can be used to check for errors that it will check for. +MontePy will check for: + +* general syntax errors +* syntax errors for all MCNP Objects supported (e.g., cells, surfaces, materials, etc.) +* Bad references to other object when the object referring to another object is supported. +* Bad mode options + +It will print all errors it found in the input to the terminal. + +To use this run: + +.. code-block:: console + + python -m montepy -c [files] + +Converting Encoding to ASCII +---------------------------- + +.. _ascii_command: + +Command Line Options +++++++++++++++++++++ +.. code-block:: console + + usage: Change_to_ascii [-h] [-d | -w] in_file out_file + + Change the encoding of a file to strict ASCII. Everything not compliant will be removed. + + positional arguments: + in_file The input file to convert + out_file The input file to convert + + options: + -h, --help show this help message and exit + -d, --delete Delete any non-ascii characters. This is the default. + -w, --whitespace Replace non-ascii characters with a space. + + +Background +++++++++++ +`Character encoding `_ is the process of representing all characters as numbers, +so they may be used by a computer. +It is the bane of almost all programmers. + +The `American Standard Code for Information Interchange (ASCII) `_ is one of the oldest, +and simplest encoding standards. +It uses one byte per character, +and only goes from 0 – 127. +This has some issues, being very American-centric, +and also only allowing 128 characters, +52 of them being the English alphabet. +One solution to this was `"Extended ASCII" `_, +which used the final bit, and allowed the encoding system +to include 0 – 255. +There isn't one "Extended ASCII", +but one of the most popular encodings is Windows CP-1252. +This isn't great. + +The most commonly used encoding now is `UTF-8 `_, or "unicode". +UTF-8 can support almost any printable character in any language, including emojis. +The complexity is that each character is a variable-length of bytes. +This means that older software, like fortran, may get confused by it. + +As far as I can tell MCNP does not document what encoding it uses. +ASCII is the most conservative bet, +so MontePy by default tries to read input files in strict ASCII. + +Dealing with Encoding Issues +++++++++++++++++++++++++++++ + +You are likely here because you got an error message something like this: + +>>> montepy.read_input("example.imcnp") +UnicodeDecodeError Traceback (most recent call last) + +UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1132: ordinal not in range(128) + +You can either change the encoding used by :func:`~montepy.input_parser.input_reader.read_input`, +or just force the entire file to be strictly ASCII. + +MontePY offers the ``change_to_ascii`` script. +The options are listed above: :ref:`ascii_command`. +For any non-ASCII character it will either remove +the character or replace it with a space (``' '``). +It defaults to deleting. +To replace it with a space instead use ``-w``. +Otherwise the arguments are the input file to correct, +and the path to write the output file to. + +.. code-block:: console + + change_to_ascii -w unicode_input.imcnp ascii_input.imcnp From 0746fb1d5eef6070be316997eb07c080389be7a1 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 19 Jan 2024 09:13:09 -0600 Subject: [PATCH 19/94] Added debugging help for encoding errors. --- doc/source/faq.rst | 68 ++++++++++++++++++++++++++++++++++++++++ doc/source/utilities.rst | 4 +++ 2 files changed, 72 insertions(+) diff --git a/doc/source/faq.rst b/doc/source/faq.rst index d738b9cd..b075d03b 100644 --- a/doc/source/faq.rst +++ b/doc/source/faq.rst @@ -1,2 +1,70 @@ Frequently Asked Questions ========================== + +Or more likely Frequent Error Debugging. + +Encoding Errors: UnicodeDecodeError +----------------------------------- + +If you received the error below while opening a file in MontePy, +there is like a non-ASCII character in your input file. +You can read more about :ref:`Character Encoding here `. + +To solve this problem you can: + +1. Try another encoding such as ``'utf8'`` or ``'cp1252'``. Pass it as an argument to :func:`~montepy.input_parser.input_reader.read_input`. +2. Remove all non-ASCII characters with :ref:`the change_to_ascii utility ` + +.. code-block:: python + + --------------------------------------------------------------------------- + UnicodeDecodeError Traceback (most recent call last) + Cell In[2], line 1 + ----> 1 problem = montepy.read_input("tests/inputs/bad_encoding.imcnp") + + File ~/dev/montepy/montepy/input_parser/input_reader.py:35, in read_input(input_file, mcnp_version, encoding) + 33 problem = mcnp_problem.MCNP_Problem(input_file) + 34 problem.mcnp_version = mcnp_version + ---> 35 problem.parse_input(encoding=encoding) + 36 return problem + + File ~/dev/montepy/montepy/mcnp_problem.py:262, in MCNP_Problem.parse_input(self, check_input, encoding) + 253 OBJ_MATCHER = { + 254 block_type.BlockType.CELL: (Cell, self._cells), + 255 block_type.BlockType.SURFACE: ( + (...) + 259 block_type.BlockType.DATA: (parse_data, self._data_inputs), + 260 } + 261 try: + --> 262 for i, input in enumerate( + 263 input_syntax_reader.read_input_syntax( + 264 self._input_file, self.mcnp_version, encoding=encoding + 265 ) + 266 ): + 267 self._original_inputs.append(input) + 268 if i == 0 and isinstance(input, mcnp_input.Message): + + File ~/dev/montepy/montepy/input_parser/input_syntax_reader.py:48, in read_input_syntax(input_file, mcnp_version, encoding) + 46 reading_queue = deque() + 47 with input_file.open("r", encoding=encoding) as fh: + ---> 48 yield from read_front_matters(fh, mcnp_version) + 49 yield from read_data(fh, mcnp_version) + + File ~/dev/montepy/montepy/input_parser/input_syntax_reader.py:79, in read_front_matters(fh, mcnp_version) + 77 lines = [] + 78 raw_lines = [] + ---> 79 for i, line in enumerate(fh): + 80 if i == 0 and line.upper().startswith("MESSAGE:"): + 81 is_in_message_block = True + + File ~/dev/montepy/montepy/input_parser/input_file.py:95, in MCNP_InputFile.__iter__(self) + 94 def __iter__(self): + ---> 95 for lineno, line in enumerate(self._fh): + 96 self._lineno = lineno + 1 + 97 yield line + + File ~/mambaforge/lib/python3.10/encodings/ascii.py:26, in IncrementalDecoder.decode(self, input, final) + 25 def decode(self, input, final=False): + ---> 26 return codecs.ascii_decode(input, self.errors)[0] + + UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 159: ordinal not in range(128) diff --git a/doc/source/utilities.rst b/doc/source/utilities.rst index 03a4abd2..4d42e3ad 100644 --- a/doc/source/utilities.rst +++ b/doc/source/utilities.rst @@ -32,6 +32,8 @@ To use this run: python -m montepy -c [files] +.. _convert_ascii: + Converting Encoding to ASCII ---------------------------- @@ -55,6 +57,8 @@ Command Line Options -w, --whitespace Replace non-ascii characters with a space. +.. _encoding_background: + Background ++++++++++ `Character encoding `_ is the process of representing all characters as numbers, From bac71c7d06a4ccb74c6197a8ae0c008205ffefe0 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 10:35:51 -0600 Subject: [PATCH 20/94] Deleted all gitlab CI work. --- .gitlab-ci.yml | 167 ------------------------------------------ templates/install.yml | 37 ---------- templates/test.yml | 15 ---- 3 files changed, 219 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 templates/install.yml delete mode 100644 templates/test.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index d486b16a..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,167 +0,0 @@ -image: python:latest - -include: - - templates/install.yml - - templates/test.yml - -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -default: - artifacts: - expire_in: 7 day - -after_script: - - export PATH=$(echo "$PATH" | sed -e 's/:\/data\/gitlab-runner\/.conda\/envs\/experiment_analysis_mcnpy\/$//') - - echo $PATH - - conda deactivate - -.job_template: &install-boiler - stage: build - extends: .install - when: delayed - start_in: 1 minutes - variables: - PYTHON_VER: "3.8" - -install-3.8: - stage: build - extends: .install - variables: - PYTHON_VER: "3.8" - -install-3.9: - <<: *install-boiler - variables: - PYTHON_VER: "3.9" - - -install-3.10: - <<: *install-boiler - variables: - PYTHON_VER: "3.10" - -install-3.11: - <<: *install-boiler - variables: - PYTHON_VER: "3.11" - -install-3.12: - <<: *install-boiler - variables: - PYTHON_VER: "3.12" - -coverage_unit_test: - stage: test - coverage: '/TOTAL.+ ([0-9\.]{1,5}%)/' - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo $PATH - - echo "Executing unit tests" - - which python - - pip freeze - - coverage run -m pytest --junitxml=test_report.xml - - coverage report - - coverage xml - artifacts: - reports: - junit: test_report.xml - coverage_report: - coverage_format: cobertura - path: coverage.xml - needs: ["install-3.8"] - -# skip 3.8 because of coverage test - -.job_template: &test_config - stage: test - extends: .test_no_cover - -unit_test-3.9: - <<: *test_config - variables: - PYTHON_VER: "3.9" - needs: ["coverage_unit_test","install-3.9"] - -unit_test-3.10: - <<: *test_config - variables: - PYTHON_VER: "3.10" - needs: ["coverage_unit_test","install-3.10"] - -unit_test-3.11: - <<: *test_config - variables: - PYTHON_VER: "3.11" - needs: ["coverage_unit_test","install-3.11"] - -unit_test-3.12: - <<: *test_config - variables: - PYTHON_VER: "3.12" - needs: ["coverage_unit_test","install-3.12"] - -doc_test: - stage: test - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Executing Sphinx build to detect syntax errors" - - sphinx-build doc/source/ doc/build/ -W --keep-going -E - - sphinx-build -b html doc/source/ doc/build/html - - mv doc/build/html html - needs: ["install-3.8"] - artifacts: - expose_as: 'Updated Documentation' - paths: - - html - expire_in: 1 day - -format_test: - stage: test - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Testing if anything is unformatted" - - echo "If error occurs changes were not formatted using black" - - black --check montepy/ tests/ - needs: ["install-3.8"] - - - -pages: - stage: deploy - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Building documentation with Sphinx." - - cd doc/ - - make html - - cd .. - - mv doc/build/html public - - python -m build --sdist --wheel - - mv dist/ public/dist - artifacts: - paths: - - public - only: - - master - - main - - doc - - -packaging: - stage: deploy - script: - - rm dist/* - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - pip install build twine - - python -m build --sdist --wheel - - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* - - only: - - master - - main diff --git a/templates/install.yml b/templates/install.yml deleted file mode 100644 index 8ccea7bb..00000000 --- a/templates/install.yml +++ /dev/null @@ -1,37 +0,0 @@ -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -.install: - script: - - if [[ -d dist ]]; then rm -r dist ; fi; - - if [[ `conda env list` == *"$CONDA_BASE_NAME-$PYTHON_VER"* ]]; then - - else - - conda create -n $CONDA_BASE_NAME-$PYTHON_VER -y python==$PYTHON_VER - - fi - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - echo "Installing dependencies" - - which python - - which pip - - pip uninstall -y montepy - # make alternate package to confuse the builder. - - if [[ -d fake_py ]]; then mkdir fake_py; fi; - - if [[ -f fake_py/__init__.py ]]; then - - touch fake_py/__init__.py - - fi - # install base requirements first - - pip install -r requirements/common.txt - # needed to build. Users shouldn't be doing this on their own. - # Want to make sure it can be installed without dev stuff. - - pip install build - - python -m build --sdist --wheel - - pip install . - - pip uninstall -y montepy - - pip install --user dist/*.whl - # test the extras installation - - pip install --user montepy[test] - - pip install --user montepy[doc] - - pip freeze - artifacts: - paths: - - dist/ diff --git a/templates/test.yml b/templates/test.yml deleted file mode 100644 index 5284fd9b..00000000 --- a/templates/test.yml +++ /dev/null @@ -1,15 +0,0 @@ -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -.test_no_cover: - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - which python - - pip freeze - - python -m pytest --junitxml=test_report.xml - artifacts: - reports: - junit: test_report.xml - From 6a14b71ade254958d6cbb497acf7e7b9d3d07951 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:08:24 -0600 Subject: [PATCH 21/94] Removed pytest.ini --- pyproject.toml | 2 ++ pytest.ini | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 6dd48dad..5bed2826 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,3 +69,5 @@ exclude_also = [ [tool.pytest.ini_options] minversion = "6.0" junit_logging = "all" +junit_family="xunit2" +filterwarnings="error" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 731f942b..00000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -junit_family=xunit2 -filterwarnings=error From 4846286f8aaeffc24c4e63b8918b2ed3553f711f Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:24:14 -0600 Subject: [PATCH 22/94] Moved all requirements to pypyroject.toml --- pyproject.toml | 21 ++++++++++++++++----- requirements/common.txt | 2 -- requirements/dev.txt | 8 -------- 3 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 requirements/common.txt delete mode 100644 requirements/dev.txt diff --git a/pyproject.toml b/pyproject.toml index 5bed2826..534453cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,7 @@ description = "A library for reading, editing, and writing MCNP input files" # gitlab limits the readme to 4,000 chars. readme = "README.md" requires-python = ">=3.8" -maintainers = [ - {name = "Micah Gale", email = "micah.gale@inl.gov"} -] +maintainers = {name="Micah Gale", email="micah.gale@inl.gov"} authors = [ {name = "Micah Gale", email = "micah.gale@inl.gov"}, {name = "Travis Labossiere-Hickman", email = "Travis.LabossiereHickman@inl.gov"}, @@ -30,13 +28,26 @@ classifiers = [ ] dependencies = [ - "numpy", + "numpy>=1.18", "sly==0.5" ] [project.optional-dependencies] -test = ["coverage", "pytest"] +test = ["coverage[toml]>=6.3.2", "pytest"] doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] +format = ["black>23.3.0"] +build = [ + "build", + "setuptool_scm", + "bump2version" +] +develop = [ + "montepy[test]", + "montepy[doc]", + "montepy[format]", + "montepy[build]", +] + [project.urls] Homepage = "https://idaholab.github.io/MontePy/index.html" diff --git a/requirements/common.txt b/requirements/common.txt deleted file mode 100644 index 97e31a82..00000000 --- a/requirements/common.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy >= 1.18 -sly >= 0.5.0 diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index c73727e3..00000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,8 +0,0 @@ --r common.txt -build -sphinx~=4.3 -sphinxcontrib-apidoc -sphinx_rtd_theme -coverage[toml]>=6.3.2 -pytest -black==23.3.0 From 4c33d4aeead116f9f7095666ad90b435fa373d0e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:28:15 -0600 Subject: [PATCH 23/94] Updated actions to not use requirements anymore. --- .github/workflows/deploy.yml | 6 +++--- .github/workflows/main.yml | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e75139c7..9de7ea0c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user -r requirements/dev.txt + - run: pip install montepy[develop] - run: python -m pytest build-pages: @@ -75,7 +75,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install build + - run: python -m pip install montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -96,7 +96,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install build + - run: python -m pip install montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d635a22b..9216a003 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: pip install --upgrade pip build - - run: pip install -r requirements/common.txt + - run: pip install build - run: python -m build --sdist --wheel - run: pip install . - run: pip uninstall -y montepy @@ -25,6 +25,9 @@ jobs: - run: pip install --user dist/*.tar.gz - run: pip install --user montepy[test] - run: pip install --user montepy[doc] + - run: pip install --user montepy[format] + - run: pip install --user montepy[build] + - run: pip install --user montepy[develop] - run: pip freeze - name: Upload build artifacts uses: actions/upload-artifact@v3 @@ -44,7 +47,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - run: pip install --user -r requirements/dev.txt + - run: pip install --user montepy[test] - run: coverage run -m pytest --junitxml=test_report.xml - run: coverage report - run: coverage xml @@ -85,7 +88,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user -r requirements/dev.txt + - run: pip install montepy[format] - run: black --check montepy/ tests/ From bf175fddcaa931b6de6d11693862126d852ab6d6 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:35:34 -0600 Subject: [PATCH 24/94] Fixed bad maintainers. --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 534453cb..ccf38d32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,9 @@ description = "A library for reading, editing, and writing MCNP input files" # gitlab limits the readme to 4,000 chars. readme = "README.md" requires-python = ">=3.8" -maintainers = {name="Micah Gale", email="micah.gale@inl.gov"} +maintainers = [ + {name = "Micah Gale", email = "micah.gale@inl.gov"} +] authors = [ {name = "Micah Gale", email = "micah.gale@inl.gov"}, {name = "Travis Labossiere-Hickman", email = "Travis.LabossiereHickman@inl.gov"}, From 0eef2c18464cdcb6693b66d3dd2ed9df9ced7f60 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:38:20 -0600 Subject: [PATCH 25/94] Relaxed black requirement. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ccf38d32..9725cc3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dependencies = [ [project.optional-dependencies] test = ["coverage[toml]>=6.3.2", "pytest"] doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] -format = ["black>23.3.0"] +format = ["black>=23.3.0"] build = [ "build", "setuptool_scm", From d166e43a47826fad2c9aee3d5d4a21fc8f81e337 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:44:38 -0600 Subject: [PATCH 26/94] Had pip defer to local for installing. --- .github/workflows/deploy.yml | 8 ++++---- .github/workflows/main.yml | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9de7ea0c..b5321f62 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[develop] + - run: pip install . montepy[develop] - run: python -m pytest build-pages: @@ -30,7 +30,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user montepy[doc] + - run: pip install --user . montepy[doc] - run: cd doc && make html - uses: actions/configure-pages@v4 - uses: actions/upload-pages-artifact@v3 @@ -75,7 +75,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install montepy[build] + - run: python -m pip install . montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -96,7 +96,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install montepy[build] + - run: python -m pip install . montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9216a003..01283017 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,11 +23,11 @@ jobs: - run: pip install --user dist/*.whl - run: pip uninstall -y montepy - run: pip install --user dist/*.tar.gz - - run: pip install --user montepy[test] - - run: pip install --user montepy[doc] - - run: pip install --user montepy[format] - - run: pip install --user montepy[build] - - run: pip install --user montepy[develop] + - run: pip install --user . montepy[test] + - run: pip install --user . montepy[doc] + - run: pip install --user . montepy[format] + - run: pip install --user . montepy[build] + - run: pip install --user . montepy[develop] - run: pip freeze - name: Upload build artifacts uses: actions/upload-artifact@v3 @@ -47,7 +47,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - run: pip install --user montepy[test] + - run: pip install --user . montepy[test] - run: coverage run -m pytest --junitxml=test_report.xml - run: coverage report - run: coverage xml @@ -71,7 +71,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[doc] + - run: pip install . montepy[doc] - run: sphinx-build doc/source/ doc/build/ -W --keep-going -E - run: sphinx-build -b html doc/source/ doc/build/html - uses: actions/upload-artifact@v3 @@ -88,7 +88,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[format] + - run: pip install . montepy[format] - run: black --check montepy/ tests/ From 373cfac26605cc2098757161e2dc9cd989bdde3e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:16:05 -0600 Subject: [PATCH 27/94] Correct setuptools-scm dependency --- pyproject.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9725cc3e..20f93952 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] format = ["black>=23.3.0"] build = [ "build", - "setuptool_scm", + "setuptools_scm>=8", "bump2version" ] develop = [ @@ -58,9 +58,12 @@ Documentation = "https://idaholab.github.io/MontePy/index.html" "Bug Tracker" = "https://github.com/idaholab/MontePy/issues" [build-system] -requires = ["setuptools >= 61.0.0"] +requires = ["setuptools >= 64.0.0", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +version_file = "montepy/_version.py" + [tool.setuptools.packages.find] include = ["montepy*"] From 88ad4f8f4c0959baf054630e7db5366289735eca Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:27:54 -0600 Subject: [PATCH 28/94] Ignoring version file from setuptools_scm --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18762426..990257f6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ doc/build/* .coverage .idea/ .ipynb_checkpoints/ +montepy/_version.py From 9fb3b123bfa53f77d1f01ab0b6bba3c26cc5523e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:53:03 -0600 Subject: [PATCH 29/94] Implemented Coveralls with a lot of trial and error. --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01283017..2d7f1663 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,10 +57,14 @@ jobs: name: test path: test_report.xml - name: Upload coverage report - uses: actions/upload-artifact@v3 + if: ${{ matrix.python-version == '3.9' }} + uses: actions/upload-artifact@v4 with: name: coverage path: coverage.xml + - name: Coveralls GitHub Action + if: ${{ matrix.python-version == '3.9' }} + uses: coverallsapp/github-action@v2.2.3 doc-test: runs-on: ubuntu-latest From 4f1c6b65bef34a4ce14914b586bf16f54e70af41 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 10:35:51 -0600 Subject: [PATCH 30/94] Deleted all gitlab CI work. --- .gitlab-ci.yml | 167 ------------------------------------------ templates/install.yml | 37 ---------- templates/test.yml | 15 ---- 3 files changed, 219 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 templates/install.yml delete mode 100644 templates/test.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index d486b16a..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,167 +0,0 @@ -image: python:latest - -include: - - templates/install.yml - - templates/test.yml - -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -default: - artifacts: - expire_in: 7 day - -after_script: - - export PATH=$(echo "$PATH" | sed -e 's/:\/data\/gitlab-runner\/.conda\/envs\/experiment_analysis_mcnpy\/$//') - - echo $PATH - - conda deactivate - -.job_template: &install-boiler - stage: build - extends: .install - when: delayed - start_in: 1 minutes - variables: - PYTHON_VER: "3.8" - -install-3.8: - stage: build - extends: .install - variables: - PYTHON_VER: "3.8" - -install-3.9: - <<: *install-boiler - variables: - PYTHON_VER: "3.9" - - -install-3.10: - <<: *install-boiler - variables: - PYTHON_VER: "3.10" - -install-3.11: - <<: *install-boiler - variables: - PYTHON_VER: "3.11" - -install-3.12: - <<: *install-boiler - variables: - PYTHON_VER: "3.12" - -coverage_unit_test: - stage: test - coverage: '/TOTAL.+ ([0-9\.]{1,5}%)/' - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo $PATH - - echo "Executing unit tests" - - which python - - pip freeze - - coverage run -m pytest --junitxml=test_report.xml - - coverage report - - coverage xml - artifacts: - reports: - junit: test_report.xml - coverage_report: - coverage_format: cobertura - path: coverage.xml - needs: ["install-3.8"] - -# skip 3.8 because of coverage test - -.job_template: &test_config - stage: test - extends: .test_no_cover - -unit_test-3.9: - <<: *test_config - variables: - PYTHON_VER: "3.9" - needs: ["coverage_unit_test","install-3.9"] - -unit_test-3.10: - <<: *test_config - variables: - PYTHON_VER: "3.10" - needs: ["coverage_unit_test","install-3.10"] - -unit_test-3.11: - <<: *test_config - variables: - PYTHON_VER: "3.11" - needs: ["coverage_unit_test","install-3.11"] - -unit_test-3.12: - <<: *test_config - variables: - PYTHON_VER: "3.12" - needs: ["coverage_unit_test","install-3.12"] - -doc_test: - stage: test - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Executing Sphinx build to detect syntax errors" - - sphinx-build doc/source/ doc/build/ -W --keep-going -E - - sphinx-build -b html doc/source/ doc/build/html - - mv doc/build/html html - needs: ["install-3.8"] - artifacts: - expose_as: 'Updated Documentation' - paths: - - html - expire_in: 1 day - -format_test: - stage: test - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Testing if anything is unformatted" - - echo "If error occurs changes were not formatted using black" - - black --check montepy/ tests/ - needs: ["install-3.8"] - - - -pages: - stage: deploy - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - echo "Building documentation with Sphinx." - - cd doc/ - - make html - - cd .. - - mv doc/build/html public - - python -m build --sdist --wheel - - mv dist/ public/dist - artifacts: - paths: - - public - only: - - master - - main - - doc - - -packaging: - stage: deploy - script: - - rm dist/* - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - pip install build twine - - python -m build --sdist --wheel - - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* - - only: - - master - - main diff --git a/templates/install.yml b/templates/install.yml deleted file mode 100644 index 8ccea7bb..00000000 --- a/templates/install.yml +++ /dev/null @@ -1,37 +0,0 @@ -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -.install: - script: - - if [[ -d dist ]]; then rm -r dist ; fi; - - if [[ `conda env list` == *"$CONDA_BASE_NAME-$PYTHON_VER"* ]]; then - - else - - conda create -n $CONDA_BASE_NAME-$PYTHON_VER -y python==$PYTHON_VER - - fi - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - echo "Installing dependencies" - - which python - - which pip - - pip uninstall -y montepy - # make alternate package to confuse the builder. - - if [[ -d fake_py ]]; then mkdir fake_py; fi; - - if [[ -f fake_py/__init__.py ]]; then - - touch fake_py/__init__.py - - fi - # install base requirements first - - pip install -r requirements/common.txt - # needed to build. Users shouldn't be doing this on their own. - # Want to make sure it can be installed without dev stuff. - - pip install build - - python -m build --sdist --wheel - - pip install . - - pip uninstall -y montepy - - pip install --user dist/*.whl - # test the extras installation - - pip install --user montepy[test] - - pip install --user montepy[doc] - - pip freeze - artifacts: - paths: - - dist/ diff --git a/templates/test.yml b/templates/test.yml deleted file mode 100644 index 5284fd9b..00000000 --- a/templates/test.yml +++ /dev/null @@ -1,15 +0,0 @@ -variables: - PYTHON_VER: "3.8" - CONDA_BASE_NAME: experiment_analysis_montepy - -.test_no_cover: - script: - - conda activate $CONDA_BASE_NAME-$PYTHON_VER - - export PATH="~/.local/bin/:/data/gitlab-runner/.conda/envs/$CONDA_BASE_NAME-$PYTHON_VER/bin:$PATH" - - which python - - pip freeze - - python -m pytest --junitxml=test_report.xml - artifacts: - reports: - junit: test_report.xml - From 5bd80516d400fe5594f735674343c0cefecf7a75 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:08:24 -0600 Subject: [PATCH 31/94] Removed pytest.ini --- pyproject.toml | 2 ++ pytest.ini | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 6dd48dad..5bed2826 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,3 +69,5 @@ exclude_also = [ [tool.pytest.ini_options] minversion = "6.0" junit_logging = "all" +junit_family="xunit2" +filterwarnings="error" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 731f942b..00000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -junit_family=xunit2 -filterwarnings=error From 5549e7645e1aba545b6a1301bebd42a58f5fc145 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:24:14 -0600 Subject: [PATCH 32/94] Moved all requirements to pypyroject.toml --- pyproject.toml | 21 ++++++++++++++++----- requirements/common.txt | 2 -- requirements/dev.txt | 8 -------- 3 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 requirements/common.txt delete mode 100644 requirements/dev.txt diff --git a/pyproject.toml b/pyproject.toml index 5bed2826..534453cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,7 @@ description = "A library for reading, editing, and writing MCNP input files" # gitlab limits the readme to 4,000 chars. readme = "README.md" requires-python = ">=3.8" -maintainers = [ - {name = "Micah Gale", email = "micah.gale@inl.gov"} -] +maintainers = {name="Micah Gale", email="micah.gale@inl.gov"} authors = [ {name = "Micah Gale", email = "micah.gale@inl.gov"}, {name = "Travis Labossiere-Hickman", email = "Travis.LabossiereHickman@inl.gov"}, @@ -30,13 +28,26 @@ classifiers = [ ] dependencies = [ - "numpy", + "numpy>=1.18", "sly==0.5" ] [project.optional-dependencies] -test = ["coverage", "pytest"] +test = ["coverage[toml]>=6.3.2", "pytest"] doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] +format = ["black>23.3.0"] +build = [ + "build", + "setuptool_scm", + "bump2version" +] +develop = [ + "montepy[test]", + "montepy[doc]", + "montepy[format]", + "montepy[build]", +] + [project.urls] Homepage = "https://idaholab.github.io/MontePy/index.html" diff --git a/requirements/common.txt b/requirements/common.txt deleted file mode 100644 index 97e31a82..00000000 --- a/requirements/common.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy >= 1.18 -sly >= 0.5.0 diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index c73727e3..00000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,8 +0,0 @@ --r common.txt -build -sphinx~=4.3 -sphinxcontrib-apidoc -sphinx_rtd_theme -coverage[toml]>=6.3.2 -pytest -black==23.3.0 From 9b3e70e93010feb9a31e30496d71cd7bac053196 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:28:15 -0600 Subject: [PATCH 33/94] Updated actions to not use requirements anymore. --- .github/workflows/deploy.yml | 6 +++--- .github/workflows/main.yml | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e75139c7..9de7ea0c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user -r requirements/dev.txt + - run: pip install montepy[develop] - run: python -m pytest build-pages: @@ -75,7 +75,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install build + - run: python -m pip install montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -96,7 +96,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install build + - run: python -m pip install montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d635a22b..9216a003 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: pip install --upgrade pip build - - run: pip install -r requirements/common.txt + - run: pip install build - run: python -m build --sdist --wheel - run: pip install . - run: pip uninstall -y montepy @@ -25,6 +25,9 @@ jobs: - run: pip install --user dist/*.tar.gz - run: pip install --user montepy[test] - run: pip install --user montepy[doc] + - run: pip install --user montepy[format] + - run: pip install --user montepy[build] + - run: pip install --user montepy[develop] - run: pip freeze - name: Upload build artifacts uses: actions/upload-artifact@v3 @@ -44,7 +47,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - run: pip install --user -r requirements/dev.txt + - run: pip install --user montepy[test] - run: coverage run -m pytest --junitxml=test_report.xml - run: coverage report - run: coverage xml @@ -85,7 +88,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user -r requirements/dev.txt + - run: pip install montepy[format] - run: black --check montepy/ tests/ From a80b73dc04579107168fe11fb5ca251da2a4a86c Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:35:34 -0600 Subject: [PATCH 34/94] Fixed bad maintainers. --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 534453cb..ccf38d32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,9 @@ description = "A library for reading, editing, and writing MCNP input files" # gitlab limits the readme to 4,000 chars. readme = "README.md" requires-python = ">=3.8" -maintainers = {name="Micah Gale", email="micah.gale@inl.gov"} +maintainers = [ + {name = "Micah Gale", email = "micah.gale@inl.gov"} +] authors = [ {name = "Micah Gale", email = "micah.gale@inl.gov"}, {name = "Travis Labossiere-Hickman", email = "Travis.LabossiereHickman@inl.gov"}, From 987350b3557cb6875d0accc633796c64de940684 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:38:20 -0600 Subject: [PATCH 35/94] Relaxed black requirement. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ccf38d32..9725cc3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dependencies = [ [project.optional-dependencies] test = ["coverage[toml]>=6.3.2", "pytest"] doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] -format = ["black>23.3.0"] +format = ["black>=23.3.0"] build = [ "build", "setuptool_scm", From 0bba8209680519bdc66136e2d820d1f836889a5e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 11:44:38 -0600 Subject: [PATCH 36/94] Had pip defer to local for installing. --- .github/workflows/deploy.yml | 8 ++++---- .github/workflows/main.yml | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9de7ea0c..b5321f62 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[develop] + - run: pip install . montepy[develop] - run: python -m pytest build-pages: @@ -30,7 +30,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install --user montepy[doc] + - run: pip install --user . montepy[doc] - run: cd doc && make html - uses: actions/configure-pages@v4 - uses: actions/upload-pages-artifact@v3 @@ -75,7 +75,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install montepy[build] + - run: python -m pip install . montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -96,7 +96,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - run: python -m pip install montepy[build] + - run: python -m pip install . montepy[build] - run: python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9216a003..01283017 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,11 +23,11 @@ jobs: - run: pip install --user dist/*.whl - run: pip uninstall -y montepy - run: pip install --user dist/*.tar.gz - - run: pip install --user montepy[test] - - run: pip install --user montepy[doc] - - run: pip install --user montepy[format] - - run: pip install --user montepy[build] - - run: pip install --user montepy[develop] + - run: pip install --user . montepy[test] + - run: pip install --user . montepy[doc] + - run: pip install --user . montepy[format] + - run: pip install --user . montepy[build] + - run: pip install --user . montepy[develop] - run: pip freeze - name: Upload build artifacts uses: actions/upload-artifact@v3 @@ -47,7 +47,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - run: pip install --user montepy[test] + - run: pip install --user . montepy[test] - run: coverage run -m pytest --junitxml=test_report.xml - run: coverage report - run: coverage xml @@ -71,7 +71,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[doc] + - run: pip install . montepy[doc] - run: sphinx-build doc/source/ doc/build/ -W --keep-going -E - run: sphinx-build -b html doc/source/ doc/build/html - uses: actions/upload-artifact@v3 @@ -88,7 +88,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 - - run: pip install montepy[format] + - run: pip install . montepy[format] - run: black --check montepy/ tests/ From c836d611aa484265e23164f6e1596838b157375c Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:16:05 -0600 Subject: [PATCH 37/94] Correct setuptools-scm dependency --- pyproject.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9725cc3e..20f93952 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] format = ["black>=23.3.0"] build = [ "build", - "setuptool_scm", + "setuptools_scm>=8", "bump2version" ] develop = [ @@ -58,9 +58,12 @@ Documentation = "https://idaholab.github.io/MontePy/index.html" "Bug Tracker" = "https://github.com/idaholab/MontePy/issues" [build-system] -requires = ["setuptools >= 61.0.0"] +requires = ["setuptools >= 64.0.0", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +version_file = "montepy/_version.py" + [tool.setuptools.packages.find] include = ["montepy*"] From 044ae17133da18009e0f0f050cd74493b3bf173c Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:27:54 -0600 Subject: [PATCH 38/94] Ignoring version file from setuptools_scm --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18762426..990257f6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ doc/build/* .coverage .idea/ .ipynb_checkpoints/ +montepy/_version.py From cea94538a58eb651e4e6a4a1330d8968aba7e32a Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 12:53:03 -0600 Subject: [PATCH 39/94] Implemented Coveralls with a lot of trial and error. --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01283017..2d7f1663 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,10 +57,14 @@ jobs: name: test path: test_report.xml - name: Upload coverage report - uses: actions/upload-artifact@v3 + if: ${{ matrix.python-version == '3.9' }} + uses: actions/upload-artifact@v4 with: name: coverage path: coverage.xml + - name: Coveralls GitHub Action + if: ${{ matrix.python-version == '3.9' }} + uses: coverallsapp/github-action@v2.2.3 doc-test: runs-on: ubuntu-latest From fbcc3a785880448653dd57a66378dba18b551e81 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 13:56:48 -0600 Subject: [PATCH 40/94] Ignore _version from coverage. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 20f93952..fe4d871d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,6 +72,7 @@ version = {attr = "montepy.__version__"} [tool.coverage.run] source = ["montepy"] +omit = ["montepy/_version.py"] [tool.coverage.report] precision = 2 From b0cf2df53f189fdecb686295c4ea57b680d2c7ca Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 14:13:57 -0600 Subject: [PATCH 41/94] Limited coveralls to coverage.xml only.P --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d7f1663..ad0deba7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,6 +65,8 @@ jobs: - name: Coveralls GitHub Action if: ${{ matrix.python-version == '3.9' }} uses: coverallsapp/github-action@v2.2.3 + with: + file: coverage.xml doc-test: runs-on: ubuntu-latest From 196ef9b9f2a63c46942ebf2c7e2d44b9aca4f67d Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:28:13 -0600 Subject: [PATCH 42/94] Added basic badges --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8eee6eff..3169d0e8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ MontePY: a cute snek on a red over white circle +[![license](https://img.shields.io/github/license/idaholab/MontePy.svg)](https://github.com/idaholab/MontePy/blob/develop/LICENSE) +[![Coverage Status](https://coveralls.io/repos/github/idaholab/MontePy/badge.svg?branch=develop)](https://coveralls.io/github/idaholab/MontePy?branch=develop) +[![PyPI version](https://badge.fury.io/py/montepy.svg)](https://badge.fury.io/py/montepy) + A python library to read, edit, and write MCNP input files. ## Installing From 53af432a0d53123077b0d9b51856f269c5775587 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:34:55 -0600 Subject: [PATCH 43/94] First try with using test reporter. --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad0deba7..af8c30ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,8 @@ jobs: - run: coverage report - run: coverage xml - name: Upload test report - uses: actions/upload-artifact@v3 + if: ${{ matrix.python-version == '3.9' }} + uses: actions/upload-artifact@v4 with: name: test path: test_report.xml @@ -62,6 +63,11 @@ jobs: with: name: coverage path: coverage.xml + - name: Test Reporter + if: ${{ matrix.python-version == '3.9' }} + uses: dorny/test-reporter@v1.7.0 + with: + path: test_report.xml - name: Coveralls GitHub Action if: ${{ matrix.python-version == '3.9' }} uses: coverallsapp/github-action@v2.2.3 From 907c082728f49a0567bdf9909e5125f3632d5dca Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:39:27 -0600 Subject: [PATCH 44/94] Added name to test reporter. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index af8c30ec..fc433ce6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,6 +67,7 @@ jobs: if: ${{ matrix.python-version == '3.9' }} uses: dorny/test-reporter@v1.7.0 with: + name: CI path: test_report.xml - name: Coveralls GitHub Action if: ${{ matrix.python-version == '3.9' }} From e23c441c92aceaf95e8be71bc6f2216e2886abb7 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:41:31 -0600 Subject: [PATCH 45/94] Added reporter to test reporter. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc433ce6..e6740755 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,6 +69,7 @@ jobs: with: name: CI path: test_report.xml + reporter: java-junit - name: Coveralls GitHub Action if: ${{ matrix.python-version == '3.9' }} uses: coverallsapp/github-action@v2.2.3 From 2ec0bcd6aff5f7c83811d557ff3acf33cf5e54cf Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:45:13 -0600 Subject: [PATCH 46/94] Made test names more meaningful. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6740755..268da249 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Test package +name: CI testing on: [push] @@ -67,7 +67,7 @@ jobs: if: ${{ matrix.python-version == '3.9' }} uses: dorny/test-reporter@v1.7.0 with: - name: CI + name: CI-test-report path: test_report.xml reporter: java-junit - name: Coveralls GitHub Action From 165693690685537f542b74e86aebf3a81b4e8911 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 14:55:26 -0600 Subject: [PATCH 47/94] Actually implemented a build and deploy phase --- .github/workflows/deploy.yml | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b5321f62..3742ce1d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,6 +37,22 @@ jobs: with: name: deploy-pages path: doc/build/html/ + + build-packages: + runs-on: ubuntu-latest + needs: [last-minute-test] + steps: + - uses: actions/checkout@v4 + - name: set up python 3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: pip install . montepy[build] + - run: python -m build . + - uses: actions/upload-artifact@v4 + with: + name: build + path: dist/* deploy-pages: permissions: @@ -65,18 +81,16 @@ jobs: environment: name: test-pypi url: https://test.pypi.org/p/montepy # Replace with your PyPI project name - needs: [deploy-pages] + needs: [deploy-pages, build-packages] permissions: contents: read id-token: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/download-artifact@v4 with: - python-version: 3.8 - - run: python -m pip install . montepy[build] - - run: python -m build --sdist --wheel + name: build + - uses: actions/setup-python@v4 - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: @@ -86,18 +100,15 @@ jobs: environment: name: pypi url: https://pypi.org/p/montepy # Replace with your PyPI project name - needs: [deploy-pages, deploy-test-pypi] + needs: [deploy-pages, deploy-test-pypi, build-packages] permissions: contents: read id-token: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/download-artifact@v4 with: - python-version: 3.8 - - run: python -m pip install . montepy[build] - - run: python -m build --sdist --wheel + name: build - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From be49ab7b63ae0a8ad6d5b00b16fdb7a4191b69d3 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 15:04:52 -0600 Subject: [PATCH 48/94] Cleaned up pypi deploy --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3742ce1d..698c8e46 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,7 +40,6 @@ jobs: build-packages: runs-on: ubuntu-latest - needs: [last-minute-test] steps: - uses: actions/checkout@v4 - name: set up python 3.8 @@ -90,7 +89,6 @@ jobs: - uses: actions/download-artifact@v4 with: name: build - - uses: actions/setup-python@v4 - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From 1d0136a3ff013773553a43d0262f8a83c1b960ee Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 15:28:05 -0600 Subject: [PATCH 49/94] Switched version system fully over to Setuptools-scm --- montepy/__init__.py | 10 +++++++++- pyproject.toml | 3 --- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/montepy/__init__.py b/montepy/__init__.py index ac195ceb..eae7e6a8 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -23,7 +23,15 @@ from montepy.universe import Universe import sys -__version__ = "0.2.5" +try: + from . import _version + __version__ = _version.version +except ImportError: + try: + from setuptools_scm import get_version + __version__ = get_version() + except ImportError: + __version__ = "Undefined" # enable deprecated warnings for users if not sys.warnoptions: diff --git a/pyproject.toml b/pyproject.toml index fe4d871d..cebc4ff0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,9 +67,6 @@ version_file = "montepy/_version.py" [tool.setuptools.packages.find] include = ["montepy*"] -[tool.setuptools.dynamic] -version = {attr = "montepy.__version__"} - [tool.coverage.run] source = ["montepy"] omit = ["montepy/_version.py"] From 0823e031e4333beb5291419f9d1691067c977398 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 15:28:31 -0600 Subject: [PATCH 50/94] Made a version command line argument. --- montepy/__main__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/montepy/__main__.py b/montepy/__main__.py index ae39fb05..11680140 100644 --- a/montepy/__main__.py +++ b/montepy/__main__.py @@ -34,6 +34,12 @@ def define_args(args): help="Check the given input file(s) for errors. Accepts globs, and multiple arguments.", metavar="input_file", ) + parser.add_argument( + "-v", + "--version", + action="store_true", + help="Print the version number", + ) args = parser.parse_args(args) return args @@ -59,8 +65,10 @@ def main(): # pragma: no cover The main function """ args = define_args(sys.argv[1:]) - if "check" in args: + if "check" in args and args.check: check_inputs(args.check) + if args.version: + print(montepy.__version__) if __name__ == "__main__": # pragma: no cover From ce33238278e570c27df701bdb2df0b0b7e528478 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sun, 21 Jan 2024 15:33:54 -0600 Subject: [PATCH 51/94] Switched to having GHA automatically change version numbers. --- .github/workflows/deploy.yml | 12 +++++++++++- pyproject.toml | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 698c8e46..b4771070 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ on: push: branches: [main] +env: + RELEASE_LEVEL: patch + jobs: last-minute-test: runs-on: ubuntu-latest @@ -19,7 +22,6 @@ jobs: build-pages: environment: name: github-pages - url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - name: Configure git @@ -40,13 +42,21 @@ jobs: build-packages: runs-on: ubuntu-latest + needs: [last-minute-test] steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: set up python 3.8 uses: actions/setup-python@v4 with: python-version: 3.8 - run: pip install . montepy[build] + - name: GitHub Actions Create Tag + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} - run: python -m build . - uses: actions/upload-artifact@v4 with: diff --git a/pyproject.toml b/pyproject.toml index cebc4ff0..51979030 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ format = ["black>=23.3.0"] build = [ "build", "setuptools_scm>=8", - "bump2version" ] develop = [ "montepy[test]", From b2482ddd5f0ac3ca6070f6ac17329370b9d95a95 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 16:27:05 -0600 Subject: [PATCH 52/94] Made GHA create automatic releases. --- .github/workflows/deploy.yml | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b4771070..252751f2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,8 +41,14 @@ jobs: path: doc/build/html/ build-packages: + name: Build, sign, and release packages on github runs-on: ubuntu-latest needs: [last-minute-test] + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + env: + GH_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v4 with: @@ -54,14 +60,39 @@ jobs: python-version: 3.8 - run: pip install . montepy[build] - name: GitHub Actions Create Tag + id: tag_version uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} + # ensure tags are up to date + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - run: python -m build . + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create a GitHub release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + draft: true + - run: >- + gh release upload + '${{ steps.tag_version.outputs.new_tag }}' dist/** + --repo '${{ github.repository }}' - uses: actions/upload-artifact@v4 with: name: build - path: dist/* + path: | + dist/*.tar.gz + dist/*.whl deploy-pages: permissions: @@ -99,6 +130,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: build + path: dist/ - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: @@ -117,8 +149,10 @@ jobs: - uses: actions/download-artifact@v4 with: name: build + path: dist/ - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + From fc06ee317e398c58a18b5f1f8b28fcaad57627f7 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 21 Jan 2024 20:51:27 -0600 Subject: [PATCH 53/94] Created pull request template Adapted from OpenMC: https://github.com/openmc-dev/openmc/blob/develop/.github/pull_request_template.md --- .github/pull_request_template.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..34bc845b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,21 @@ + + +# Description + +Please include a summary of the change and which issue is fixed if applicable. Please also include relevant motivation and context. + +Fixes # (issue) + +# Checklist + +- [ ] I have performed a self-review of my own code +- [ ] 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 94b30969f76992b2ab470ab7a2136589854a29ec Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 22 Jan 2024 08:21:09 -0600 Subject: [PATCH 54/94] Did hacky lazy encoding. --- montepy/constants.py | 7 +++++++ montepy/input_parser/input_file.py | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/montepy/constants.py b/montepy/constants.py index 60bac6ec..3bf4d8b3 100644 --- a/montepy/constants.py +++ b/montepy/constants.py @@ -40,6 +40,13 @@ How many spaces a tab is expand to. """ +ASCII_CEILING = 127 +""" +The maximum allowed code point allowed by ASCII. + +Source: `Wikipedia `_ +""" + def get_max_line_length(mcnp_version=DEFAULT_VERSION): """ diff --git a/montepy/input_parser/input_file.py b/montepy/input_parser/input_file.py index 461306aa..038ced61 100644 --- a/montepy/input_parser/input_file.py +++ b/montepy/input_parser/input_file.py @@ -1,5 +1,6 @@ # Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved. import itertools as it +from montepy.constants import ASCII_CEILING from montepy.utilities import * @@ -20,6 +21,8 @@ def __init__(self, path, parent_file=None): self._path = path self._parent_file = parent_file self._lineno = 1 + self._replace_with_space = False + self._mode = None self._fh = None @make_prop_pointer("_path") @@ -57,7 +60,7 @@ def lineno(self): """ pass - def open(self, mode, encoding="ascii"): + def open(self, mode, encoding="ascii", replace=False): """ Opens the underlying file, and returns self. @@ -79,6 +82,12 @@ def open(self, mode, encoding="ascii"): :type encoding: str :returns: self """ + if "r" in mode: + if replace: + self._replace_with_space = True + mode = "rb" + encoding = None + self._mode = mode self._fh = open(self.path, mode, encoding=encoding) return self @@ -94,12 +103,23 @@ def __exit__(self, exc_type, exc_val, exc_tb): def __iter__(self): for lineno, line in enumerate(self._fh): self._lineno = lineno + 1 + if self._mode == "rb" and self._replace_with_space: + line = self._clean_line(line) yield line + @staticmethod + def _clean_line(line): + new_line = bytes([code if code < ASCII_CEILING else ord(" ") for code in line]) + line = new_line.decode("ascii") + line = line.replace("\r\n", "\n").replace("\r", "\n") + return line + def read(self, size=-1): """ """ if self._fh: ret = self._fh.read(size) + if self._mode == "rb" and self._replace_with_space: + ret = self._clean_line(ret) self._lineno += ret.count("\n") return ret @@ -107,6 +127,8 @@ def readline(self, size=-1): """ """ if self._fh: ret = self._fh.readline(size) + if self._mode == "rb" and self._replace_with_space: + ret = self._clean_line(ret) self._lineno += ret.count("\n") return ret From ad9be990e482ee26c64bd46bb3b8e61e4a2ccd05 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 22 Jan 2024 10:21:27 -0600 Subject: [PATCH 55/94] Set replace to True default, and propogate through stack. --- montepy/input_parser/input_file.py | 6 ++++-- montepy/input_parser/input_reader.py | 14 ++++---------- montepy/input_parser/input_syntax_reader.py | 15 ++++----------- montepy/mcnp_problem.py | 15 ++++----------- 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/montepy/input_parser/input_file.py b/montepy/input_parser/input_file.py index 038ced61..0ef736ce 100644 --- a/montepy/input_parser/input_file.py +++ b/montepy/input_parser/input_file.py @@ -60,7 +60,7 @@ def lineno(self): """ pass - def open(self, mode, encoding="ascii", replace=False): + def open(self, mode, encoding="ascii", replace=True): """ Opens the underlying file, and returns self. @@ -78,8 +78,10 @@ def open(self, mode, encoding="ascii", replace=False): :param mode: the mode to open the file in :type mode: str - :param encoding: The encoding scheme to use. + :param encoding: The encoding scheme to use. If replace is true, this is ignored, and changed to ASCII :type encoding: str + :param replace: replace all non-ASCII characters with a space (0x20) + :type replace: bool :returns: self """ if "r" in mode: diff --git a/montepy/input_parser/input_reader.py b/montepy/input_parser/input_reader.py index 0be4ae07..400d5e1f 100644 --- a/montepy/input_parser/input_reader.py +++ b/montepy/input_parser/input_reader.py @@ -3,26 +3,20 @@ from montepy.constants import DEFAULT_VERSION -def read_input(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): +def read_input(input_file, mcnp_version=DEFAULT_VERSION, replace=True): """ Reads the specified MCNP Input file. The MCNP version must be a three component tuple e.g., (6, 2, 0) and (5, 1, 60). - .. Note:: - For different encoding schemes see the available list - `here `_. - - CP1252 is commonly referred to as "extended-ASCII". - You may have success with this encoding for working with special characters. :param input_file: the path to the input file to read. :type input_file: str :param mcnp_version: The version of MCNP that the input is intended for. :type mcnp_version: tuple :returns: The MCNP_Problem instance representing this file. - :param encoding: The encoding scheme to use. - :type encoding: str + :param replace: replace all non-ASCII characters with a space (0x20) + :type replace: bool :rtype: MCNP_Problem :raises UnsupportedFeature: If an input format is used that MontePy does not support. :raises MalformedInputError: If an input has a broken syntax. @@ -32,5 +26,5 @@ def read_input(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): """ problem = mcnp_problem.MCNP_Problem(input_file) problem.mcnp_version = mcnp_version - problem.parse_input(encoding=encoding) + problem.parse_input(replace=replace) return problem diff --git a/montepy/input_parser/input_syntax_reader.py b/montepy/input_parser/input_syntax_reader.py index 4c32f098..56c7dd29 100644 --- a/montepy/input_parser/input_syntax_reader.py +++ b/montepy/input_parser/input_syntax_reader.py @@ -15,7 +15,7 @@ reading_queue = [] -def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"): +def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION, replace=True): """ Creates a generator function to return a new MCNP input for every new one that is encountered. @@ -25,26 +25,19 @@ def read_input_syntax(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii" The version must be a three component tuple e.g., (6, 2, 0) and (5, 1, 60). - .. Note:: - For different encoding schemes see the available list - `here `_. - - CP1252 is commonly referred to as "extended-ASCII". - You may have success with this encoding for working with special characters. - :param input_file: the path to the input file to be read :type input_file: MCNP_InputFile :param mcnp_version: The version of MCNP that the input is intended for. :type mcnp_version: tuple - :param encoding: The encoding scheme to use. - :type encoding: str + :param replace: replace all non-ASCII characters with a space (0x20) + :type replace: bool :returns: a generator of MCNP_Object objects :rtype: generator """ global reading_queue reading_queue = deque() - with input_file.open("r", encoding=encoding) as fh: + with input_file.open("r", replace=replace) as fh: yield from read_front_matters(fh, mcnp_version) yield from read_data(fh, mcnp_version) diff --git a/montepy/mcnp_problem.py b/montepy/mcnp_problem.py index 9984a2d6..16b8426e 100644 --- a/montepy/mcnp_problem.py +++ b/montepy/mcnp_problem.py @@ -232,21 +232,14 @@ def transforms(self): """ return self._transforms - def parse_input(self, check_input=False, encoding="ascii"): + def parse_input(self, check_input=False, replace=True): """ Semantically parses the MCNP file provided to the constructor. - .. Note:: - For different encoding schemes see the available list - `here `_. - - CP1252 is commonly referred to as "extended-ASCII". - You may have success with this encoding for working with special characters. - - :param encoding: The encoding scheme to use. - :type encoding: str :param check_input: If true, will try to find all errors with input and collect them as warnings to log. :type check_input: bool + :param replace: replace all non-ASCII characters with a space (0x20) + :type replace: bool """ trailing_comment = None last_obj = None @@ -261,7 +254,7 @@ def parse_input(self, check_input=False, encoding="ascii"): try: for i, input in enumerate( input_syntax_reader.read_input_syntax( - self._input_file, self.mcnp_version, encoding=encoding + self._input_file, self.mcnp_version, replace=replace ) ): self._original_inputs.append(input) From b75fe6598e7eb5dab7e60a2d2f7948128f640382 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 22 Jan 2024 10:21:46 -0600 Subject: [PATCH 56/94] Updated encoding test to using replace system. --- tests/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index 229ab40b..800c4249 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1035,8 +1035,8 @@ def test_expansion_warning_crash(self): def test_alternate_encoding(self): with self.assertRaises(UnicodeDecodeError): problem = montepy.read_input( - os.path.join("tests", "inputs", "bad_encoding.imcnp") + os.path.join("tests", "inputs", "bad_encoding.imcnp"), replace=False ) problem = montepy.read_input( - os.path.join("tests", "inputs", "bad_encoding.imcnp"), encoding="cp1252" + os.path.join("tests", "inputs", "bad_encoding.imcnp"), replace=True ) From 7019777c84d4ae44c32d66aae595d918e9476603 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 14:40:16 -0600 Subject: [PATCH 57/94] Added documentation on how versioning now works. --- doc/source/developing.rst | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/source/developing.rst b/doc/source/developing.rst index c6ec53a2..5d9c2485 100644 --- a/doc/source/developing.rst +++ b/doc/source/developing.rst @@ -77,19 +77,40 @@ Setting up and Typical Development Workflow Deploy Process ^^^^^^^^^^^^^^ -MontePy currently does not use a continuous deploy process. -Rather changes are staged on the ``develop`` branch prior to a release. +MontePy currently does not use a continuous deploy (CD) process. +Changes are staged on the ``develop`` branch prior to a release. Both ``develop`` and ``main`` are protected branches. -``main`` should only be used for releases. +``main`` is only be used for releases. If someone clones ``main`` they will get the most recent official release. Only a select few core-developers are allowed to approve a merge to ``main`` and therefore a new release. -``develop`` should be production quality code that has been approved for release, +``develop`` is for production quality code that has been approved for release, but is waiting on the next release. So all new features and bug fixes must first be merged onto ``develop``. The expectation is that features once merged onto ``develop`` are stable, well tested, well documented, and well-formatted. +Automated Versioning +^^^^^^^^^^^^^^^^^^^^ + +As part of the CD process a new version number is created. +The `GitHub action `_ that does this goes through the following process: + +1. Finds the last release version as git tags. +2. Analyzes all commit messages since then to determine if this is a Major, Minor, or Patch release. +3. Creates a tag with the apropriately incremented new release version. + +This means that git commit messages needs to convey the appropriate level of information. +The library uses `angular's commit message conventions `_. +This convention will not be enforced for all commits, +but will be for all merge commits from Pull Requests. + +Additional References: + +1. `github action `_ +1. `angular's commit message conventions `_ +1. `Semantic versioning standard `_ + Merge Checklist ^^^^^^^^^^^^^^^ From caf2d810eb7b75e79223de94c9d9c93b0f3a91d3 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 14:46:29 -0600 Subject: [PATCH 58/94] Switched run to on pull_request to allow running on fork --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce76eb98..b6257636 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ name: CI testing -on: [push] +on: [pull_request] jobs: build: From 85af4cfa90daaa3bee23057c26ecbc556762d2fe Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 15:43:43 -0600 Subject: [PATCH 59/94] Reformatted code with black. --- montepy/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/montepy/__init__.py b/montepy/__init__.py index eae7e6a8..fdb96396 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -25,10 +25,12 @@ try: from . import _version + __version__ = _version.version except ImportError: try: from setuptools_scm import get_version + __version__ = get_version() except ImportError: __version__ = "Undefined" From 314838fb4e5ccedc434b2da2245ab0101998e759 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 15:55:18 -0600 Subject: [PATCH 60/94] Updated permissions for test reporter. --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b6257636..b79e0d86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,10 @@ name: CI testing on: [pull_request] +permissions: + contents: read + actions: read + checks: write jobs: build: runs-on: ubuntu-latest From 1a3f878a809a7a74031b2702e78ed306391720c1 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 16:02:33 -0600 Subject: [PATCH 61/94] Tried to actually set permissions. --- .github/workflows/main.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b79e0d86..01b6e151 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,10 +2,7 @@ name: CI testing on: [pull_request] -permissions: - contents: read - actions: read - checks: write + jobs: build: runs-on: ubuntu-latest @@ -41,6 +38,10 @@ jobs: test: runs-on: ubuntu-latest + permissions: + contents: read + actions: read + checks: write strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] From f54bec62064c1ec594f859a09cc56f43f44af8c0 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 16:10:21 -0600 Subject: [PATCH 62/94] Tried yolo permissions --- .github/workflows/main.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01b6e151..46913d6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,10 +38,7 @@ jobs: test: runs-on: ubuntu-latest - permissions: - contents: read - actions: read - checks: write + permissions: write-all strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] From b9b9fbac16fa3375e14f5fd3b30ec97d874abe03 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 25 Jan 2024 17:20:41 -0600 Subject: [PATCH 63/94] Revert "Updated permissions for test reporter." This reverts commit 314838fb4e5ccedc434b2da2245ab0101998e759. --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 46913d6b..e7a5f1de 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,6 @@ name: CI testing on: [pull_request] - jobs: build: runs-on: ubuntu-latest From 983087d14b7a71ccb05fd78bedda70ddb0c00e8e Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:16:12 -0600 Subject: [PATCH 64/94] Fixed bad grammar. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3169d0e8..11897449 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ There is also a developer's guide covering the design and approach of MontePy, a * Can parse the following surfaces exactly P(X|Y|Z), C(X|Y|Z), C/(X|Y|Z) (I mean it can do PX, and PY, etc.) * Can read in all other inputs but not understand them * Can write out full MCNP problem even if it doesn't fully understand an input. -* Can write out the MCNP problem verbatim, and try to match +* Can write out the MCNP problem verbatim, and try to match the original user formatting. * Can quickly access cells, surfaces, and materials by their numbers. For example: `cell = problem.cells[105]`. * Can quickly update cell importances. For example `cell.importance.neutron = 2.0`. * Has over 240 test cases right now From 71a98470eca8ede7a73ded3b4ec90d1128e9a091 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:27:30 -0600 Subject: [PATCH 65/94] Added DOI to code. --- doc/source/index.rst | 2 ++ doc/source/publications.rst | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 doc/source/publications.rst diff --git a/doc/source/index.rst b/doc/source/index.rst index be171a76..4a0b1bd4 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -18,6 +18,8 @@ Welcome to MontePy's documentation! api/modules + publications + See Also ======== diff --git a/doc/source/publications.rst b/doc/source/publications.rst new file mode 100644 index 00000000..c8820728 --- /dev/null +++ b/doc/source/publications.rst @@ -0,0 +1,15 @@ +Publications +============ + +Permanent Link to Software +-------------------------- + +* `DOI:10.11578/dc.20240115.1 `_ + + +Journals and Conference Papers +------------------------------ + +Currently we don't have any articles to show here. +If you have an interesting paper that uses MontePy, +open an issue and we may add it here. From 0df59d11e1c17836581d0c37debd8ad4ca3f6c50 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:51:55 -0600 Subject: [PATCH 66/94] Created test script for finding missing documentation. --- doc/source/_test_for_missing_docs.py | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 doc/source/_test_for_missing_docs.py diff --git a/doc/source/_test_for_missing_docs.py b/doc/source/_test_for_missing_docs.py new file mode 100644 index 00000000..0729f2db --- /dev/null +++ b/doc/source/_test_for_missing_docs.py @@ -0,0 +1,33 @@ +import glob +import os +import sys +import warnings + +ignored = {"__pycache__", "_version.py", "__main__.py"} + +base = os.path.join("..", "..") + + +def crawl_path(rel_path): + missing = False + for f in os.listdir(os.path.join(base, rel_path)): + f_name = os.path.join(rel_path, f) + if f in ignored: + continue + if os.path.isdir(os.path.join(base, f_name)): + crawl_path(f_name) + elif os.path.isfile(os.path.join(base, f_name)) and ".py" in f: + if f == "__init__.py": + f_name = os.path.join(rel_path, ".py") + path = f_name.replace("/", ".").replace(".py", ".rst") + if not os.path.exists(os.path.join("api", path)): + missing = True + warnings.warn( + f"Missing sphinx documentation for {os.path.join(rel_path, f)}" + ) + return missing + + +missing = crawl_path("montepy") +if missing: + sys.exit(314) From 7a405933f60fe7feca0adf6fd40023541674b13d Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:53:31 -0600 Subject: [PATCH 67/94] Ran test as part of doc test. --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e7a5f1de..1cfaa0c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,6 +94,8 @@ jobs: with: name: website path: doc/build/html + - run: cd doc/source + - run: python _test_for_missing_docs.py format-test: runs-on: ubuntu-latest From 2400a8af3bf7f1f3e983a674f9557728b8b39cf3 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:58:36 -0600 Subject: [PATCH 68/94] Fixed bug with how __init__ was treated. --- doc/source/_test_for_missing_docs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/_test_for_missing_docs.py b/doc/source/_test_for_missing_docs.py index 0729f2db..05f8925c 100644 --- a/doc/source/_test_for_missing_docs.py +++ b/doc/source/_test_for_missing_docs.py @@ -18,8 +18,9 @@ def crawl_path(rel_path): crawl_path(f_name) elif os.path.isfile(os.path.join(base, f_name)) and ".py" in f: if f == "__init__.py": - f_name = os.path.join(rel_path, ".py") - path = f_name.replace("/", ".").replace(".py", ".rst") + path = f_name.replace("/", ".").replace(".__init__.py", ".rst") + else: + path = f_name.replace("/", ".").replace(".py", ".rst") if not os.path.exists(os.path.join("api", path)): missing = True warnings.warn( From b7428347e5f1e022e7204b75382243001e18e7bb Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 21:59:30 -0600 Subject: [PATCH 69/94] Updated version of black --- montepy/data_inputs/fill.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/montepy/data_inputs/fill.py b/montepy/data_inputs/fill.py index cd18f1fa..82e6d5d6 100644 --- a/montepy/data_inputs/fill.py +++ b/montepy/data_inputs/fill.py @@ -525,9 +525,11 @@ def _value_node_generator(): payload.append(self.universes[i][j][k].number) else: payload = [ - self.universe.number - if self.universe is not None - else self.old_universe_number + ( + self.universe.number + if self.universe is not None + else self.old_universe_number + ) ] try: start_transform = new_vals.index("(") From d694d0e245db35fe7c556d5e8378a44015ffa3b4 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:04:47 -0600 Subject: [PATCH 70/94] Added missing documentation files. --- doc/source/api/montepy.data_inputs.tally.rst | 8 ++++++++ doc/source/api/montepy.data_inputs.tally_multiplier.rst | 8 ++++++++ doc/source/api/montepy.input_parser.input_file.rst | 8 ++++++++ doc/source/api/montepy.input_parser.tally_parser.rst | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 doc/source/api/montepy.data_inputs.tally.rst create mode 100644 doc/source/api/montepy.data_inputs.tally_multiplier.rst create mode 100644 doc/source/api/montepy.input_parser.input_file.rst create mode 100644 doc/source/api/montepy.input_parser.tally_parser.rst diff --git a/doc/source/api/montepy.data_inputs.tally.rst b/doc/source/api/montepy.data_inputs.tally.rst new file mode 100644 index 00000000..dc16f381 --- /dev/null +++ b/doc/source/api/montepy.data_inputs.tally.rst @@ -0,0 +1,8 @@ +montepy.data\_inputs.tally module +================================= + + +.. automodule:: montepy.data_inputs.tally + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/api/montepy.data_inputs.tally_multiplier.rst b/doc/source/api/montepy.data_inputs.tally_multiplier.rst new file mode 100644 index 00000000..f38e1552 --- /dev/null +++ b/doc/source/api/montepy.data_inputs.tally_multiplier.rst @@ -0,0 +1,8 @@ +montepy.data\_inputs.tally_multiplier module +============================================ + + +.. automodule:: montepy.data_inputs.tally_multiplier + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/api/montepy.input_parser.input_file.rst b/doc/source/api/montepy.input_parser.input_file.rst new file mode 100644 index 00000000..6f552e8d --- /dev/null +++ b/doc/source/api/montepy.input_parser.input_file.rst @@ -0,0 +1,8 @@ +montepy.input\_parser.input\_file module +========================================== + + +.. automodule:: montepy.input_parser.input_file + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/api/montepy.input_parser.tally_parser.rst b/doc/source/api/montepy.input_parser.tally_parser.rst new file mode 100644 index 00000000..65756dde --- /dev/null +++ b/doc/source/api/montepy.input_parser.tally_parser.rst @@ -0,0 +1,8 @@ +montepy.input\_parser.tally\_parser module +========================================== + + +.. automodule:: montepy.input_parser.tally\_parser + :members: + :undoc-members: + :show-inheritance: From 80b370a3f701598173679ac97917a09709378a7a Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:05:05 -0600 Subject: [PATCH 71/94] Ignored private file. --- doc/source/_test_for_missing_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/_test_for_missing_docs.py b/doc/source/_test_for_missing_docs.py index 05f8925c..f0dbf9a7 100644 --- a/doc/source/_test_for_missing_docs.py +++ b/doc/source/_test_for_missing_docs.py @@ -3,7 +3,7 @@ import sys import warnings -ignored = {"__pycache__", "_version.py", "__main__.py"} +ignored = {"__pycache__", "_version.py", "__main__.py", "_cell_data_control.py"} base = os.path.join("..", "..") From 4a413aa915ec65e9c7c069e464b3ce1a22381407 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:07:30 -0600 Subject: [PATCH 72/94] Actually added new files to the TOC. --- doc/source/api/montepy.data_inputs.rst | 2 ++ doc/source/api/montepy.input_parser.rst | 2 ++ doc/source/api/montepy.input_parser.tally_parser.rst | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/source/api/montepy.data_inputs.rst b/doc/source/api/montepy.data_inputs.rst index e4248fb2..96bdae1e 100644 --- a/doc/source/api/montepy.data_inputs.rst +++ b/doc/source/api/montepy.data_inputs.rst @@ -26,6 +26,8 @@ Submodules montepy.data_inputs.material_component montepy.data_inputs.mode montepy.data_inputs.thermal_scattering + montepy.data_inputs.tally + montepy.data_inputs.tally_multiplier montepy.data_inputs.transform montepy.data_inputs.universe_input montepy.data_inputs.volume diff --git a/doc/source/api/montepy.input_parser.rst b/doc/source/api/montepy.input_parser.rst index 5ffd32e2..89fa0dc0 100644 --- a/doc/source/api/montepy.input_parser.rst +++ b/doc/source/api/montepy.input_parser.rst @@ -18,11 +18,13 @@ Submodules montepy.input_parser.data_parser montepy.input_parser.input_reader montepy.input_parser.input_syntax_reader + montepy.input_parser.input_file montepy.input_parser.mcnp_input montepy.input_parser.parser_base montepy.input_parser.read_parser montepy.input_parser.shortcuts montepy.input_parser.surface_parser montepy.input_parser.syntax_node + montepy.input_parser.tally_parser montepy.input_parser.thermal_parser montepy.input_parser.tokens diff --git a/doc/source/api/montepy.input_parser.tally_parser.rst b/doc/source/api/montepy.input_parser.tally_parser.rst index 65756dde..eaf525b2 100644 --- a/doc/source/api/montepy.input_parser.tally_parser.rst +++ b/doc/source/api/montepy.input_parser.tally_parser.rst @@ -2,7 +2,7 @@ montepy.input\_parser.tally\_parser module ========================================== -.. automodule:: montepy.input_parser.tally\_parser +.. automodule:: montepy.input_parser.tally_parser :members: :undoc-members: :show-inheritance: From 508f932b73e295c3584b384db8d627cc302ec57e Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:12:00 -0600 Subject: [PATCH 73/94] Tried to get cd to persist --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1cfaa0c8..939c3b93 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,8 +94,8 @@ jobs: with: name: website path: doc/build/html - - run: cd doc/source - - run: python _test_for_missing_docs.py + - run: | cd doc/source + python _test_for_missing_docs.py format-test: runs-on: ubuntu-latest From 04f30d495cf5e413d713d31a553fc75502913043 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:14:08 -0600 Subject: [PATCH 74/94] Fixed syntax. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 939c3b93..bdef0a22 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,7 +94,8 @@ jobs: with: name: website path: doc/build/html - - run: | cd doc/source + - run: | + cd doc/source python _test_for_missing_docs.py format-test: From c9ebe7092f58f36883653a0047abe98c8ca62ada Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 31 Jan 2024 22:16:05 -0600 Subject: [PATCH 75/94] Named missing api test --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bdef0a22..c107a575 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,7 +94,8 @@ jobs: with: name: website path: doc/build/html - - run: | + - name: Test for missing API documentation + run: | cd doc/source python _test_for_missing_docs.py From 108018f20bee4b2815d250932189157b72774965 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Thu, 1 Feb 2024 17:15:55 -0600 Subject: [PATCH 76/94] Get that good SEO. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11897449..860b3edb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coverage Status](https://coveralls.io/repos/github/idaholab/MontePy/badge.svg?branch=develop)](https://coveralls.io/github/idaholab/MontePy?branch=develop) [![PyPI version](https://badge.fury.io/py/montepy.svg)](https://badge.fury.io/py/montepy) -A python library to read, edit, and write MCNP input files. +MontePy is a python library to read, edit, and write MCNP input files. ## Installing From d724f0b6bbd85be0740da809caddd9cd67737129 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sat, 3 Feb 2024 20:29:20 -0600 Subject: [PATCH 77/94] Updated edge test to test #351. --- tests/test_edge_cases.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index 9285e4e7..fabcf147 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -176,3 +176,4 @@ def test_geometry_comments(self): cell = montepy.Cell(input) # this step caused an error for #163 cell.comments + cell._tree.format() From 9efa140bdd77ecf3793f302d526a1aaf82e30d1c Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sat, 3 Feb 2024 21:22:18 -0600 Subject: [PATCH 78/94] Fixed GeometryTree parsers to actually use syntax nodes. --- montepy/input_parser/cell_parser.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/montepy/input_parser/cell_parser.py b/montepy/input_parser/cell_parser.py index 567c9963..8585a649 100644 --- a/montepy/input_parser/cell_parser.py +++ b/montepy/input_parser/cell_parser.py @@ -75,7 +75,7 @@ def union(self, p): def geometry_expr(self, p): left = p.geometry_expr right = p.geometry_term - nodes = {"left": left.nodes, "operator": p.union, "right": right.nodes} + nodes = {"left": left, "operator": p.union, "right": right} return syntax_node.GeometryTree("union", nodes, ":", left, right) @_("geometry_term") @@ -112,7 +112,7 @@ def geometry_term(self, p): for node in node_iter: new_tree = syntax_node.GeometryTree( "intersection", - {"left": left, "operator": None, "right": node}, + {"left": left, "operator": syntax_node.PaddingNode(), "right": node}, "*", left, node, @@ -142,7 +142,10 @@ def geometry_factor(self, p): @_("COMPLEMENT geometry_factory") def geometry_factor(self, p): - nodes = {"operator": p.COMPLEMENT, "left": p.geometry_factory} + nodes = { + "operator": syntax_node.PaddingNode(p.COMPLEMENT), + "left": p.geometry_factory, + } return syntax_node.GeometryTree( "complement", nodes, From b29a57e44243d9b8b6db511af585306d0a82dd77 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sat, 3 Feb 2024 21:23:09 -0600 Subject: [PATCH 79/94] Ensure all nodes are nodes. --- montepy/input_parser/syntax_node.py | 1 + 1 file changed, 1 insertion(+) diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py index b6c1b6d1..0ce727a0 100644 --- a/montepy/input_parser/syntax_node.py +++ b/montepy/input_parser/syntax_node.py @@ -222,6 +222,7 @@ class GeometryTree(SyntaxNodeBase): def __init__(self, name, tokens, op, left, right=None): super().__init__(name) + assert all(list(map(lambda v: isinstance(v, SyntaxNodeBase), tokens.values()))) self._nodes = tokens self._operator = Operator(op) self._left_side = left From 3bcfbeff8aac6fb839597c7c0b15c6e868d5ac83 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sat, 3 Feb 2024 21:25:18 -0600 Subject: [PATCH 80/94] Fixed test to have right type. --- tests/test_geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 32c0a3ff..661e474f 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -10,7 +10,7 @@ class TestHalfSpaceUnit(TestCase): def test_init(self): surface = montepy.surfaces.CylinderOnAxis() - node = montepy.input_parser.syntax_node.GeometryTree("hi", [], "*", " ", " ") + node = montepy.input_parser.syntax_node.GeometryTree("hi", {}, "*", " ", " ") half_space = HalfSpace(+surface, Operator.UNION, -surface, node) self.assertIs(half_space.operator, Operator.UNION) self.assertEqual(half_space.left, +surface) From 4246f30f3f77df162ef7c458dccf563ce9cab403 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Sat, 3 Feb 2024 21:32:59 -0600 Subject: [PATCH 81/94] Revert "Defined recursive GeometryTree Comments function for nested dicts." This reverts commit d0f5f9d7e05d0a7b1233f70efd4307dde331c7ee. -This was a hacky workaround for the real problem that was just solved --- montepy/__init__.py | 2 +- montepy/input_parser/syntax_node.py | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/montepy/__init__.py b/montepy/__init__.py index ac195ceb..52702af7 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -23,7 +23,7 @@ from montepy.universe import Universe import sys -__version__ = "0.2.5" +__version__ = "0.2.6dev1" # enable deprecated warnings for users if not sys.warnoptions: diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py index 0ce727a0..496a7280 100644 --- a/montepy/input_parser/syntax_node.py +++ b/montepy/input_parser/syntax_node.py @@ -242,19 +242,8 @@ def format(self): @property def comments(self): - for key, node in self.nodes.items(): - if isinstance(node, SyntaxNodeBase): - yield from node.comments - elif isinstance(node, dict): - yield from GeometryTree._recurse_comments(node) - - @staticmethod - def _recurse_comments(tree): - for node in tree.values(): - if isinstance(node, SyntaxNodeBase): - yield from node.comments - elif isinstance(node, dict): - yield from GeometryTree._recurse_comments(node) + for node in self.nodes.values(): + yield from node.comments @property def left(self): From f4032f35f8bda6ee8ecac3f9c3bf1d59512e2006 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 3 Feb 2024 23:44:21 -0600 Subject: [PATCH 82/94] Updated test to run after merge for protected branches --- .github/workflows/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c107a575..42bd6d5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,9 @@ name: CI testing -on: [pull_request] +on: + pull_request: + push: + branches: [develop, main, alpha-test] jobs: build: From 8bfe485772e4a087fd9312cb60b9af0322ea79e1 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Tue, 6 Feb 2024 15:22:44 -0600 Subject: [PATCH 83/94] Update bug_report.md to prompt users to do the right thing --- .github/ISSUE_TEMPLATE/bug_report.md | 68 ++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 46c1f24f..125612f4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -6,32 +6,74 @@ labels: bug assignees: '' --- - + **Describe the bug** + A clear and concise description of what the bug is. **To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error -**Expected behavior** -A clear and concise description of what you expected to happen. +A short code snippet of what you have ran. Please change or remove any specific values or anything that can't be public. For example: + +``` python +problem = montepy.read_input("foo.imcnp") +``` + +**Error Message (if any)** + +If an error message was printed please include the entire stacktrace. If it includes any specific values please change or remove them. For example: + +``` python +In [6]: problem.cells.append(copy.deepcopy(cell)) +--------------------------------------------------------------------------- +NumberConflictError Traceback (most recent call last) +Cell In[6], line 1 +----> 1 problem.cells.append(copy.deepcopy(cell)) + +File ~/dev/montepy/montepy/numbered_object_collection.py:202, in NumberedObjectCollection.append(self, obj) + 200 raise TypeError(f"object being appended must be of type: {self._obj_class}") + 201 if obj.number in self.numbers: +--> 202 raise NumberConflictError( + 203 ( + 204 "There was a numbering conflict when attempting to add " + 205 f"{obj} to {type(self)}. Conflict was with {self[obj.number]}" + 206 ) + 207 ) + 208 else: + 209 self.__num_cache[obj.number] = obj -**Screenshots** -If applicable, add screenshots to help explain your problem. +NumberConflictError: There was a numbering conflict when attempting to add CELL: 3, mat: 3, DENS: 1.0 g/cm3 to . Conflict was with CELL: 3, mat: 3, DENS: 1.0 g/cm3 +``` + +**MCNP input file snippet** + +If applicable, please include a small section of the input file you were working on. If it includes any specific values please change or remove them. For example: + +``` +1 1 20 + -1000 $ dollar comment + imp:n,p=1 U=350 trcl=5 + +C surfaces +1000 SO 1 + +C data +C materials +C UO2 5 atpt enriched +m1 92235.80c 5 & +92238.80c 95 +``` + +**Version** -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - Version [e.g. 0.2.5] **Additional context** + Add any other context about the problem here. From ba16e0c9c617abe8c3c2439bfb5a557a128187c9 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 12 Feb 2024 11:00:21 -0600 Subject: [PATCH 84/94] Added # to replicate #363 bug. --- tests/inputs/test.imcnp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/inputs/test.imcnp b/tests/inputs/test.imcnp index 4d9b70e3..fd0d4cbe 100644 --- a/tests/inputs/test.imcnp +++ b/tests/inputs/test.imcnp @@ -4,6 +4,7 @@ foo MCNP Test Model for MOAA C cells +c # hidden vertical Do not touch c 1 1 20 -1000 $ dollar comment From 8970e16766af9e6f9621206559431ae761422fa1 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 12 Feb 2024 11:16:50 -0600 Subject: [PATCH 85/94] fixed vertical mode detector to ignore comments. --- montepy/input_parser/input_syntax_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/input_parser/input_syntax_reader.py b/montepy/input_parser/input_syntax_reader.py index 540164a0..84f483fb 100644 --- a/montepy/input_parser/input_syntax_reader.py +++ b/montepy/input_parser/input_syntax_reader.py @@ -186,7 +186,7 @@ def flush_input(): ): yield from flush_input() # die if it is a vertical syntax format - if "#" in line[0:BLANK_SPACE_CONTINUE]: + if "#" in line[0:BLANK_SPACE_CONTINUE] and not line_is_comment: raise errors.UnsupportedFeature("Vertical Input format is not allowed") # cut line down to allowed length old_line = line From a9021da71cc7c7bd3184f2f0c8feb944a5edf196 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 12 Feb 2024 11:17:08 -0600 Subject: [PATCH 86/94] updated test for added comment. --- tests/test_integration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index a43836b5..7e5164af 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -342,6 +342,7 @@ def test_cell_card_pass_through(self): # test input pass-through answer = [ "C cells", + "c # hidden vertical Do not touch", "c", "1 1 20", " -1000 $ dollar comment", @@ -354,20 +355,20 @@ def test_cell_card_pass_through(self): cell = new_prob.cells[1] output = cell.format_for_mcnp_input((6, 2, 0)) print(output) - self.assertEqual(int(output[3].split("$")[0]), -5) + self.assertEqual(int(output[4].split("$")[0]), -5) # test mass density printer cell.mass_density = 10.0 with self.assertWarns(LineExpansionWarning): output = cell.format_for_mcnp_input((6, 2, 0)) print(output) - self.assertAlmostEqual(float(output[2].split()[2]), -10) + self.assertAlmostEqual(float(output[3].split()[2]), -10) # ensure that surface number updated # Test material number change new_prob = copy.deepcopy(problem) new_prob.materials[1].number = 5 cell = new_prob.cells[1] output = cell.format_for_mcnp_input((6, 2, 0)) - self.assertEqual(int(output[2].split()[1]), 5) + self.assertEqual(int(output[3].split()[1]), 5) def test_thermal_scattering_pass_through(self): problem = copy.deepcopy(self.simple_problem) From d7e7de63a79890ac42b45449ac5ce7d18a8c3b21 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Mon, 5 Feb 2024 16:47:02 -0600 Subject: [PATCH 87/94] Removed unused vars. --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 252751f2..c4fc82f8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,8 +4,6 @@ on: push: branches: [main] -env: - RELEASE_LEVEL: patch jobs: last-minute-test: From 65a463bb6d166a15e7c17d9deaad2ed413fb5c03 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Mon, 5 Feb 2024 16:50:16 -0600 Subject: [PATCH 88/94] Fixed typo with bug reports labels. --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 125612f4..77fd90ba 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,7 +2,7 @@ name: Bug report about: Create a report to help us improve title: '' -labels: bug +labels: bugs assignees: '' --- From 0c5f3e26052ae640e2f0cc8f0d1353df7f7ae7db Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Mon, 5 Feb 2024 16:52:27 -0600 Subject: [PATCH 89/94] Switched to implicit sys.argv. --- montepy/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/montepy/__main__.py b/montepy/__main__.py index 11680140..3fec69c7 100644 --- a/montepy/__main__.py +++ b/montepy/__main__.py @@ -14,7 +14,7 @@ """ -def define_args(args): +def define_args(args=None): """ Sets and parses the command line arguments. @@ -64,7 +64,7 @@ def main(): # pragma: no cover """ The main function """ - args = define_args(sys.argv[1:]) + args = define_args() if "check" in args and args.check: check_inputs(args.check) if args.version: From 0d7fbe611f6372ba0288f005a0804afa8036bf0b Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Mon, 5 Feb 2024 16:53:50 -0600 Subject: [PATCH 90/94] Removed unecessary check. --- montepy/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/__main__.py b/montepy/__main__.py index 3fec69c7..5141ea4b 100644 --- a/montepy/__main__.py +++ b/montepy/__main__.py @@ -65,7 +65,7 @@ def main(): # pragma: no cover The main function """ args = define_args() - if "check" in args and args.check: + if args.check: check_inputs(args.check) if args.version: print(montepy.__version__) From bfbd0c9a52115063b57b5a2c3730f6972eca1eea Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Tue, 13 Feb 2024 17:55:57 -0600 Subject: [PATCH 91/94] Removed dubplicate TOC entry for input_file. --- doc/source/api/montepy.input_parser.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/api/montepy.input_parser.rst b/doc/source/api/montepy.input_parser.rst index abf8a2df..fc837495 100644 --- a/doc/source/api/montepy.input_parser.rst +++ b/doc/source/api/montepy.input_parser.rst @@ -19,7 +19,6 @@ Submodules montepy.input_parser.input_file montepy.input_parser.input_reader montepy.input_parser.input_syntax_reader - montepy.input_parser.input_file montepy.input_parser.mcnp_input montepy.input_parser.parser_base montepy.input_parser.read_parser From c57bcfe23b9308de7aa6b58ee29ab843eb6682b6 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 5 Mar 2024 08:45:07 -0600 Subject: [PATCH 92/94] updated coverage options to make coverall paths work. --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f3a0fe3b..9fab1856 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,8 +70,7 @@ version_file = "montepy/_version.py" include = ["montepy*"] [tool.coverage.run] -source = ["montepy"] -omit = ["montepy/_version.py"] +omit = ["montepy/_version.py","tests/*"] [tool.coverage.report] precision = 2 From c675ff1239cf48cad47381950e2662e181c663ee Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 12 Apr 2024 08:44:33 -0500 Subject: [PATCH 93/94] Updated integration tests to replicate #395. --- tests/test_integration.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_integration.py b/tests/test_integration.py index 7da34589..c4ba5afb 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -138,6 +138,10 @@ def test_write_to_file(self): for i, data in enumerate(self.simple_problem.data_inputs): if isinstance(data, material.Material): self.assertEqual(data.number, test_problem.data_inputs[i].number) + if data.thermal_scattering is not None: + assert ( + test_problem.data_inputs[i].thermal_scattering is not None + ) elif isinstance(data, volume.Volume): self.assertEqual(str(data), str(test_problem.data_inputs[i])) else: From 57f8933593dbc7da1845aeecd3ee2501bb858e94 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 12 Apr 2024 08:58:54 -0500 Subject: [PATCH 94/94] Added method to ensure thermal scattering is written to file. --- montepy/data_inputs/material.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/montepy/data_inputs/material.py b/montepy/data_inputs/material.py index 022c20bc..44516538 100644 --- a/montepy/data_inputs/material.py +++ b/montepy/data_inputs/material.py @@ -116,6 +116,21 @@ def cells(self): if cell.material == self: yield cell + def format_for_mcnp_input(self, mcnp_version): + """ + Creates a string representation of this MCNP_Object that can be + written to file. + + :param mcnp_version: The tuple for the MCNP version that must be exported to. + :type mcnp_version: tuple + :return: a list of strings for the lines that this input will occupy. + :rtype: list + """ + lines = super().format_for_mcnp_input(mcnp_version) + if self.thermal_scattering is not None: + lines += self.thermal_scattering.format_for_mcnp_input(mcnp_version) + return lines + def add_thermal_scattering(self, law): """ Adds thermal scattering law to the material