Repository: CORE-GATECH-GROUP/serpent-tools (python)

Issue:
ENH Support installing with conda
**Is your feature request related to a problem? Please describe.**
Many users are using `conda` as their package manager to install e.g., numpy, scipy, pandas, etc. We should support this, such that users can install with `conda install -c conda-forge serpentTools` (maybe with a different channel?)

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
`pip install` is fine, but then you often need to be managing two package managers: pip and conda, which is not always fun.

**Additional context**

Some (hopefully) useful links
- https://conda-forge.org/
- https://github.com/conda-forge/staged-recipes
- https://github.com/idaholab/moose/tree/next/conda
- https://github.com/conda-forge/openmc-feedstock


Pull request description:
DOC: Add instructions for installing with conda
Closes #494

Make sure you have read over the developer guide to ease
the review process. These include:

- [x] PR fits the [project scope](http://serpent-tools.readthedocs.io/en/latest/develop/contributing.html#project-scope)
- [x] Code to be committed is [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) and matches the [code style](http://serpent-tools.readthedocs.io/en/latest/develop/codestyle.html#code-style) of the project
- [x] New and/or changed features are [well documented](http://serpent-tools.readthedocs.io/en/latest/develop/documentation.html#documentation) and have adequate testing
- [x] For first-time contributors, you have included your attribution in [`docs/contributors.rst`](https://github.com/CORE-GATECH-GROUP/serpent-tools/blob/develop/docs/contributors.rst)


Patch:
diff --git a/README.rst b/README.rst
index 936a9ee..db0ed7f 100644
--- a/README.rst
+++ b/README.rst
@@ -33,6 +33,10 @@ For more detailed instructions, including operating-system specific
 instructions and building from source, see
 `Installation Guide <http://serpent-tools.readthedocs.io/en/latest/install.html>`_.
 
+Alternatively, use ``conda`` with::
+
+  $ conda install -c conda-forge serpentTools
+
 Issues
 ======
 
diff --git a/docs/changelog.rst b/docs/changelog.rst
index ef0dd7f..644db99 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -6,6 +6,13 @@
 Changelog
 =========
 
+.. _v0.11.0:
+
+0.11.0
+======
+
+* Depletion reader settings can be provided at construction - :pull:`516`
+
 .. _v0.10.1:
 
 :release-tag:`0.10.1`
diff --git a/docs/install.rst b/docs/install.rst
index 651287b..aa8c5d9 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -50,6 +50,15 @@ dependency group with::
 
     $ pip install "serpentTools[extras]"
 
+.. _install-conda:
+
+Installing from Conda
+====================
+
+``serpentTools`` can also be installed via :term:`conda` with::
+
+  $ conda install -c conda-forge serpentTools
+
 .. _install-release:
 
 Installing from a Release
diff --git a/src/serpentTools/parsers/depletion.py b/src/serpentTools/parsers/depletion.py
index 18ade58..f30ff96 100644
--- a/src/serpentTools/parsers/depletion.py
+++ b/src/serpentTools/parsers/depletion.py
@@ -147,6 +147,37 @@ class DepletionReader(DepPlotMixin, MaterialReader):
     ----------
     filePath: str
         path to the depletion file
+    materials : list of string, optional
+        Names and patterns to use when determining if a material found
+        in the file should be processed or not. ``["fuel"]`` will
+        result in only the material exactly named ``fuel`` to be processed.
+        But ``["fuel.*"]`` is a pattern that will match and collect any
+        material that begins with ``fuel``. If not provided,
+        pulls from ``depletion.materials`` setting.
+
+        .. versionadded:: 0.11.0
+
+    materialVariables : list of string, optional
+        Names of variables to pull for each processed material. List can
+        contain zero or more entries like ``"ADENS"``, ``"MDENS"``, and
+        ``"INH_TOX"``. If not provided, pulls from
+        ``depletion.materialVariables`` setting.
+
+        .. versionadded:: 0.11.0
+
+    metadataKeys : list of string, optional
+        Metadata fields to pull from the file. List can contain
+        zero or more of the following strings: ``"ZAI"``, ``"NAMES"``,
+        ``"DAYS",`` and ``"BU"`` (case sensitive). If not provided,
+        pulls from ``depletion.metadataKeys`` setting
+
+        .. versionadded:: 0.11.0
+
+    processTotal : bool, optional
+        Flag to process the ``TOTAL`` data section or not. If not given,
+        pulls from the ``depletion.processTotal`` setting.
+
+        .. versionadded:: 0.11.0
 
     Attributes
     ----------
@@ -170,6 +201,7 @@ class DepletionReader(DepPlotMixin, MaterialReader):
         of this reader
 
     """
+
     docAttrs = """materials: dict
         Dictionary with material names as keys and the corresponding
         :py:class:`~serpentTools.objects.materials.DepletedMaterial` class
@@ -178,9 +210,24 @@ class DepletionReader(DepPlotMixin, MaterialReader):
         Dictionary with file-wide data names as keys and the
         corresponding data, e.g. ``'zai'``: [list of zai numbers]"""
 
-    def __init__(self, filePath):
-        MaterialReader.__init__(self, filePath, 'depletion')
-        patterns = self.settings['materials'] or ['.*']
+    def __init__(
+        self,
+        filePath,
+        materials=None,
+        materialVariables=None,
+        metadataKeys=None,
+        processTotal=None,
+    ):
+        MaterialReader.__init__(self, filePath, "depletion")
+        if metadataKeys is not None:
+            self.settings["metadataKeys"] = metadataKeys
+        if materials is not None:
+            self.settings["materials"] = materials
+        if processTotal is not None:
+            self.settings["processTotal"] = processTotal
+        if materialVariables is not None:
+            self.settings["materialVariables"] = materialVariables
+        patterns = self.settings["materials"] or [".*"]
         # match all materials if nothing given
         self._matPatterns = [re.compile(mat) for mat in patterns]
         DepPlotMixin.__init__(self)


Test patch:
diff --git a/tests/test_depletion.py b/tests/test_depletion.py
index 4e2c5d7..de56a25 100644
--- a/tests/test_depletion.py
+++ b/tests/test_depletion.py
@@ -1,11 +1,13 @@
 """Test the depletion file."""
+
 from unittest import TestCase
 from os import remove
+from io import BytesIO
 
 from numpy import array
 from numpy.testing import assert_equal
+import pytest
 
-from io import BytesIO
 from serpentTools.data import getFile
 from serpentTools.settings import rc
 from serpentTools.parsers.depletion import (
@@ -434,3 +436,41 @@ class DepMatlabExportNoConverter(DepMatlabExportHelper):
 
 
 del DepMatlabExportHelper
+
+
+def test_defaultSettings():
+    """Test behavior of settings if no additional arguments given"""
+    r = DepletionReader(DEP_FILE_PATH)
+    assert r.settings["metadataKeys"] == ["ZAI", "NAMES", "DAYS", "BU"]
+    assert r.settings["materials"] == []
+    assert r.settings["processTotal"]
+    assert r.settings["materialVariables"] == []
+
+
+def test_simpleOverloadSettings():
+    """Test overwritting some settings and the behavior"""
+    base = DepletionReader(DEP_FILE_PATH)
+    base.read()
+    alt = DepletionReader(
+        DEP_FILE_PATH,
+        materials=["f.*"],
+        materialVariables=["ADENS", "INH_TOX"],
+        metadataKeys=["ZAI"],
+        processTotal=False,
+    )
+    assert not alt.settings["processTotal"]
+    alt.read()
+    assert set(alt.metadata) == {
+        "zai",
+    }
+    assert alt.zais == base.zais
+    assert set(alt.materials) == {
+        "fuel",
+    }
+    fuel = alt["fuel"]
+    assert set(fuel.data) == {"adens", "inhTox"}
+    assert fuel["adens"] == pytest.approx(base["fuel"]["adens"])
+    assert fuel["inhTox"] == pytest.approx(base["fuel"]["inhTox"])
+    assert alt.days is None
+    assert alt.burnup is None
+    assert alt.names is None