posit-dev / posit-dev/positron
"Run Python File in Console" button has different behavior than running the script manually
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 184
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 206
Description
When you press the run button in the top right of a python file it sends that file to the "console" to be run using the %run magic. This does effectively run the code but has a couple differences compared to doing something selecting the whole file and command + entering it.
- The run code is labeled as non-interactive. Thus things like plots can behave differently and often won't show up. See #5991 for example.
- The run code does not have access to the namespace of the session. However, it does modify that namespace after running with whatever definitions were made in the script. This behavior makes sense for doing things like loading modules etc but can be pretty confusing when it errors trying to read a variable that you can see in the variable explorer. As a note, this one can be 'fixed' by running with the
-iflag
Runs just fine if all code is selected and run
Potential solutions:
I think there are a few ways to go about this.
- Add the
-iflag to enables to be seen by run code - Send code to console directly instead of using the magic
- Either putting this new behavior or the previous behavior behind a feature flag.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the difference between the “Run Python File in Console” button and selecting the file and running it manually. Trace the button’s use of the %run magic and compare its interactive and namespace behavior with the issue’s examples. Done means the chosen behavior is consistent for plots and access to existing session variables, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100