Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry projects not recognized on windows 10 #35

Open
altomcat opened this issue Oct 29, 2021 · 3 comments
Open

Poetry projects not recognized on windows 10 #35

altomcat opened this issue Oct 29, 2021 · 3 comments

Comments

@altomcat
Copy link

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 ()
TakaakiFuruse added a commit to TakaakiFuruse/poetry.el that referenced this issue Jan 23, 2022
@andreaskundig
Copy link

I have the same problem on windows 11. If run dos2unix on pyproject.toml, then everything works, so a dumb workaround would be to configure git to keep pyproject.toml in unix format. The patch proposed by @altomcat two years ago seems like a good solution, why hasn't this been fixed?

@Eason0210
Copy link

Have the same issue on Windows 10.

Any progress on this?

@cybniv
Copy link
Owner

cybniv commented Jan 7, 2024

I really can not reproduce this on any system, unfortunately.

I'll try to test this in a Windoze VM asap. And it will be Windows on ARM, for what it's worth.

However, the proposed fix is looking not right for me.

There's no final ] that must be escaped IMHO, as ] is only treated as a special character if there's a preceding unquoted [ and there isn't.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Special.html

In addition, it's still unclear to me what [^M] should do any good in this case. If anything related to windows carriage return line breaks, the regex should be (\r?\n) instead of $, but this remains to be proven to be even remotely necessary.

For all the users affected by these issue (100% using MS Windows):

I'd be good to have the following information:

  • What version of poetry.el are you using? As a doom emacs user, e.g., the latest commits are not yet in upstream

  • How are you using Emacs on Windows? I'm guessing the whole WSL1/WSL2 user base does not have this problem, so it's limited to the binary builds from Corwin Brust available on gnu.org, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants