Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into BlueDrink9/main
Browse files Browse the repository at this point in the history
* origin/main:
  tests: remove old spec (williamboman#1634)
  chore(main): release 1.10.0 (williamboman#1605)
  fix(pypi): fix variable shadowing (williamboman#1610)
  feat(pypi): attempt more python3 candidates (williamboman#1608)
  fix(golang): fix fetching package versions for packages containing subpath specifier (williamboman#1607)
  feat: don't use vim.g.python3_host_prog as a candidate for python (williamboman#1606)
  fix(ui): don't indent empty lines (williamboman#1597)
  • Loading branch information
williamboman committed Mar 21, 2024
2 parents 6e35cbd + 3b5068f commit e0894c9
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 162 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.10.0](https://github.com/williamboman/mason.nvim/compare/v1.9.0...v1.10.0) (2024-01-29)


### Features

* don't use vim.g.python3_host_prog as a candidate for python ([#1606](https://github.com/williamboman/mason.nvim/issues/1606)) ([bce96d2](https://github.com/williamboman/mason.nvim/commit/bce96d2fd483e71826728c6f9ac721fc9dd7d2cf))
* **pypi:** attempt more python3 candidates ([#1608](https://github.com/williamboman/mason.nvim/issues/1608)) ([dcd0ea3](https://github.com/williamboman/mason.nvim/commit/dcd0ea30ccfc7d47e879878d1270d6847a519181))


### Bug Fixes

* **golang:** fix fetching package versions for packages containing subpath specifier ([#1607](https://github.com/williamboman/mason.nvim/issues/1607)) ([9c94168](https://github.com/williamboman/mason.nvim/commit/9c9416817c9f4e6f333c749327a1ed5355cfab61))
* **pypi:** fix variable shadowing ([#1610](https://github.com/williamboman/mason.nvim/issues/1610)) ([aa550fb](https://github.com/williamboman/mason.nvim/commit/aa550fb0649643eee89d5e64c67f81916e88a736))
* **ui:** don't indent empty lines ([#1597](https://github.com/williamboman/mason.nvim/issues/1597)) ([c7e6705](https://github.com/williamboman/mason.nvim/commit/c7e67059bb8ce7e126263471645c531d961b5e1d))

## [1.9.0](https://github.com/williamboman/mason.nvim/compare/v1.8.3...v1.9.0) (2024-01-06)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<code>:help mason.nvim</code>
</p>
<p align="center">
<sup>Latest version: v1.9.0</sup> <!-- x-release-please-version -->
<sup>Latest version: v1.10.0</sup> <!-- x-release-please-version -->
</p>

# Table of Contents
Expand Down
79 changes: 61 additions & 18 deletions lua/mason-core/installer/managers/pypi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,73 @@ local installer = require "mason-core.installer"
local log = require "mason-core.log"
local path = require "mason-core.path"
local platform = require "mason-core.platform"
local semver = require "mason-core.semver"
local spawn = require "mason-core.spawn"

local M = {}

local VENV_DIR = "venv"

local is_executable = _.compose(_.equals(1), vim.fn.executable)

---@async
---@param py_executables string[]
local function create_venv(py_executables)
---@param candidates string[]
local function resolve_python3(candidates)
a.scheduler()
local available_candidates = _.filter(is_executable, candidates)
for __, candidate in ipairs(available_candidates) do
---@type string
local version_output = spawn[candidate]({ "--version" }):map(_.prop "stdout"):get_or_else ""
local ok, version = pcall(semver.new, version_output:match "Python (3%.%d+.%d+)")
if ok then
return { executable = candidate, version = version }
end
end
return nil
end

---@param min_version? Semver
local function get_versioned_candidates(min_version)
return _.filter_map(function(pair)
local version, executable = unpack(pair)
if not min_version or version > min_version then
return Optional.of(executable)
else
return Optional.empty()
end
end, {
{ semver.new "3.12.0", "python3.12" },
{ semver.new "3.11.0", "python3.11" },
{ semver.new "3.10.0", "python3.10" },
{ semver.new "3.9.0", "python3.9" },
{ semver.new "3.8.0", "python3.8" },
{ semver.new "3.7.0", "python3.7" },
{ semver.new "3.6.0", "python3.6" },
})
end

---@async
local function create_venv()
local stock_candidates = platform.is.win and { "python", "python3" } or { "python3", "python" }
local stock_target = resolve_python3(stock_candidates)
if stock_target then
log.fmt_debug("Resolved stock python3 installation version %s", stock_target.version)
end
local versioned_candidates = get_versioned_candidates(stock_target and stock_target.version)
log.debug("Resolving versioned python3 candidates", versioned_candidates)
local target = resolve_python3(versioned_candidates) or stock_target
local ctx = installer.context()
return Optional.of_nilable(_.find_first(function(executable)
return ctx.spawn[executable]({ "-m", "venv", "--system-site-packages", VENV_DIR }):is_success()
end, py_executables)):ok_or "Failed to create python3 virtual environment."
if not target then
ctx.stdio_sink.stderr(
("Unable to find python3 installation. Tried the following candidates: %s.\n"):format(
_.join(", ", _.concat(stock_candidates, versioned_candidates))
)
)
return Result.failure "Failed to find python3 installation."
end
log.fmt_debug("Found python3 installation version=%s, executable=%s", target.version, target.executable)
ctx.stdio_sink.stdout "Creating virtual environment…\n"
return ctx.spawn[target.executable] { "-m", "venv", "--system-site-packages", VENV_DIR }
end

---@param ctx InstallContext
Expand Down Expand Up @@ -71,21 +126,9 @@ function M.init(opts)
log.fmt_debug("pypi: init", opts)
local ctx = installer.context()

a.scheduler()

local executables = platform.is.win
and _.list_not_nil(
vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog),
"python",
"python3"
)
or _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python3", "python")

-- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path.
ctx:promote_cwd()

ctx.stdio_sink.stdout "Creating virtual environment…\n"
try(create_venv(executables))
try(create_venv())

if opts.upgrade_pip then
ctx.stdio_sink.stdout "Upgrading pip inside the virtual environment…\n"
Expand Down
2 changes: 1 addition & 1 deletion lua/mason-core/installer/registry/providers/golang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
---@async
---@param purl Purl
function M.get_versions(purl)
return providers.golang.get_all_versions(get_package_name(purl))
return providers.golang.get_all_versions(("%s/%s"):format(purl.namespace, purl.name))
end

return M
4 changes: 1 addition & 3 deletions lua/mason-core/managers/pip3/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ function M.install(packages)

a.scheduler()

local executables = platform.is.win
and _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python", "python3")
or _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python3", "python")
local executables = platform.is.win and { "python", "python3" } or { "python3", "python" }

-- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path.
ctx:promote_cwd()
Expand Down
19 changes: 10 additions & 9 deletions lua/mason-core/ui/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ local function render_node(viewport_context, node, _render_context, _output)
end
end

local active_styles = get_styles(full_line, render_context)

-- apply indentation
full_line = (" "):rep(active_styles.indentation) .. full_line
for j = 1, #line_highlights do
local highlight = line_highlights[j]
highlight.col_start = highlight.col_start + active_styles.indentation
highlight.col_end = highlight.col_end + active_styles.indentation
output.highlights[#output.highlights + 1] = highlight
-- only apply cascading styles to non-empty lines
if string.len(full_line) > 0 then
local active_styles = get_styles(full_line, render_context)
full_line = (" "):rep(active_styles.indentation) .. full_line
for j = 1, #line_highlights do
local highlight = line_highlights[j]
highlight.col_start = highlight.col_start + active_styles.indentation
highlight.col_end = highlight.col_end + active_styles.indentation
output.highlights[#output.highlights + 1] = highlight
end
end

output.lines[#output.lines + 1] = full_line
Expand Down
18 changes: 0 additions & 18 deletions lua/mason/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,6 @@ local function check_languages()
}
end
end,
function()
a.scheduler()
if vim.g.python3_host_prog then
check {
cmd = vim.fn.expand(vim.g.python3_host_prog),
args = { "--version" },
name = "python3_host_prog",
relaxed = true,
}
a.scheduler()
check {
cmd = vim.fn.expand(vim.g.python3_host_prog),
args = { "-m", "pip", "--version" },
name = "python3_host_prog pip",
relaxed = true,
}
end
end,
}
end

Expand Down
4 changes: 2 additions & 2 deletions lua/mason/version.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local M = {}

M.VERSION = "v1.9.0" -- x-release-please-version
M.VERSION = "v1.10.0" -- x-release-please-version
M.MAJOR_VERSION = 1 -- x-release-please-major
M.MINOR_VERSION = 9 -- x-release-please-minor
M.MINOR_VERSION = 10 -- x-release-please-minor
M.PATCH_VERSION = 0 -- x-release-please-patch

return M
70 changes: 0 additions & 70 deletions tests/mason-core/installer/managers/build_spec.lua

This file was deleted.

7 changes: 7 additions & 0 deletions tests/mason-core/installer/managers/pypi_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local Result = require "mason-core.result"
local installer = require "mason-core.installer"
local match = require "luassert.match"
local path = require "mason-core.path"
local pypi = require "mason-core.installer.managers.pypi"
local spawn = require "mason-core.spawn"
local spy = require "luassert.spy"
local stub = require "luassert.stub"

Expand All @@ -16,6 +18,11 @@ local function venv_py(ctx)
end

describe("pypi manager", function()
before_each(function()
stub(spawn, "python3", mockx.returns(Result.success()))
spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.12.0" })
end)

it("should init venv without upgrading pip", function()
local ctx = create_dummy_context()
stub(ctx, "promote_cwd")
Expand Down
40 changes: 0 additions & 40 deletions tests/mason-core/managers/pip3_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,61 +63,21 @@ describe("pip3 manager", function()
it(
"should exhaust python3 executable candidates if all fail",
async_test(function()
vim.g.python3_host_prog = "/my/python3"
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
ctx.spawn.python3 = spy.new(mockx.throws())
ctx.spawn.python = spy.new(mockx.throws())
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.throws())
local err = assert.has_error(function()
installer.prepare_installer(ctx):get_or_throw()
installer.exec_in_context(ctx, pip3.packages { "package" })
end)
vim.g.python3_host_prog = nil

assert.equals("Unable to create python3 venv environment.", err)
assert.spy(ctx.spawn["/my/python3"]).was_called(1)
assert.spy(ctx.spawn.python3).was_called(1)
assert.spy(ctx.spawn.python).was_called(1)
end)
)

it(
"should not exhaust python3 executable if one succeeds",
async_test(function()
vim.g.python3_host_prog = "/my/python3"
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
ctx.spawn.python3 = spy.new(mockx.throws())
ctx.spawn.python = spy.new(mockx.returns {})
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.returns {})

installer.prepare_installer(ctx):get_or_throw()
installer.exec_in_context(ctx, pip3.packages { "package" })
vim.g.python3_host_prog = nil
assert.spy(ctx.spawn.python3).was_called(0)
assert.spy(ctx.spawn.python).was_called(1)
assert.spy(ctx.spawn["/my/python3"]).was_called(1)
end)
)

it(
"should expand python3_host_prog path",
async_test(function()
vim.g.python3_host_prog = "~/python3"
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
ctx.spawn.python = spy.new(mockx.returns {})
ctx.spawn[vim.env.HOME .. "/python3"] = spy.new(mockx.returns {})

installer.prepare_installer(ctx):get_or_throw()
installer.exec_in_context(ctx, pip3.packages { "package" })
a.scheduler()
vim.g.python3_host_prog = nil
assert.spy(ctx.spawn[vim.env.HOME .. "/python3"]).was_called(1)
end)
)

it(
"should use install_args from settings",
async_test(function()
Expand Down
20 changes: 20 additions & 0 deletions tests/mason-core/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,24 @@ describe("integration test", function()
)
end)
)

it("should not apply cascading styles to empty lines", function()
local render_output = display._render_node(
{
win_width = 120,
},
Ui.CascadingStyleNode({ "INDENT" }, {
Ui.HlTextNode {
{
{ "Hello World!", "MyHighlightGroup" },
},
{
{ "", "" },
},
},
})
)

assert.same({ " Hello World!", "" }, render_output.lines)
end)
end)

0 comments on commit e0894c9

Please sign in to comment.