diff --git a/lua/cp/scraper.lua b/lua/cp/scraper.lua index d2613cf..21cd697 100644 --- a/lua/cp/scraper.lua +++ b/lua/cp/scraper.lua @@ -25,6 +25,15 @@ end ---@param args string[] ---@param opts { sync?: boolean, ndjson?: boolean, on_event?: fun(ev: table), on_exit?: fun(result: table) } local function run_scraper(platform, subcommand, args, opts) + if not utils.setup_python_env() then + local msg = 'no Python environment available (install uv or nix)' + logger.log(msg, vim.log.levels.ERROR) + if opts and opts.on_exit then + opts.on_exit({ success = false, error = msg }) + end + return { success = false, error = msg } + end + local plugin_path = utils.get_plugin_path() local cmd = utils.get_python_cmd(platform, plugin_path) vim.list_extend(cmd, { subcommand }) diff --git a/lua/cp/utils.lua b/lua/cp/utils.lua index 05a715d..b120a6f 100644 --- a/lua/cp/utils.lua +++ b/lua/cp/utils.lua @@ -129,7 +129,8 @@ local function discover_nix_python() end local plugin_path = M.get_plugin_path() - logger.log('Building Python environment with nix...', nil, true) + vim.notify('[cp.nvim] Building Python environment with nix...', vim.log.levels.INFO) + vim.cmd.redraw() local result = vim .system( { 'nix', 'build', plugin_path .. '#pythonEnv', '--no-link', '--print-out-paths' }, @@ -177,6 +178,8 @@ function M.setup_python_env() if vim.fn.executable('uv') == 1 then local plugin_path = M.get_plugin_path() logger.log('Python env: uv sync (dir=' .. plugin_path .. ')') + vim.notify('[cp.nvim] Setting up Python environment...', vim.log.levels.INFO) + vim.cmd.redraw() local env = vim.fn.environ() env.VIRTUAL_ENV = '' @@ -264,10 +267,6 @@ function M.check_required_runtime() return false, timeout.reason end - if not M.setup_python_env() then - return false, 'no Python environment available (install uv or nix)' - end - return true end