-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to check if a package is installed.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |