Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix semver version check for requests #657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion linkcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
Main function module for link checking.
"""

# Returns True if found > minimum where each is a semver string of numeric tokens:
# 0.10.0 >= 0.9.0 <== True
# 10.1.3 >= 10.1.3 <== True
# 10.1.3 >= 10.1 <== True
# 10.1.0 >= 10.1 <== True
# 10.1 >= 10.1.3 <== False
def semver_gte(found, minimum):
min_tokens = minimum.split(".")
found_tokens = found.split(".")
while len(found_tokens) < len(min_tokens):
found_tokens.append('0')
for min_token, found_token in zip(min_tokens, found_tokens):
if int(found_token) < int(min_token):
return False;
return True;

# version checks
import sys
# Needs Python >= 2.7 because we use dictionary based logging config
Expand All @@ -26,7 +42,7 @@
sys.version_info < (2, 7, 2, 'final', 0)):
raise SystemExit("This program requires Python 2.7.2 or later.")
import requests
if requests.__version__ < '2.2.0':
if not semver_gte(requests.__version__, '2.2.0'):
raise SystemExit("This program requires Python requests 2.2.0 or later.")

import os
Expand Down