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

[bug]: send file and send until cursor in python linux doesn't works as expected #369

Closed
f3fora opened this issue May 8, 2024 · 11 comments

Comments

@f3fora
Copy link
Contributor

f3fora commented May 8, 2024

commit 95383e0 breaks send_file and send_until_cursor in python linux.
A file like the following one, which is sent to iron, is divided in an awkward way, and the interpreter raises several errors.

It works fine if I select all the text and then send_visual.

foo = 1


class Foo:
    def __init__(self) -> None:
        self.bar = 1

    def foo(self) -> int:
        return self.bar


bar = Foo()
print(bar.foo())
@f3fora
Copy link
Contributor Author

f3fora commented May 9, 2024

Dear @nickeisenberg ,

I think the last approach for formatting python code of the last commits and PRs is not so solid.

I think, parsing and splitting the code, should not be done manually and by case.
I think that you can try to achieve better, more robust and general result with the appropriate tools, e.g. treesitter.

See for example #210

@nickeisenberg
Copy link
Contributor

nickeisenberg commented May 9, 2024

@f3fora Did send_file or send_until_cursor ever work for you? I had errors with those in the past when only common.bracked_paste was used.

And I understand what you are saying about the formatting, when I have more time I will try and find better way. However, I believe I have a fix your your send_file and send_until_cursor issue now. The latest commit should work now.

@f3fora
Copy link
Contributor Author

f3fora commented May 10, 2024

@f3fora Did send_file or send_until_cursor ever work for you? I had errors with those in the past when only common.bracked_paste was used.

It worked until 95383e0 .

And I understand what you are saying about the formatting, when I have more time I will try and find better way. However, I believe I have a fix your your send_file and send_until_cursor issue now. The latest commit should work now.

Thanks. It works. There is still some empty lines that are not required and fill the interpreter.

@nickeisenberg
Copy link
Contributor

I just checkout out the commit prior to the one you referenced. Are you using IPython? send_file works for me on that commit for IPython but it fails when using python3 as the repl_definition.

When I have some time, I'll see about removing that extra line that is added when sending to the terminal. Thanks!

@anku94
Copy link

anku94 commented May 10, 2024

Same problem, using IPython --no-autoindent with python3.10 - both send_file and send_until_cursor are broken. send_visual and send_line work.

@nickeisenberg maybe try a somewhat "complicated" example? I can try figuring out a reproducible example if you are unable to reproduce.

@nickeisenberg
Copy link
Contributor

nickeisenberg commented May 10, 2024

@anku94 its still not working after the latest commit to master? I cant produce an example where send_file fails now.

Im going to close this issue as I can't produce a example that causes an error, please reopen a new issue if you have an example that causes a bug though!

@anku94
Copy link

anku94 commented May 13, 2024

@nickeisenberg sorry for the delayed response, I still seem to have issues.

The extension now seems to separate code blocks by blank lines, and as a result, function definitions with blank lines end up getting passed as separate code blocks. Example code:

def f():
  a = 5

  print(a)

Will produce:

Python 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC
 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.13.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: def f():
   ...:     a = 5
   ...: 

In [2]:     print(a)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 print(a)

NameError: name 'a' is not defined

This is with both send_until_cursor and send_line.

@nickeisenberg
Copy link
Contributor

nickeisenberg commented May 13, 2024

@anku94 this is weird, I do not have that issue

def f():
  a = 5

  print(a)
  
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.24.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: def f():
   ...:   a = 5
   ...:   print(a)
   ...: 

In [2]: 

by any chance, does your config look like this?

    iron.setup {
      config = {
         ...
        repl_definition = {python = {command = {"ipython", "--no-autoindent"}}},
        ...
      },

@anku94
Copy link

anku94 commented May 13, 2024

Yes, that's what my config looks like. I did not have anything for python, and the new update complained about repl_definition.python being set to nil, so I added this.

@nickeisenberg
Copy link
Contributor

nickeisenberg commented May 13, 2024

@anku94 Can you try this

    local python_formatter = require("iron.fts.common").bracketed_paste_python
    iron.setup {
      config = {
        ...
        repl_definition = {
          python = {
            command = { "ipython", "--no-autoindent" },
            format = python_formatter,
          }
        }
        ...
      },
      ...
    }

Also I'm not sure why it complained about being set to nil. I have mine set to nil.

@anku94
Copy link

anku94 commented May 14, 2024

This works - thank you!! :)

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

3 participants