-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 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
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
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,26 @@ | ||
from sys import executable | ||
from subprocess import check_call, CalledProcessError | ||
|
||
|
||
def install_package(package, version="upgrade"): | ||
result = False | ||
if version.lower() == "upgrade": | ||
try: | ||
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"]) | ||
except CalledProcessError: | ||
result = check_call([executable, "-m", "pip", "install", package, "--upgrade"]) | ||
else: | ||
from pkg_resources import get_distribution | ||
current_package_version = None | ||
try: | ||
current_package_version = get_distribution(package) | ||
except Exception: | ||
pass | ||
if current_package_version is None or current_package_version != version: | ||
installation_sign = "==" if ">=" not in version else "" | ||
try: | ||
result = check_call( | ||
[executable, "-m", "pip", "install", package + installation_sign + version, "--user"]) | ||
except CalledProcessError: | ||
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version]) | ||
return result |