-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pypi): improve resolving suitable python version (#1725)
- Loading branch information
1 parent
0fb4e56
commit 0950b15
Showing
10 changed files
with
300 additions
and
19 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,64 @@ | ||
-- Function to split a version string into its components | ||
local function split_version(version) | ||
local parts = {} | ||
for part in version:gmatch "[^.]+" do | ||
table.insert(parts, tonumber(part) or part) | ||
end | ||
return parts | ||
end | ||
|
||
-- Function to compare two versions | ||
local function compare_versions(version1, version2) | ||
local v1_parts = split_version(version1) | ||
local v2_parts = split_version(version2) | ||
local len = math.max(#v1_parts, #v2_parts) | ||
|
||
for i = 1, len do | ||
local v1_part = v1_parts[i] or 0 | ||
local v2_part = v2_parts[i] or 0 | ||
|
||
if v1_part < v2_part then | ||
return -1 | ||
elseif v1_part > v2_part then | ||
return 1 | ||
end | ||
end | ||
|
||
return 0 | ||
end | ||
|
||
-- Function to check a version against a single specifier | ||
local function check_single_specifier(version, specifier) | ||
local operator, spec_version = specifier:match "^([<>=!]+)%s*(.+)$" | ||
local comp_result = compare_versions(version, spec_version) | ||
|
||
if operator == "==" then | ||
return comp_result == 0 | ||
elseif operator == "!=" then | ||
return comp_result ~= 0 | ||
elseif operator == "<=" then | ||
return comp_result <= 0 | ||
elseif operator == "<" then | ||
return comp_result < 0 | ||
elseif operator == ">=" then | ||
return comp_result >= 0 | ||
elseif operator == ">" then | ||
return comp_result > 0 | ||
else | ||
error("Invalid operator in version specifier: " .. operator) | ||
end | ||
end | ||
|
||
-- Function to check a version against multiple specifiers | ||
local function check_version(version, specifiers) | ||
for specifier in specifiers:gmatch "[^,]+" do | ||
if not check_single_specifier(version, specifier:match "^%s*(.-)%s*$") then | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
return { | ||
check_version = check_version, | ||
} |
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
Oops, something went wrong.