-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check and update requirements automatically (#145)
* check and update requirements automatically * remove depency numpy
- Loading branch information
1 parent
0014802
commit 016c1e1
Showing
2 changed files
with
45 additions
and
1 deletion.
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,45 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from importlib.metadata import distributions | ||
|
||
from packaging.requirements import Requirement | ||
from packaging.version import Version | ||
|
||
|
||
def install_dependencies(): | ||
current_path = os.path.abspath(os.path.dirname(__file__)) | ||
with open(os.path.join(current_path, "requirements.txt")) as f: | ||
required_packages = [ | ||
line.strip() | ||
for line in f.readlines() | ||
if line.strip() and not line.strip().startswith("#") | ||
] | ||
|
||
installed_packages = { | ||
dist.metadata["Name"]: Version(dist.version) for dist in distributions() | ||
} | ||
|
||
for package in required_packages: | ||
try: | ||
requirement = Requirement(package) | ||
installed_version = installed_packages.get(requirement.name) | ||
if not installed_version or not requirement.specifier.contains( | ||
installed_version | ||
): | ||
try: | ||
print(f"\033[92m[BizyAir]\033[0m Try to install depency {package}") | ||
subprocess.check_call( | ||
[sys.executable, "-m", "pip", "install", package] | ||
) | ||
except subprocess.CalledProcessError as e: | ||
print(f"\033[91m[BizyAir]\033[0m Failed to install {package}: {e}") | ||
continue | ||
except Exception as e: | ||
print( | ||
f"\033[91m[BizyAir]\033[0m Failed to parse requirement {package}: {e}" | ||
) | ||
continue | ||
|
||
|
||
install_dependencies() |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
numpy<2.0 | ||
oss2 | ||
crcmod | ||
requests | ||
|