Skip to content

Commit

Permalink
fix: check for empty string and add pep440 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed May 31, 2024
1 parent 2248839 commit e0d3374
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/mason/providers/client/pypi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ return {
:map_catching(vim.json.decode)
:map(_.path { "info", "requires_python" })
:and_then(function(requires_python)
if type(requires_python) ~= "string" then
if type(requires_python) ~= "string" or requires_python == "" then
return Result.failure "Package does not specify supported Python versions."
else
return Result.success(requires_python)
Expand Down
2 changes: 1 addition & 1 deletion lua/mason/providers/registry-api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return {
.get({ package = pkg, version = version })
:map(_.prop "requires_python")
:and_then(function(requires_python)
if type(requires_python) ~= "string" then
if type(requires_python) ~= "string" or requires_python == "" then
return Result.failure "Package does not specify supported Python versions."
else
return Result.success(requires_python)
Expand Down
22 changes: 22 additions & 0 deletions tests/mason-core/pep440_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local pep440 = require "mason-core.pep440"

describe("pep440 version checking", function()
it("should check single version specifier", function()
assert.is_false(pep440.check_version("3.5.0", ">=3.6"))
assert.is_true(pep440.check_version("3.6.0", ">=3.6"))
assert.is_false(pep440.check_version("3.6.0", ">=3.6.1"))
end)

it("should check version specifier with lower and upper bound", function()
assert.is_true(pep440.check_version("3.8.0", ">=3.8,<3.12"))
assert.is_false(pep440.check_version("3.12.0", ">=3.8,<3.12"))
assert.is_true(pep440.check_version("3.12.0", ">=3.8,<4.0.0"))
end)

it("should check multiple specifiers with different constraints", function()
assert.is_false(pep440.check_version("3.5.0", "!=4.0,<=4.0,>=3.8"))
assert.is_false(pep440.check_version("4.0.0", "!=4.0,<=4.0,>=3.8"))
assert.is_true(pep440.check_version("3.8.1", "!=4.0,<=4.0,>=3.8"))
assert.is_true(pep440.check_version("3.12.0", "!=4.0,<=4.0,>=3.8"))
end)
end)

0 comments on commit e0d3374

Please sign in to comment.