Closed drusmanbashir closed 1 month ago
Hi, looking at the logs, it looks like pymple is trying to resolve imports from root in your case.
Could you show me your project tree, and try running
:lua print(vim.fn.getcwd())
and paste me the output of that?
Cheers
The project is called fran. It resides under /home/ub/code/fran/ ... Project structure in screenshot
I use "ahmedkhalf/project.nvim" to change cwd() dynamically. If I am inside any .py file buffer in this project and called :lua print(vim.fn.getcwd())
I get :
/home/ub/code/fran/fran
if i am inside nvim-tree sidebar and call the command, i get:
/home/ub/code
Thanks!
Could you try adding the following root python marker to your config?
python = {
-- the names of root markers to look out for when discovering a project
root_markers = { "pyproject.toml", "setup.py", ".git", "manage.py", ".project_root" },
... ---------------
}
I made changes as suggested. My configuration looks as follows:
{
"alexpasmantier/pymple.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
-- optional (nicer ui)
"stevearc/dressing.nvim",
"nvim-tree/nvim-web-devicons",
},
build = ":PympleBuild",
config = function()
require("pymple").setup({
update_imports = {
-- the filetypes on which to run the update imports command
-- NOTE: this should at least include "python" for the plugin to
-- actually do anything useful
filetypes = { "python", "markdown" },
},
-- options for the add import for symbol under cursor feature
add_import_to_buf = {
-- whether to autosave the buffer after adding the import (which will
-- automatically format/sort the imports if you have on-save autocommands)
autosave = true,
},
python = {
-- the names of root markers to look out for when discovering a project
root_markers = { "pyproject.toml", "setup.py", ".git", "manage.py", ".project_root" },
},
keymaps = {
-- Resolves import for symbol under cursor.
-- This will automatically find and add the corresponding import to
-- the top of the file (below any existing doctsring)
resolve_import_under_cursor = {
desc = "Resolve import under cursor",
keys = "<leader>lq", -- feel free to change this to whatever you like
},
},
logging = {
file = {
enabled = true,
path = vim.fn.stdpath("data") .. "/pymple.vlog",
max_lines = 1000, -- feel free to increase this number
},
-- this might help in some scenarios
console = {
enabled = false,
},
level = "debug",
},
}
)
end,
},
}
Log files:
[DEBUG Mon 09 Sep 2024 01:59:05 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:24: Created PympleUpdateImports user command
[DEBUG Mon 09 Sep 2024 01:59:05 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:35: Created PympleResolveImport user command
[DEBUG Mon 09 Sep 2024 01:59:05 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:42: Created PympleBuild user command
[DEBUG Mon 09 Sep 2024 01:59:05 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:49: Created PympleLogs user command
[INFO Mon 09 Sep 2024 01:59:05 PM BST] .../.local/share/nvim/lazy/pymple.nvim/lua/pymple/hooks.lua:62: Found nvim-tree installation, hooking up events
[INFO Mon 09 Sep 2024 01:59:05 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:59: Pymple setup complete
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:118: Updating imports from /home/ub/code/fran/fran/utils/common2.py to /home/ub/code/fran/fran/utils/common.py in filetypes: { "python", "markdown" }
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:66: Operating on a file
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:16: split gg args: --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.utils\s+import\s+(?:\([\sa-zA-Z0-9_,]*common2[\sa-zA-Z0-9_,]*\)\s*|[\w,]*common2[\w,]*)' .
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.utils\s+import\s+(?:\([\sa-zA-Z0-9_,]*common2[\sa-zA-Z0-9_,]*\)\s*|[\w,]*common2[\w,]*)' .
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:36: monolithic gg args: --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.utils\.common2\b' .
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.utils\.common2\b' .
[DEBUG Mon 09 Sep 2024 02:00:13 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[INFO Mon 09 Sep 2024 02:00:13 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:129: No jobs to run.
Thanks,
I'm pretty sure the project root discovery is starting too high in your case and never finds your project markers.
Could you try updating to the latest version (I added a couple of log messages to try and debug your case), re-running your command and printing the logs?
[INFO Mon 09 Sep 2024 05:14:19 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:34: --- NEW PYMPLE SESSION ---
[INFO Mon 09 Sep 2024 05:14:19 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:35: --------------------------------------------------------------
[DEBUG Mon 09 Sep 2024 05:14:19 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:40: Current directory: /home/ub
[DEBUG Mon 09 Sep 2024 05:14:19 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:24: Created PympleUpdateImports user command
[DEBUG Mon 09 Sep 2024 05:14:19 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:35: Created PympleResolveImport user command
[DEBUG Mon 09 Sep 2024 05:14:19 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:42: Created PympleBuild user command
[DEBUG Mon 09 Sep 2024 05:14:19 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:49: Created PympleLogs user command
[INFO Mon 09 Sep 2024 05:14:19 PM BST] .../.local/share/nvim/lazy/pymple.nvim/lua/pymple/hooks.lua:62: Found nvim-tree installation, hooking up events
[INFO Mon 09 Sep 2024 05:14:19 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:61: Pymple setup complete
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:118: Updating imports from /home/ub/code/fran/fran/utils/common.py to /home/ub/code/fran/fran/utils/common2.py in filetypes: { "python", "markdown" }
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...local/share/nvim/lazy/pymple.nvim/lua/pymple/project.lua:36: Project root: /home/ub/code/fran:/home/ub/code/label_analysis:/home/ub/code/dicom_utils:/home/ub/code/xnat
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:66: Operating on a file
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:16: split gg args: --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.utils\s+import\s+(?:\([\sa-zA-Z0-9_,]*common[\sa-zA-Z0-9_,]*\)\s*|[\w,]*common[\w,]*)' .
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.utils\s+import\s+(?:\([\sa-zA-Z0-9_,]*common[\sa-zA-Z0-9_,]*\)\s*|[\w,]*common[\w,]*)' .
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:36: monolithic gg args: --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.utils\.common\b' .
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.utils\.common\b' .
[DEBUG Mon 09 Sep 2024 05:14:34 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[INFO Mon 09 Sep 2024 05:14:34 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:129: No jobs to run.
[INFO Mon 09 Sep 2024 05:15:07 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:33: --------------------------------------------------------------
See above. Thanks for helping. I dont mind it looking into other projects, e.g., code/xnat , code/dicom_utils as they import from this project (fran), but it does not refactor the import statements as far as i can see inside fran.
Ok, got it. I'm pretty sure opening neovim directly in your project folder will make it work.
I'll try adding additional logic to properly discover project root in workflows like yours in the coming days.
Just fyi: I now get a brief error when I start nvim: sed cant read 1459d: no such file or directory :D
Just pushed a fix for your project discovery problem.
Pymple should now be able to automatically infer which project you're working on when renaming files.
It works on my machine. Can you confirm that's the case for yours?
Thanks in advance.
PS: the sed problem is probably linked to interaction with another plugin since pymple doesn't run anything related to sed on startup.
Fixed in #42
Didn't work. Logs:
[INFO Sat 14 Sep 2024 03:09:00 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:33: --------------------------------------------------------------
[INFO Sat 14 Sep 2024 03:09:00 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:34: --- NEW PYMPLE SESSION ---
[INFO Sat 14 Sep 2024 03:09:00 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:35: --------------------------------------------------------------
[DEBUG Sat 14 Sep 2024 03:09:00 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:40: Current directory: /home/ub
[DEBUG Sat 14 Sep 2024 03:09:00 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:24: Created PympleUpdateImports user command
[DEBUG Sat 14 Sep 2024 03:09:00 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:35: Created PympleResolveImport user command
[DEBUG Sat 14 Sep 2024 03:09:00 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:42: Created PympleBuild user command
[DEBUG Sat 14 Sep 2024 03:09:00 PM BST] ...share/nvim/lazy/pymple.nvim/lua/pymple/user_commands.lua:49: Created PympleLogs user command
[INFO Sat 14 Sep 2024 03:09:00 PM BST] .../.local/share/nvim/lazy/pymple.nvim/lua/pymple/hooks.lua:62: Found nvim-tree installation, hooking up events
[INFO Sat 14 Sep 2024 03:09:00 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/init.lua:61: Pymple setup complete
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:118: Updating imports from /home/ub/code/fran/fran/transforms/imageio.py to /home/ub/code/fran/fran/transforms/imageio2.py in filetypes: { "python", "markdown" }
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...local/share/nvim/lazy/pymple.nvim/lua/pymple/project.lua:36: Project root: /home/ub/code/fran:/home/ub/code/label_analysis:/home/ub/code/dicom_utils:/home/ub/code/xnat:/home/ub/code/registration
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:66: Operating on a file
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:16: split gg args: --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.transforms\s+import\s+(?:\([\sa-zA-Z0-9_,]*imageio[\sa-zA-Z0-9_,]*\)\s*|[\w,]*imageio[\w,]*)' .
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -U -t python -t markdown 'from\s+\.home\.ub\.code\.fran\.fran\.transforms\s+import\s+(?:\([\sa-zA-Z0-9_,]*imageio[\sa-zA-Z0-9_,]*\)\s*|[\w,]*imageio[\w,]*)' .
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...nvim/lazy/pymple.nvim/lua/pymple/update_imports/init.lua:36: monolithic gg args: --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.transforms\.imageio\b' .
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:97: Starting gg job: gg -C --json -t python -t markdown '[^\.]\b\.home\.ub\.code\.fran\.fran\.transforms\.imageio\b' .
[DEBUG Sat 14 Sep 2024 03:09:38 PM BST] ...b/.local/share/nvim/lazy/pymple.nvim/lua/pymple/jobs.lua:119: 0 results found
[INFO Sat 14 Sep 2024 03:09:38 PM BST] ...ub/.local/share/nvim/lazy/pymple.nvim/lua/pymple/api.lua:130: No jobs to run.
[
My bad, didn't spot that pythonpath in the logs. You should be good to go now 😉
Thanks to you, Now i have a powerful IDE. Still use pycharm for debugging as the debugger is a bit meh. that an interesting nextt project for you ? lol
I mostly debug python using ipdb tbh. Never really felt the need for a full-fledged debugger :)
Cheers !
You're welcome to contribute to pymple in the future if you find any interesting improvement you feel is worth integrating! 👍🏻
Hi Thanks for the much needed plugin! I am setting it up with nvim-tree. I have installed all dependencies. if i go inside nvim-tree and rename a file, a rename box appears as shown in your gif. But after renaming the file nothing happens at all. No confirmation box appears. I just get the message that the file has been renamed.
Neovim: NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068
Checkhealth:
============================================================================== pymple: health#pymple#check
Checking for required plugins ~
Checking external dependencies ~
For example, I just renamed a file common.py to common2.py. See the Pymplelog: