diff --git a/src/biocutils/package_utils.py b/src/biocutils/package_utils.py new file mode 100644 index 0000000..e6e4b3a --- /dev/null +++ b/src/biocutils/package_utils.py @@ -0,0 +1,22 @@ +__author__ = "jkanche" +__copyright__ = "jkanche" +__license__ = "MIT" + + +def is_package_installed(package_name: str) -> bool: + """Check if the package is installed. + + Args: + package_name (str): Package name. + + Returns: + bool: True if package is installed, otherwise False. + """ + _installed = False + try: + exec(f"import {package_name}") + _installed = True + except Exception: + pass + + return _installed diff --git a/tests/test_utils.py b/tests/test_list_type_checks.py similarity index 100% rename from tests/test_utils.py rename to tests/test_list_type_checks.py diff --git a/tests/test_package_utils.py b/tests/test_package_utils.py new file mode 100644 index 0000000..5373269 --- /dev/null +++ b/tests/test_package_utils.py @@ -0,0 +1,22 @@ +from biocutils.package_utils import is_package_installed + +__author__ = "jkanche" +__copyright__ = "jkanche" +__license__ = "MIT" + + +def test_for_pandas(): + pkg = is_package_installed("pandas") + + assert pkg is False + + +def test_for_scipy(): + pkg = is_package_installed("scipy") + + assert pkg is False + +def test_for_numpy(): + pkg = is_package_installed("numpy") + + assert pkg is True \ No newline at end of file