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

Allow "Run Python File in Terminal" button to be configurable #11812

Open
Tracked by #22610
luabud opened this issue May 14, 2020 · 11 comments
Open
Tracked by #22610

Allow "Run Python File in Terminal" button to be configurable #11812

luabud opened this issue May 14, 2020 · 11 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments area-terminal feature-request Request for new features or functionality needs proposal Need to make some design decisions

Comments

@luabud
Copy link
Member

luabud commented May 14, 2020

This could be done by linking it to "Run Without Debugging" if we have an easy set up experience for running scripts. Or simply by allowing arguments to be passed to python (e.g. -i) or to the file.

We should also allow for stopping the execution

Related:

#10130
#11036
#12185
#12668

@Inetov
Copy link

Inetov commented Oct 16, 2020

yes, at the moment this is a completely useless button.
we have a button close at hand, but to use launch.json we need to go to the menu ...

@gandhis1
Copy link

I agree here, unless I'm missing something apparently there isn't any way to run a script with arguments through this button/command. One is forced to use the Debug screen launchers which is substantially less convenient.

@Diogo-Rossi
Copy link

Diogo-Rossi commented Sep 11, 2022

I agree here, unless I'm missing something apparently there isn't any way to run a script with arguments through this button/command. One is forced to use the Debug screen launchers which is substantially less convenient.

@gandhis1, if you think it will be good, please, up vote this

@Diogo-Rossi
Copy link

Diogo-Rossi commented Sep 12, 2022

Or simply by allowing arguments to be passed to python (e.g. -i) or to the file.

@luabud, I think we already can pass arguments to python with the setting "python.terminal.launchArgs".

I've opened this issue to request the same for the script file.

@luabud
Copy link
Member Author

luabud commented Sep 14, 2022

Yes, good point! And perhaps you meant to reference #19810?

@Diogo-Rossi
Copy link

Yes, good point! And perhaps you meant to reference #19810?

Yeah, my bad. I updated the link now.

@AntonVucinic
Copy link

AntonVucinic commented Sep 19, 2022

Another good option would be to add the ability to run currently open file as a module. This is already referenced by #10130 in a slightly different way. Currently there is only a way to set a specific module to be ran.
There is a workaround that works for files in the project root directory:

{
    "name": "Python: Module",
    "type": "python",
    "request": "launch",
    "module": "${fileBasenameNoExtension}",
    "justMyCode": true
}

I think there should be an option to run the currently open file as a module and also set that to be the default behaviour for the "Run Python File" button so that it could be used without starting the debugger.

@starball5
Copy link

starball5 commented Jun 21, 2023

@Apromixately
Copy link

I agree with @AntonVucinic and #10130 running files as a module would be useful. When there is a bit of folder hierarchy, the only way to import something is to use modules. This could also be solved with some search/replace in the variables.

To give a bash example:

folder='foo/bar/baz'
echo ${folder//\//.}

gives foo.bar.baz which is pretty much what is needed here. Then this could be solved using:

{
    "name": "Python: Module",
    "type": "python",
    "request": "launch",
     "module": "${relativeFileDirname//\//.}.${fileBasenameNoExtension}",
    "justMyCode": true
}

Apologies if this seems like hijacking this issue but #10130 is closed.

@Apromixately
Copy link

Actually, there might be an easier way to solve this. Afaict from https://code.visualstudio.com/docs/editor/variables-reference#_command-variables, if this extension would define a getModule function we could use ${command:getModule}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments area-terminal feature-request Request for new features or functionality needs proposal Need to make some design decisions
Projects
None yet
Development

No branches or pull requests

7 participants