From 0a8dfb73dacdcd4f1c14d64213e95a513e04bbc6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 5 Oct 2022 20:14:10 -0400 Subject: [PATCH] make lammps_config_has_package() accessible in Python module --- python/lammps/core.py | 16 ++++++++++++++++ unittest/python/python-capabilities.py | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index 074e579d13..3d0dc21e80 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -265,6 +265,7 @@ class lammps(object): self.lib.lammps_encode_image_flags.restype = self.c_imageint + self.lib.lammps_config_has_package.argtypes = [c_char_p] self.lib.lammps_config_package_name.argtypes = [c_int, c_char_p, c_int] self.lib.lammps_config_accelerator.argtypes = [c_char_p, c_char_p, c_char_p] @@ -1627,6 +1628,21 @@ class lammps(object): # ------------------------------------------------------------------------- + def has_package(self, name): + """ Report if the named package has been enabled in the LAMMPS shared library. + + This is a wrapper around the :cpp:func:`lammps_config_has_package` + function of the library interface. + + :param name: name of the package + :type name: string + + :return: state of package availability + :rtype: bool + """ + return self.lib.lammps_config_has_package(name.encode()) != 0 + # ------------------------------------------------------------------------- + @property def accelerator_config(self): """ Return table with available accelerator configuration settings. diff --git a/unittest/python/python-capabilities.py b/unittest/python/python-capabilities.py index 3ac66ebdc6..be38a9f090 100644 --- a/unittest/python/python-capabilities.py +++ b/unittest/python/python-capabilities.py @@ -60,6 +60,13 @@ class PythonCapabilities(unittest.TestCase): for pkg in selected_packages: self.assertIn(pkg, installed_packages) + def test_has_package(self): + selected_packages = [key[4:] for key in self.cmake_cache.keys() if not key.startswith('PKG_CONFIG') and key.startswith('PKG_') and self.cmake_cache[key]] + self.assertFalse(self.lmp.has_package('XXXXXX')) + + for pkg in selected_packages: + self.assertTrue(self.lmp.has_package(pkg)) + def test_has_style(self): self.assertTrue(self.lmp.has_style('pair', 'lj/cut')) self.assertFalse(self.lmp.has_style('pair', 'lennard_jones'))