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

Can not pass options to the script executed by ipython #20

Open
egilewski opened this issue Feb 19, 2024 · 7 comments
Open

Can not pass options to the script executed by ipython #20

egilewski opened this issue Feb 19, 2024 · 7 comments

Comments

@egilewski
Copy link

Unlike the default Flask shell, this one allows to specify a script to execute, just like outside of Flask do ipython script.py and python script.py. However passing options to a script invoked that way may require a preceding -- separator, which is being dropped by click library and never makes it to IPython.start_ipython(argv=ipython_args,

Demonstration:

$ echo 'import sys; print(sys.argv)' >script.py

Works as expected:

$ flask shell script.py --test test
[TerminalIPythonApp] WARNING | Unrecognized alias: 'test', it will have no effect.
['/usr/src/script.py']

Doesn't work as expected:

$ flask shell script.py -- --test test
[TerminalIPythonApp] WARNING | Unrecognized alias: 'test', it will have no effect.
['/usr/src/script.py']

Expected result in the second case:

$ flask shell script.py -- --test test
['/usr/src/script.py', '--test', 'test']

It seems that the required feature is missing in click, though may be added in pallets/click#2205 (see also pallets/click#619 and pallets/click#1340).

I realize that this may not have been a planned feature, but this would be a nice extra thing that the default Flask shell doesn't offer.

@egilewski egilewski changed the title Can not pass arguments to the script executed by ipython Can not pass options to the script executed by ipython Feb 19, 2024
@egilewski
Copy link
Author

I found a way, though it's a strange one: $ flask shell script.py -- -- --test test

@ei-grad
Copy link
Owner

ei-grad commented Apr 3, 2024

To make it doesn't look strange, the proper syntax would be flask shell -- script.py -- --test test. For me it looks like it works as expected.

But I agree that -- handling by click is really not intuitive in the first example. A related issue exists in pallets/click#619.

Not sure if it could be a good idea to change this behavior.

@ei-grad
Copy link
Owner

ei-grad commented Apr 3, 2024

Hmm. Looks like I got the issue wrong. First example actually is not related to pallets/click#619.

@ei-grad
Copy link
Owner

ei-grad commented Apr 3, 2024

Works as expected:

$ flask shell script.py --test test
[TerminalIPythonApp] WARNING | Unrecognized alias: 'test', it will have no effect.
['/usr/src/script.py']

This actually doesn't work as expected (as of my sense), and it changed behavior in IPython 8.x (with IPython<8 it results in error and non-zero exit code instead of a WARNING log message). But still I don't think we should do anything with it, because passing options after the filename argument matches the ipython behavior to interpret this options as dedicated to ipython:

→ ipython script.py --test test
[TerminalIPythonApp] WARNING | Unrecognized alias: 'test', it will have no effect.
['/home/ei-grad/repos/github.com/ei-grad/flask-shell-ipython/script.py']

@ei-grad
Copy link
Owner

ei-grad commented Apr 3, 2024

This actually doesn't work as expected (as of my sense)

Oh. Sorry, it looks like I got the message a little bit wrong again :-).

@ei-grad
Copy link
Owner

ei-grad commented Apr 3, 2024

Not sure what to do with this :-). Probably we can just document it in the README. Any thoughts are welcome.

@egilewski
Copy link
Author

Maybe it will be ripe for an easy solution after pallets/click#2205 is resolved.

README shouldn't hurt, but just the ability to find this issue with a strange/not strange solution should save people time.

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

2 participants