diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0b771d5..05540fe 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -40,6 +40,12 @@ jobs: shell: bash -l {0} run: python -m pytest -v -rs --cov=./ --cov-report=xml + - name: Test hoomd2 functions + shell: bash -l {0} + run: | + mamba install -c conda-forge hoomd=2 + python -m pytest -v -rs -k test_xml_to_gsd --cov=./ --cov-report=xml --cov-append + - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: diff --git a/cmeutils/gsd_utils.py b/cmeutils/gsd_utils.py index c39130d..f53a771 100644 --- a/cmeutils/gsd_utils.py +++ b/cmeutils/gsd_utils.py @@ -2,8 +2,6 @@ import freud import gsd.hoomd -import hoomd -import hoomd.deprecated import numpy as np @@ -202,6 +200,14 @@ def xml_to_gsd(xmlfile, gsdfile): gsdfile : str Path to gsd file """ + try: + import hoomd + import hoomd.deprecated + except ImportError: + raise ImportError( + "You must have hoomd version 2 installed to use xml_to_gsd()" + ) + hoomd.util.quiet_status() hoomd.context.initialize("") hoomd.deprecated.init.read_xml(xmlfile, restart=xmlfile) diff --git a/cmeutils/tests/test_gsd.py b/cmeutils/tests/test_gsd.py index e52225e..ed0e756 100644 --- a/cmeutils/tests/test_gsd.py +++ b/cmeutils/tests/test_gsd.py @@ -2,6 +2,7 @@ import gsd.hoomd import numpy as np +import packaging.version from base_test import BaseTest from cmeutils.gsd_utils import ( @@ -9,6 +10,16 @@ snap_delete_types, xml_to_gsd ) +try: + import hoomd + if "version" in dir(hoomd): + hoomd_version = packaging.version.parse(hoomd.version.version) + else: + hoomd_version = packaging.version.parse(hoomd.__version__) + has_hoomd = True +except ImportError: + has_hoomd = False + class TestGSD(BaseTest): def test_get_type_position(self, gsdfile): @@ -57,6 +68,10 @@ def test_snap_delete_types_bonded(self, snap_bond): new_snap = snap_delete_types(snap_bond, "A") assert "A" not in new_snap.particles.types + @pytest.mark.skipif( + not has_hoomd or hoomd_version.major != 2, + reason="HOOMD is not installed or is wrong version" + ) def test_xml_to_gsd(self, tmp_path, p3ht_gsd, p3ht_xml): new_gsd = tmp_path / "new.gsd" xml_to_gsd(p3ht_xml, new_gsd) diff --git a/environment.yml b/environment.yml index baa0a62..9705015 100644 --- a/environment.yml +++ b/environment.yml @@ -4,7 +4,6 @@ channels: dependencies: - freud - gsd - - hoomd<3 - numpy - pip - python=3.7