Git Product home page Git Product logo

poetry.el's Introduction

https://img.shields.io/badge/license-GPL-brightgreen.svg https://img.shields.io/badge/python-3.7+-blue.svg https://melpa.org/packages/poetry-badge.svg https://stable.melpa.org/packages/poetry-badge.svg

Important notice

I recently took over maintaining this project. I actively use this package with GNU Emacs 29.3 and poetry 1.8.2 on macOS.

poetry.el

Poetry in Emacs.

From Poetry documentation: “Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.”

poetry.el is a wrapper around Poetry, offering a simple an intuitive interface in Emacs.

Installation

From Melpa

poetry.el is available on Melpa, the most straightforward way of installing it is to use use-package:

(use-package poetry
 :ensure t)

Manually

  1. Dependencies

    poetry.el needs transient and pyvenv to be installed. These packages are both available on MELPA.

  2. Clone the poetry.el repository:
    $ git clone https://github.com/cybniv/poetry.el /path/to/poetry.el
        
  3. Add the following lines to .emacs.el (or equivalent):
    (add-to-list 'load-path "/path/to/poetry.el")
    (require 'poetry)
        

Usage

poetry.el uses transient to provide a magit-like interface. The entry point is simply:

M-x poetry

The interface should then be pretty much self-explanatory for poetry users:

doc/screenshot1.png

For users not familiar with how Poetry works, the documentation is a great place to start.

Tracking Poetry virtualenv

poetry.el also provides a global minor mode that automatically activate the correct virtualenv when visiting Poetry project files. You can activate this feature with:

M-x poetry-tracking-mode

By default, poetry.el checks if the virtualenv needs to be updated after every command. It has the advantage of always providing the right virtualenv, but can be annoyingly slow. You can change the strategy poetry.el uses through the poetry-tracking-strategy.

poetry.el's People

Contributors

bramadams avatar cybniv avatar dylanjw avatar galaunay avatar kevorr avatar ktetzlaff avatar lampze avatar mastor avatar mjlbach avatar rdugan avatar tarsius avatar vivus-ignis avatar wyuenho avatar yukiteruamano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

poetry.el's Issues

VIRTUAL_ENV environment variable not updated when switching projects

I have two projects, test1 and test2; both have their own checked out Git repository and its own virtualenv managed by Poetry. When i open a file in test1, pyvenv helpfully sets the VIRTUAL_ENV environment variable within Emacs to /home/user/.cache/pypoetry/virtualenvs/test1-x69QFwi_-py3.9 for me.

However, when i switch to another project (ie. by opening a file within test2), VIRTUAL_ENV is untouched. In some extreme cases (i can’t predictably reproduce it yet), when i run a command using poetry from within the Emacs shell, this results in Poetry (the tool) recreate an empty virtualenv for me (this is a real bugger when i work with large projects with dependencies to be compiled).

I use a combination of projectile, magit, and poetry for managing my projects, if it counts.

Hide poetry venv info in the modeline

Hi, i'm using poetry for my python projects and i can't find what to set to hide the poetry venv name in the doom modeline (see screen "venv: test-python-...")

Screenshot1

I though it was a doom modeline problem but the text also appears when it is disabled :

Screenshot2

I tried few things like diminish but I cant find a way to hide this text

README: not maintained at the moment

I am not able to maintain poetry.el at the moment.

I hope I will soon be able to take care of this again, but in the meantime, I am afraid any issue report or PR will be left unanswered.
If you happen to be willing to make a fork and maintain poetry.el, please email me directly, I will gladly redirect Melpa and users to your fork !

add to MELPA and automatically download toml dep

Hi,

It would be nice for an easy install via MELPA.

Step #2 says to just (add-to-list 'load-path "/path/to/poetry.el/directory") and the (require 'poetry). However I got this message when I tried to evaluate the second form

Debugger entered--Lisp error: (file-error "Cannot open load file" "Not a directory" "toml")
  require(toml)
  eval-buffer(#<buffer  *load*> nil "/Users/jr/.emacs.d/el/poetry.el" nil t)  ; Reading at buffer position 933
  load-with-code-conversion("/Users/jr/.emacs.d/el/poetry.el" "/Users/jr/.emacs.d/el/poetry.el" nil t)
  require(poetry)
  eval((require 'poetry) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

I solved by installing (use-package toml :ensure t). Could this be handled by poetry.el as well if/when published in MELPA?

cannot create new projects with `M-x poetry`

I'm on macOS Mojave Emacs 26.1.... I cannot create new projects.

Steps to reproduce:

  1. M-x poetry
  2. n
  3. enter in minibuffer poetry-testing
  4. Error with message "let*: Wrong type argument: stringp, 47"

Error while running `poetry-add`

Whenever I try to use poetry-add, I receive a brief message in the minibuffer stating: "Error while running Poetry command" and the *poetry-error* buffer is opened. In the error buffer, it just looks like Poetry installing the package, but it's in progress and never completes.

Wondering if anybody else has experienced a similar issue, whether that's expected, or whether I have something misconfigured in my emacs.

Efficiency of `poetry-call` and `poetry-do-call`

I'd like to preface this with the caveat that I am not an elisp expert. I would barely classify myself as a beginner. That being said, the efficiency of this module has been really bothering me lately. I've disabled poetry-tracking-mode altogether because regardless of the tracking strategy, the sad fact is that executing poetry commands is painfully slow. This is a huge bummer because the idea is fantastic. We should be able to automatically track the appropriate environment smoothly as we move between files.

Because of this, I recently started going through the code to try to figure out why this could be. After all, nothing this package is doing is complicated in anyway. It just needs to traverse the directory tree, find a pyprojec.toml that uses poetry, and then make one or two poetry calls to deduce the environment path. Poetry itself isn't slow, so this should be very quick.

Upon looking at the code, I was baffled by the implementation of these two functions. Namely, the synchronization between the two of them and the synchronization with the subprocess itself. Especially the use of sleep-for .1. I had some thoughts after doing some research around Emacs/elisp documentation, and I'm curious of anyone's thoughts. I'm not sure if I'll have the time to get up to speed in Elisp and this project to actually implement them, but wanted to raise some options to maybe help the project along.

  1. The poetry-do-call function uses a polling loop to wait for process completion. Could this not be replaced by a simple (while (accept-process-output process)) loop as shown here?
  2. The poetry-call function uses a similar polling loop when in blocking mode to wait for the queue to empty in order to call the requested poetry command. Could we not use a condition variable here to remove the polling loop? Reference. In reality, this function essentially forces all poetry-call invocations to be serialized (i.e. non-parallel), so you could even just wrap the call in a mutex and get rid of the queue altogether unless I'm misunderstanding something.
  3. All of the blocking semantics defined here seem to be in an attempt to keep the Poetry output buffer tidy. I'm not intimately familiar with how buffers work from the perspective of plugins and Elisp, but is it possible to have a separate poetry-call function for internal calls which uses a temporary buffer? My thought-process here is that the Poetry buffer is mainly useful when doing manual operations like adding a dependency, updating the lock file, packaging your application, etc. However, there's no need for this song-and-dance when we are updating the virtual environment. Those commands have no need to fuss with any kind of synchronization or save their output to a persistent buffer that I can think of. For example, the call to poetry info -p in poetry-get-virtualenv has no need to put it's output in the persistent Poetry buffer and could instead be executed on a temporary/ephemeral buffer with no locking or queue semantics. I'm happy to be proven wrong here, but it's just a thought.

Again, just to reiterate, I'm not an elisp dev. I'm just a happy Emacs user, and I'd love to see this project improve. I love poetry, and I don't want to use any editor other than Emacs if I can avoid it. :)

Poetry projects not recognized on windows 10

I did an update recently and my poetry projects were no longer recognized.
I found a regex error in the poetry-find-project-root function where the final ] must be escaped.

Sometimes I've used a different text editor to edit pyproject.toml . It can add carriage returns at the end of each lines, so I've changed the regex a bit to handle them. There may be a more elegant way to do this, but that's another story.

Here is the diff with the changes I made.

$ git diff
warning: LF will be replaced by CRLF in poetry.el.
The file will have its original line endings in your working directory
diff --git a/poetry.el b/poetry.el
index 8d6b92b..09f7e0c 100644
--- a/poetry.el
+++ b/poetry.el
@@ -431,7 +431,7 @@ credential to use."
                (poetry-with-current-file file
                 (goto-char (point-min))
                 (when (re-search-forward
-                       "^\\[tool\\.poetry\\.scripts\\]$" nil t)
+                       "^\\[tool\\.poetry\\.scripts\\][^M]?$" nil t)
                   (forward-line 1)
                   (beginning-of-line)
                   (while (re-search-forward
@@ -824,11 +824,11 @@ If OPT is non-nil, set an optional dep."
      (goto-char (point-min))
      (if dev
          (unless
-             (re-search-forward "^\\[tool\\.poetry\\.dev-dependencies\\]$"
+             (re-search-forward "^\\[tool\\.poetry\\.dev-dependencies\\][^M]?$"
                                 nil t)
            (poetry-error "No dependencies to remove"))
        (unless
-              (re-search-forward "^\\[tool\\.poetry\\.dependencies\\]$"
+              (re-search-forward "^\\[tool\\.poetry\\.dependencies\\][^M]?$"
                                  nil t)
          (poetry-error "No dependencies to remove")))
      (let ((beg (point))
@@ -871,8 +871,8 @@ If OPT is non-nil, set an optional dep."
               (when file
                 (poetry-with-current-file file
                    (goto-char (point-min))
-                   (when (re-search-forward "^\\[tool\\.poetry\\]$" nil t)
-                     (when (re-search-forward "^name = \"\\(.*\\)\"$" nil t)
+                   (when (re-search-forward "^\\[tool\\.poetry\\][^M]?$" nil t)
+                     (when (re-search-forward "^name = \"\\(.*\\)\"[^M]?$" nil t)
                        (substring-no-properties (match-string 1))))))))))

 ;;;###autoload
@@ -884,7 +884,7 @@ If OPT is non-nil, set an optional dep."
                    (with-temp-buffer
                      (insert-file-contents-literally (concat (file-name-as-directory root) "pyproject.toml"))
                      (buffer-string)))
-                  (_ (string-match "^\\[tool\\.poetry]$" pyproject-contents)))
+                  (_ (string-match "^\\[tool\\.poetry\\][^M]?$" pyproject-contents)))
         (setq poetry-project-root root))))

 (defun poetry-get-virtualenv ()

lsp mode awkwardness

Do you use lsp-mode in conjunction with poetry.el? I'm using lsp-deferred, but the connection to the language server is still to early to pick up the right env and run pyls from within the venv. I've tried all three tracking strategies.

Package broken on OSX

Every interaction with poetry fails with next message

[projectname] Could not find poetry executable

In my opinion, issue originates from this commit.

5340ec3

The main problem is that there is no section for darwin type system which leads to raising an error, while executable is perfectly findable.

I fixed that locally, so I can try to create PR with this fix

poetry in org-mode babel

I'm having difficulties getting python blocks to execute with a virtual environment activated. My setup, in doom emacs, seems to be fully functional with poetry.el otherwise, including lsp. The org file is in the same directory with the python code.

When I look at sys.path I see this:

#+property: header-args :session default :results output :exports both

#+BEGIN_SRC python
import sys
from credentials import consumer_key, consumer_secret

print(sys.path)
#+END_SRC

#+RESULTS:
: ['', '/usr/lib64/python38.zip', '/usr/lib64/python3.8', '/usr/lib64/python3.8/lib-dynload', '/home/uri/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/site-packages', '/usr/lib64/python3.8/site-packages', '/usr/lib/python3.8/site-packages']

`poetry-venv-workon` returns error

When I try to do M-: (poetry-venv-workon), I get the following error:

Debugger entered--Lisp error: (wrong-type-argument characterp "config")
  mapconcat(identity (("config") ("virtualenvs.in-project")) " ")
  poetry-do-call(config ("virtualenvs.in-project") nil nil t)
  poetry-call(config ("virtualenvs.in-project") nil nil t)
  poetry-get-configuration("virtualenvs.in-project")
  poetry-get-virtualenv()
  poetry-venv-workon()
  eval((poetry-venv-workon) t)
  eval-expression((poetry-venv-workon) nil nil 127)
  funcall-interactively(eval-expression (poetry-venv-workon) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

This is on Emacs 27.0.90. On another machine, which runs Emacs 26, activating the venv works just fine.

BTW, I was trying to activate the venv this way (with eval-expression) because the menu that pops up when I do M-x poetry doesn't have the option to activate the venv. Guess that might be related to the error I get.

Every command hangs

Every command hangs indefinitely for me until I hit C-g to cancel it. Afterwards I find nothing suspicious in *Messages*, but poetry.el does create a buffer called *poetry* with the following contents (example for poetry-new):

Compilation started at Fri Jan 27 19:25:54

/home/kahr/.local/bin/poetry new -n --ansi /home/kahr/tmp/
sh-5.2$ 

Which doesn't give the impression that it's actually running anything. If I run the /home/kahr/.local/bin/poetry new -n --ansi /home/kahr/tmp/ command manually it works just fine.

This is on Emacs 28.2.

Error while opening files with poetry-tracking-mode on

The Problem

While opening any file in a poetry project with poetry-tracking-mode on, the modeline displays a compilation error and the *poetry-error* buffer is opened. The error buffer is empty, but on going to *Messages* buffer, there is a statement that says "Error while running a poetry command". Functionality-wise, everything seems to work as expected and despite the error the virtual environment is activated. I have individually checked all poetry commands via Emacs and they seem to do fine too. I do not understand why then is an error shown.

Reproducing

  • M-x poetry-tracking-mode
  • C-x C-f Open any file in project

Not getting in buffer completions.

I only recently started using poetry and found this package. I like the package, it lets me manage my poetry project from within Emacs.

I am having a problem though, I tried poetry-venv-workon, poetry-venv-toggle, poetry-tracking-mode, I think it does activates the venv but I am not seeing any completions in buffer.

For example before I installed poetry and creating a virtual environment I installed Django package from pip in my user wherever python places its packages PATH and I was getting completions fine. But after installing poetry and setting up a venv I am not seeing any completions in buffer.

Unable to use with errors

Hello,

I'm using Pop_os 20.1.

I've installed python with "pyenv install 3.8.6."

When I run "M-x poetry init" within that directory, I get the following error:

$ /home/jordan/.pyenv/versions/3.8.6/bin/python: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/jordan/.pyenv/versions/3.8.6/bin/python)
exit

Process shell exited abnormally with code 1

I am able to run poetry init in the terminal with no errors. I also get the same error when loading a virtual environment using poetry.el, but again poetry in the bash shell outside of works.

Choose different hook for poetry-tracking-mode

The use of post-command-hook for poetry-tracking-mode causes the feature to be unusable for me, as every keystroke triggers the poetry-track-virtualenv function which slows editing to a crawl.

The python-mode-hook and projectile-after-switch-project-hook (assuming projectile) may be more appropriate.

The following use-package statement is a hack to get around the issue (while also auto enabling the feature on the hooks mentioned)

(use-package poetry
  :ensure t
  :config
  (add-hook 'poetry-tracking-mode-hook (lambda () (remove-hook 'post-command-hook 'poetry-track-virtualenv)))
  (add-hook 'python-mode-hook 'poetry-track-virtualenv)
  (add-hook 'projectile-after-switch-project-hook 'poetry-track-virtualenv))

poetry-tracking-mode cannot find poetry executable

Hi, and thanks for the package.

With poetry-tracking-mode enabled, when I open a file in a project, I get this error:

Error in post-command-hook (poetry-track-virtualenv): (error "[project] Could not find ’poetry’ executable")

I definitely have poetry installed, so I'm not sure what this could be.

OS: Pop_os (linux debian) latest release.

'$ which poetry' returns:

/home//.poetry/bin/poetry

slow performance on poetry 1.5

Apologies for the lack of detail, but we were forced to update to poetry 1.5 from 1.3 (due to dependabot dropping support for 1.3). Since the upgrade the performance of most actions (format on save, magit, etc.) has been degraded. The only artifact I have noticed is that the mini-buffer is flashing a message about poetry.

BUG - when I activate poetry-tracking-mode

I am trying to use poetry.el for the first time. I am running into this issue where when I try to do: poetry-tracking-mode, within a buffer with a python code open from a project managed by poetry, it shows the following error:

-*- mode: compilation; default-directory: "/home/<user>/<project_name>" -*-
Compilation started at Fri Jul  7 18:36:57

env -u VIRTUAL_ENV  config virtualenvs.in-project
env: ‘config’: Permission denied

Compilation exited abnormally with code 126 at Fri Jul  7 18:36:57

Any help would be highly appreciated!

Refresh workspace after poetry-add or poetry-remove on lsp-mode

Hi, thanks for maintaining this package!

I'm an lsp-mode user and the snippet provided by @jidicula works great to determine the correct virtual env.

But when a dependency is added or removed you have to manually execute lsp-workspace-restart so the library changes are available to the project.

Is it possible to execute this command after every poetry-add or poetry-remove if LSP-mode is used?

Thanks!

Incompatible version of Poetry.el on Melpa Stable

Version of Poetry still on Melpa Stable indicates 0.1.0. This version is incompatible because of uninstallable cl 1.0 package.

Help from list-packages:

Package poetry is incompatible.

     Status: Incompatible because it depends on uninstallable packages.
    Archive: stable
    Version: 0.1.0
     Commit: 6fb34742a66421c6104e02d65e8d391fc4494ab5
    Summary: poetry in Emacs
   Requires: transient-0.1.0, cl-1.0 (not available), xterm-color-1.8
    Website: https://github.com/galaunay/poetry.el
   Keywords: python tools 
 Maintainer: Gaby Launay <[email protected]>
     Author: Gaby Launay <[email protected]>
Other versions: 20240103.947 (installed), 20240103.947 (melpa).

This package offers an interface to poetry (https://poetry.eustace.io/),
a Python dependency management and packaging command line tool.

This is the same as #19 . Seems like 0.2.0 release was not tagged. I don't know anything about Melpa Stable, so not sure if it only pulls from the latest tagged releases.

Would help people who use Melpa Stable if next release (or old one) can be tagged.

Emacs 26.3: list-packages shows poetry.el as incompatible

  poetry             0.1.0         incompat   melpa-s... poetry in Emacs

and looking at the *Help* buffer (details )

poetry is an incompatible package.

     Status: Incompatible because it depends on uninstallable packages.
    Archive: melpa-stable
    Version: 0.1.0
     Commit: 6fb34742a66421c6104e02d65e8d391fc4494ab5
    Summary: poetry in Emacs
   Requires: transient-0.1.0, cl-1.0 (not available), xterm-color-1.8
   Homepage: https://github.com/galaunay/poetry.el
   Keywords: python tools 
Other versions: 20200326.1328 (melpa).

This package offers an interface to poetry (https://poetry.eustace.io/),
a Python dependency management and packaging command line tool.

That said, I loaded it manually following the instructions in the readme, and it loaded with no errors, and m-x poetry asks me to create or init a project

Poetry-mode runtime error. `env: unknown option --u`

It would be nice if you could define the poetry executable for this package, and/or how it is called. The full output of the error is:

env: unknown option -- u
usage: env [-i] [name=value ...] [utility [argument ...]]

This error arose from OpenBSD not using the gnu implementation of env, in which for gnu the -u flag is valid. Where as for the nongnu derivative of env, -u is not valid.

Adding an alias to my shell and see if that clears up the issue.

create new project dwim

Currently, M-x poetry only installs projects on existing directories.

Would be nice that if the given project name in prompt does not exist then create new directory with that name.

Steps to reproduce

  1. Go to $HOME
  2. C-x d
  3. M-x poetry
  4. insert in minibuffer poet-testing

Error

error: apply: Setting current directory: No such file or directory, /Users/jr/poet-testing

OS and Emacs version

macOS mojae , Emacs 26.1

[BUG] Issues running venv toggle after the new poetry 1.0 release

Issue

Hey, currently with the new release of poetry (1.0) I can't seem to toggle the virtual environment on.
The option is simply not there and M-x ing it has been giving me issue.

Sorry for the non specificity of the report, however I have since moved on to the pipenv as an intermediary solution so I can not remember what issues I had previously. However thought that its wise to report. I have seen some forks that attempt to fix this. Maybe you can accept or ask for a PR?

Or maybe i am just being dense.

System Specs

Please ask if needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.