wyuenho / emacs-pet

Tracks down the correct Python tooling executables from your virtualenvs so you can glue the binaries to Emacs and delete code in init.el
GNU General Public License v3.0
105 stars 13 forks source link

(pet-use-poetry-p) doesn't find poetry #4

Closed janoc closed 2 years ago

janoc commented 2 years ago

Hello,

I can't manage to get (pet-use-poetry-p) to ever detect poetry.

The problem seems to be in this block that always returns nil:

  (and (not
        (null
         (string-match-p
          "poetry"
          (or (let-alist (pet-pyproject)
                .build-system.build-backend)
              ""))))
       (executable-find "poetry"))

The string-match-p always returns nil, so the and shortcircuits and the executable is never found, despite poetry being in the path. If I remove everything apart from the executable-find, then everything works as expected.

How to reproduce:

wyuenho commented 2 years ago

What's in your pyproject.toml file?

janoc commented 2 years ago

Pretty much the default as generated by poetry new except for the graphics.py dependency. But the same thing happens also on my work projects with much bigger pyproject.toml

[tool.poetry]
name = "Bezier"
version = "0.1.0"
description = ""
authors = ["Jan Ciger <jan.ciger@xxx.xxx>"]

[tool.poetry.dependencies]
python = "^3.8"
"graphics.py" = "^5.0.1"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
wyuenho commented 2 years ago

What's in your pet-pyproject-cache and exec-path? Is pyproject.toml in the root of your project?

janoc commented 2 years ago

Layout of my project:

.
├── bezier
│   ├── __init__.py
│   └── main.py
├── .flake8
├── .git
│   ├── branches
│   ├── config
│   ├── description
│   ├── HEAD
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── fsmonitor-watchman.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── pre-merge-commit.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── pre-push.sample
│   │   ├── pre-rebase.sample
│   │   ├── pre-receive.sample
│   │   ├── push-to-checkout.sample
│   │   └── update.sample
│   ├── info
│   │   └── exclude
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
├── .gitignore
├── poetry.lock
├── .projectile
├── pyproject.toml
├── README.rst
└── tests
    ├── __init__.py
    └── test_bezier.py

pet-pyproject-cache is nil

exec-path is: (/usr/local/bin /usr/bin /bin /usr/local/games /usr/games /usr/local/sbin /usr/sbin /usr/lib64/qt5/bin /home/janoc/scripts /home/janoc/.local/bin /home/janoc/.cabal/bin /home/janoc/.platformio/penv/bin /home/janoc/src/ele/avr/arduino/arduino /sbin /usr/sbin /usr/local/bin /opt/java/jdk/bin /opt/java/jdk/jre/bin /opt/android-sdk-linux/tools /opt/dar-2.4.0/bin /opt/arm/arm-none-eabi/bin /opt/gcc-arm-none-eabi/bin /opt/openocd/bin /media/u/build/arm/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin /opt/avr-toolchain/bin /opt/OpenSceneGraph/bin /opt/emacs/bin /opt/rtags/bin /opt/the_silver_searcher/bin /opt/node/bin /opt/racket/bin/ /opt/kconfig-frontends/bin /opt/icestorm/bin /opt/clang/bin /opt/lisp/sbcl/bin /opt/DotNet /opt/fpga/verilator/bin /opt/fpga/gtkwave/bin /opt/emacs-29/libexec/emacs/29.0.50/x86_64-pc-linux-gnu)

janoc commented 2 years ago

Yeah but pet-virtualenv-root uses pet-use-poetry-p to try to see whether it should look for poetry - and that returns always nil, so it doesn't even try.

I have tried to debug it but I don't quite understand the logic behind that let-alist call there, so that's where I am stuck with it. If I remove/comment those lines out, pet-use-poetry-p returns the path to poetry and pet-virtualenv-root works as expected too.

wyuenho commented 2 years ago

Hmm, that's very strange. Either pet-project-root can't detect your project root or pet-parse-config-file can't parse your pyproject.toml for whatever reason. I'd turn on pet-debug and see what comes up in the *Messages* buffer or edebug pet-parse-config-file and see what's up. It's very hard for me to debug here.

wyuenho commented 2 years ago

BTW, just making sure, you do have dasel or tomljson installed and they are on your exec-path right?

janoc commented 2 years ago

(executable-find "dasel") returns "/usr/local/bin/dasel"

and setting pet-debug to t before enabling pet-mode doesn't produce any relevant output in the "Messages" apart from the usual stuff - turning on LSP mode.

Could you at least tell me what is that let-alist attempting to do there? Maybe that would give me a pointer at where to look.

I am surprised that you can't reproduce it, though.

wyuenho commented 2 years ago

let-alist just allows you to select into an alist path, if that's returning nil, that means something is wrong with parsing pyproject.yaml, i.e. either it was not found or there was some syntax error. pet-pyproject parses the TOML file into JSON, and then json-parse-string parses it into an elisp association list.

wyuenho commented 2 years ago

BTW, you seem to be using some old version of pet, install from main and tell me if you still have the same error.

janoc commented 2 years ago

Ha, that seems to have fixed the issue. After updating I am getting poetry recognized now.

My pet was probably a week or so old - I have installed it right after you have posted it on reddit and didn't think to update as it was still quite recent.

janoc commented 2 years ago

OK then I guess I can close this. I will test it tomorrow on my work machine with a different project as well, if it still/again doesn't work then I will reopen this.

Thanks for your help!