Add '-m mod : run library module as a script' option.#1352
Conversation
|
Should 'run_module' come first or last, assuming more than one such code-to-run is given? I'm fine with a decision of 'behavior undefined' for such situations (which are probably rare), but a public decision would be useful. |
|
The python executable only allows one of |
|
IPython will not stop parsing args at '-c' or '-m', so if that should happen, more work would need to be done: |
|
Well, I don't think there is much that can be done without changing the IPython argument parser. However, it may be possible to one day support syntax like where the As such, the current patch is useful for running modules which take no arguments, and in the last commit I took the similar sys.argv handling from _exec_file(), which will allow some arguments. |
|
Yes, it will work if no arguments are to be passed, which is already a nice feature. We already use The relevant line: https://github.com/ipython/ipython/blob/master/IPython/frontend/terminal/ipapp.py#L309 |
|
Just pushed a small fix so that |
There was a problem hiding this comment.
module_to_run and code_to_run should probably be treated the same. Do you want to set a flag inside _file_to_run_changed to use here, rather than explicitly checking for self.module_to_run?
There was a problem hiding this comment.
So do you mean something like
def _file_to_run_changed(self, name, old, new):
something_to_run = True
...
# internal, not-configurable
interact = Bool(True)
something_to_run=Bool(False)
....
def initialize(self, argv=None):
...
if self.extra_args and not self.something_to_run:
self.file_to_run = self.extra_args[0]
...
…, file, or code to run.
|
Nice, thanks! Looks good to me. |
Add '-m mod : run library module as a script' option.
Add '-m mod : run library module as a script' option.
@fperez is very prescient...
Closes gh-1350.