-
Notifications
You must be signed in to change notification settings - Fork 160
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
7 changed files
with
93 additions
and
25 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
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,12 +1,12 @@ | ||
-r requirements.txt | ||
|
||
black==23.9.1 # needs to be also updated in .pre-commit-config.yaml | ||
colorlog==6.7.0 | ||
django-debug-toolbar==3.8.1 | ||
black==23.12.1 # needs to be also updated in .pre-commit-config.yaml | ||
colorlog==6.8.0 | ||
django-debug-toolbar==4.2.0 | ||
django-extensions==3.2.3 | ||
Faker==19.6.2 | ||
pre-commit==3.4.0 | ||
Faker==22.2.0 | ||
pre-commit==3.6.0 | ||
PyYAML==6.0.1 | ||
selenium==4.9.1 | ||
Sphinx==7.2.6 | ||
sphinx-rtd-theme==1.3.0 | ||
sphinx-rtd-theme==2.0.0 |
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,6 +1,6 @@ | ||
-r requirements.txt | ||
|
||
gunicorn==20.1.0 | ||
mysqlclient==2.1.1 | ||
sentry-sdk==1.10.1 | ||
ujson==5.4.0 | ||
gunicorn==21.2.0 | ||
mysqlclient==2.2.1 | ||
sentry-sdk==1.39.2 | ||
ujson==5.9.0 |
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,71 @@ | ||
import re | ||
import requests | ||
from packaging import version | ||
from pathlib import Path | ||
|
||
print_red = lambda x: print("\33[91m", x, "\33[0m") | ||
print_green = lambda x: print("\33[92m", x, "\33[0m") | ||
print_yellow = lambda x: print("\33[93m", x, "\33[0m") | ||
|
||
# Regex matching some_weird_package2[full]==4.3.2abcd | ||
regex = re.compile(r"^[a-zA-Z0-9_\-\[\]]+==[a-zA-Z0-9.]+") | ||
|
||
|
||
def check_requirements_versions(requirements_files): | ||
for requirements_file in requirements_files: | ||
requirements_path = Path(requirements_file) | ||
|
||
if not requirements_path.exists(): | ||
print(f"{requirements_path.name} does not exists.") | ||
print() | ||
continue | ||
|
||
with open(requirements_path) as f: | ||
requirements = f.readlines() | ||
|
||
print(f" #### {requirements_path.name}") | ||
print() | ||
print(" Package Version Latest ") | ||
print(" ----------------------------- -------------- ---------------") | ||
|
||
for line in requirements: | ||
match = regex.match(line) | ||
if not match: | ||
continue | ||
|
||
# Extract package and version from regex match (e.g. some_weird_package2[full] and 4.3.2abcd) | ||
# and remove the extras requirements if present (e.g. remove [full] leaving only some_weird_package2) | ||
package, requirements_version = match.group().split("==") | ||
if "[" in package: | ||
package = package[: package.index("[")] | ||
|
||
# Retrieve package info from Pypi and extract latest version | ||
response = requests.get(f"https://pypi.org/pypi/{package}/json") | ||
latest_version = response.json().get("info").get("version") | ||
|
||
# Print with colors: | ||
# - green if versions are exactly equal (no update available) | ||
# - yellow if major versions are equal (minor or patch update available) | ||
# - red otherwise (major update available or another issue) | ||
print_with_colors = print_red | ||
if version.parse(latest_version) == version.parse(requirements_version): | ||
print_with_colors = print_green | ||
elif version.parse(latest_version).major == version.parse(requirements_version).major: | ||
print_with_colors = print_yellow | ||
|
||
print_with_colors(f"{package:30}{requirements_version:15}{latest_version:15}") | ||
|
||
print() | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("requirements_file", nargs="+", help="requirements file") | ||
args = parser.parse_args() | ||
|
||
try: | ||
check_requirements_versions(args.requirements_file) | ||
except KeyboardInterrupt: | ||
pass |