diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..46c1f24f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,37 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Reminders** +1. This is not a place to debug your MCNP models +1. MCNP is export controlled and only its 6.2 and 6.3 user manuals are public. Don't include any information about MCNP which is not in those manuals. +1. Your model may be export controlled, or proprietary. Please change specific numbers (e.g., dimensions, material compositions, etc.) in your minimum working examples. + +**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. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**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. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..32076a73 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'feature request' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. + +**Reminder** +Only the MCNP 6.2 and 6.3 user manuals are public. If this discusses a feature of MCNP you could only know by running MCNP please do not include it. diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..e75139c7 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,105 @@ +name: Deploy + +on: + push: + branches: [main] + +jobs: + last-minute-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: set up python 3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: pip install --user -r requirements/dev.txt + - run: python -m pytest + + build-pages: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Configure git + env: + TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/" + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: pip install --user montepy[doc] + - run: cd doc && make html + - uses: actions/configure-pages@v4 + - uses: actions/upload-pages-artifact@v3 + with: + name: deploy-pages + path: doc/build/html/ + + deploy-pages: + permissions: + contents: read + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: [build-pages, last-minute-test] + runs-on: ubuntu-latest + steps: + - run: ls -l + - uses: actions/download-artifact@v4 + with: + name: deploy-pages + - run: ls -l + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + with: + artifact_name: deploy-pages + + + deploy-test-pypi: + environment: + name: test-pypi + url: https://test.pypi.org/p/montepy # Replace with your PyPI project name + needs: [deploy-pages] + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: python -m pip install build + - run: python -m build --sdist --wheel + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + deploy-pypi: + environment: + name: pypi + url: https://pypi.org/p/montepy # Replace with your PyPI project name + needs: [deploy-pages, deploy-test-pypi] + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: python -m pip install 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 new file mode 100644 index 00000000..d635a22b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,91 @@ +name: Test package + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: set up python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - run: pip install --upgrade pip build + - run: pip install -r requirements/common.txt + - run: python -m build --sdist --wheel + - run: pip install . + - run: pip uninstall -y montepy + - 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 freeze + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + with: + name: build + path: dist/* + + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: set up python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - run: pip install --user -r requirements/dev.txt + - run: coverage run -m pytest --junitxml=test_report.xml + - run: coverage report + - run: coverage xml + - name: Upload test report + uses: actions/upload-artifact@v3 + with: + name: test + path: test_report.xml + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage + path: coverage.xml + + doc-test: + runs-on: ubuntu-latest + + 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[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 + with: + name: website + path: doc/build/html + + format-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: set up python 3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - run: pip install --user -r requirements/dev.txt + - run: black --check montepy/ tests/ + + diff --git a/README.md b/README.md index 74875231..8eee6eff 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,17 @@ # MontePy +MontePY: a cute snek on a red over white circle + A python library to read, edit, and write MCNP input files. ## Installing -See the [Installing section in the user guide](https://experiment_analysis_all.pages.hpc.inl.gov/software/montepy/starting.html#installing). +See the [Installing section in the user guide](https://idaholab.github.io/MontePy/starting.html#installing). ## User Documentation -MontePy has a [sphinx website](https://experiment_analysis_all.pages.hpc.inl.gov/software/montepy/). +MontePy has a [sphinx website](https://idaholab.github.io/MontePy/index.html). This has a getting started guide for users, as well as API documentation. There is also a developer's guide covering the design and approach of MontePy, and how to contribute. @@ -19,9 +21,9 @@ There is also a developer's guide covering the design and approach of MontePy, a * Handles almost all MCNP input syntax including: message blocks, & continue, comments, etc. * Parses Cells, surfaces, materials, and transforms very well. * 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 cards but not understand them -* Can write out full MCNP problem even if it doesn't fully understand a card. -* Can write out the MCNP problem verbatim, if it has not been modified at all. +* 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 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 @@ -56,7 +58,7 @@ So MontePy doesn't do what you want? Right now development is done with a Just- If there's a feature you want add an issue here with the feature request tag. If you want to add a feature on your own talk to Micah Gale (but still add the issue). The system is very modular and you should be able to develop it pretty quickly. -Also read the [developer's guide](https://experiment_analysis_all.pages.hpc.inl.gov/software/montepy/developing.html). +Also read the [developer's guide](https://idaholab.github.io/MontePy/developing.html). # Version Numbering Scheme @@ -70,4 +72,4 @@ Also read the [developer's guide](https://experiment_analysis_all.pages.hpc.inl. Official shall not change. New merges to main shall have a version number incremented. -# Finally: make objects not regexs! +# Finally: make objects not regexes! diff --git a/doc/source/conf.py b/doc/source/conf.py index 921d2d98..7ba3c42c 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -21,8 +21,8 @@ # -- Project information ----------------------------------------------------- project = "MontePy" -copyright = "2021 – 2023, Battelle Energy Alliance LLC." -author = "Micah D. Gale (@galemica), Travis J. Labossiere-Hickman (@tjlaboss)" +copyright = "2021 – 2024, Battelle Energy Alliance LLC." +author = "Micah D. Gale (@micahgale), Travis J. Labossiere-Hickman (@tjlaboss)" release = importlib.metadata.version("montepy") diff --git a/doc/source/developing.rst b/doc/source/developing.rst index 4bf70d34..c6ec53a2 100644 --- a/doc/source/developing.rst +++ b/doc/source/developing.rst @@ -322,7 +322,7 @@ How to __str__ vs __repr__ """""""""""""""""""""""""" All objects must implement ``__str__`` (called by ``str()``), and ``__repr__`` (called by ``repr()``). -See `this issue `_ for a more detailed discussion. +See `this issue `_ for a more detailed discussion. In general ``__str__`` should return a one line string with enough information to uniquely identify the object. For numbered objects this should include their number, and a few high level details. For ``__repr__`` this should include debugging information. diff --git a/doc/source/index.rst b/doc/source/index.rst index 4f7d4e9c..be171a76 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -22,7 +22,7 @@ See Also ======== * `MontePy github Repository `_ -* `MCNP 6.2 User Manual `_ +* `MCNP 6.2 User Manual `_ * `MCNP 6.3 User Manual `_ Indices and tables diff --git a/montepy/__init__.py b/montepy/__init__.py index 40fed7d2..ac195ceb 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -23,7 +23,8 @@ from montepy.universe import Universe import sys -__version__ = "0.2.4" +__version__ = "0.2.5" + # enable deprecated warnings for users if not sys.warnoptions: import os, warnings diff --git a/montepy/errors.py b/montepy/errors.py index a61b73b3..f0c2464d 100644 --- a/montepy/errors.py +++ b/montepy/errors.py @@ -10,8 +10,7 @@ def __init__(self, message): class MalformedInputError(ValueError): """ - <<<<<<< HEAD - Raised when there is an error with the MCNP input not related to the parser. + Raised when there is an error with the MCNP input not related to the parser. """ def __init__(self, input, message): diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py index ff301500..b6c1b6d1 100644 --- a/montepy/input_parser/syntax_node.py +++ b/montepy/input_parser/syntax_node.py @@ -241,8 +241,19 @@ def format(self): @property def comments(self): - for node in self.nodes.values(): - yield from node.comments + 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) @property def left(self): diff --git a/pyproject.toml b/pyproject.toml index 3c01b772..6dd48dad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,14 +14,14 @@ authors = [ {name = "Travis Labossiere-Hickman", email = "Travis.LabossiereHickman@inl.gov"}, {name = "Brenna Carbno"} ] -keywords = ["MCNP", "neutronics", "imcnp", "input file", "monte carlo"] +keywords = ["MCNP", "neutronics", "imcnp", "input file", "monte carlo", "radiation transport"] license = {file="LICENSE"} classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python :: 3 :: Only", "Intended Audience :: Science/Research", "Intended Audience :: Developers", -# "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Topic :: Scientific/Engineering :: Physics", @@ -39,8 +39,10 @@ test = ["coverage", "pytest"] doc = ["sphinx", "sphinxcontrib-apidoc", "sphinx_rtd_theme"] [project.urls] -Homepage = "https://github.com/idaholab/montepy" +Homepage = "https://idaholab.github.io/MontePy/index.html" Repository = "https://github.com/idaholab/montepy.git" +Documentation = "https://idaholab.github.io/MontePy/index.html" +"Bug Tracker" = "https://github.com/idaholab/MontePy/issues" [build-system] requires = ["setuptools >= 61.0.0"] diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index ba4c6609..9285e4e7 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -160,3 +160,19 @@ def test_void_cell_set_material(self): print(output) parts = output[0].split() self.assertAlmostEqual(float(parts[2]), -dens_value, places=9) + + def test_geometry_comments(self): + in_strs = """21073 130 0.010000 (-11516 97 -401 ) $ C 1 Lower water + :(-11526 97 -401 ) $ C 2 Lower water + :(-11536 97 -401 ) $ C 3 Lower water + :(-11546 97 -401 ) $ C 4 Lower water + :(-11556 97 -401 ) $ C 5 Lower water + :(-11576 97 -401 ) imp:n=1 $ C 7 Lower water""".split( + "\n" + ) + input = montepy.input_parser.mcnp_input.Input( + in_strs, montepy.input_parser.block_type.BlockType.CELL + ) + cell = montepy.Cell(input) + # this step caused an error for #163 + cell.comments