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

REPL doesn’t work when the python file is in nested folder #23656

Open
rebornix opened this issue Jun 23, 2024 · 8 comments
Open

REPL doesn’t work when the python file is in nested folder #23656

rebornix opened this issue Jun 23, 2024 · 8 comments
Assignees
Labels
area-repl feature-request Request for new features or functionality needs community feedback Awaiting community feedback

Comments

@rebornix
Copy link
Member

Type: Bug

My python file is in a sub folder nested/test.py and there is a csv file next to it nested/data.csv, however if I try to load the file with relative path "data.csv", it only works if I use "nested/data.csv".

I was expecting the relative path to just work. However if this is as designed, I would love to have a setting to set the cwdto the parent folder of the python file when using it in REPL.

Extension version: 2024.9.11731014
VS Code version: Code - Insiders 1.91.0-insider (Universal) (63d06667600a2c40245a0ab1f9e2ea816d2fe849, 2024-06-21T10:24:54.816Z)
OS version: Darwin arm64 23.5.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

testing
• promptToConfigure: false

Installed Extensions
Extension Name Extension Id Version
Dev Containers ms-vscode-remote.remote-containers 0.373.0
EditorConfig for VS Code EditorConfig.EditorConfig 0.16.4
ESLint dbaeumer.vscode-eslint 3.0.10
Extension Test Runner ms-vscode.extension-test-runner 0.0.9
Flame Chart Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-flame 1.0.9
GitHub Copilot GitHub.copilot 1.205.0
GitHub Copilot Chat GitHub.copilot-chat 0.17.2024062101
GitHub Issue Notebooks ms-vscode.vscode-github-issue-notebooks 0.0.130
GitHub Pull Requests GitHub.vscode-pull-request-github 0.91.2024062004
GitHub Theme GitHub.github-vscode-theme 6.3.4
GitLens — Git supercharged eamodio.gitlens 2024.6.2205
JavaScript Debugger ms-vscode.js-debug 1.90.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.2
Jupyter ms-toolsai.jupyter 2024.6.2024062001
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.18
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Markdown Checkboxes bierner.markdown-checkbox 0.4.0
Markdown Preview Github Styling bierner.markdown-preview-github-styles 2.0.4
Mocha Test Explorer hbenl.vscode-mocha-test-adapter 2.14.1
Node.js Notebooks (REPL) donjayamanne.typescript-notebook 2.0.6
Nord arcticicestudio.nord-visual-studio-code 0.19.0
PR Pinger jrieken.vscode-pr-pinger 0.0.6
Prettier - Code formatter esbenp.prettier-vscode 10.4.0
Pylance ms-python.vscode-pylance 2024.6.101
Python ms-python.python 2024.9.11731014
Python Debugger ms-python.debugpy 2024.7.11591012
Ruff charliermarsh.ruff 2024.28.0
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Test Adapter Converter ms-vscode.test-adapter-converter 0.1.9
Test Explorer UI hbenl.vscode-test-explorer 2.21.1
System Info
Item Value
CPUs Apple M3 Max (14 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 3, 2, 2
Memory (System) 36.00GB (0.07GB free)
Process Argv --enable-proposed-api rebornix.anyllm --enable-proposed-api rebornix.lulu --crash-reporter-id 1ce5da70-91d5-46fb-a706-70ff08933f9c
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
vsaa593:30376534
py29gd2263:31024238
c4g48928:30535728
a9j8j154:30646983
962ge761:30841072
pythongtdpath:30726887
welcomedialog:30812478
pythonnoceb:30776497
asynctok:30898717
dsvsc013:30777762
dsvsc014:30777825
dsvsc015:30821418
pythonregdiag2:30926734
pythonmypyd1:30859725
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30870582
dsvsc016:30879898
dsvsc017:30880771
dsvsc018:30880772
cppperfnew:30980852
pythonait:30973460
jchc7451:31067543
showvideot:31016890
chatpanelt:31014475
g316j359:31013175
a69g1124:31018687
dvdeprecation:31040973
dwnewjupyter:31046869
impr_priority:31057980
nativerepl2:31071685

@anthonykim1
Copy link

This is weird - does print(os.getcwd()) yield / for you as well? Ideally it should be the workspace path.. trying to think of why we only get this in the new native repl vs. terminal repl.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 9, 2024
@saurabhbikram
Copy link

This is weird - does print(os.getcwd()) yield / for you as well? Ideally it should be the workspace path.. trying to think of why we only get this in the new native repl vs. terminal repl.

I can confirm i have the same issue, and print(os.getcwd()) does indeed yield /

setting "python.REPL.sendToNativeREPL":false i get the correct working directory in the 'old' terminal.

@Anstetten
Copy link

This is weird - does print(os.getcwd()) yield / for you as well? Ideally it should be the workspace path.. trying to think of why we only get this in the new native repl vs. terminal repl.

I am facing the same issue. It spawns in the wrong working directory.
It "thinks" it is in the right directory (provides autocomplete for stuff like import backend.components.blabla) but importing anything fails.

@anthonykim1
Copy link

anthonykim1 commented Aug 6, 2024

Hey folks, good news here: working to get this resolved this month :)
As in directory context for REPL should be set properly when users launch REPL, similar to how terminal is able to pull up current working directory.
If user is inside multi-root directory we would show options for user to select which directory to use, but otherwise in a more common one workspace directory, we would automatically just set that as a cwd.

Will let you all know once I merge in the changes so you can try it all out. Thanks!

@anthonykim1
Copy link

@rebornix As far as settings to straight up let the users set their cwd for REPL, I think that would be feature request.
I think the default directory/workspace behavior should be same as Terminal as a baseline regardless.

Not too sure about the setting as folks could just

os.chdir(new_dir)

and set their cwd if they want to override the default workspace directory setting.

@anthonykim1 anthonykim1 added bug Issue identified by VS Code Team member as probable bug area-repl and removed info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels Aug 6, 2024
@anthonykim1 anthonykim1 added this to the August 2024 milestone Aug 6, 2024
@anthonykim1
Copy link

Let's track the bug here: #23821
and I'll change this to feature request as in wanting for explicit setting to set directory for REPL even in single workspace scenario.

@anthonykim1 anthonykim1 added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Aug 6, 2024
@anthonykim1 anthonykim1 removed this from the August 2024 milestone Aug 6, 2024
@anthonykim1 anthonykim1 added the needs community feedback Awaiting community feedback label Aug 6, 2024
Copy link

github-actions bot commented Aug 6, 2024

Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

anthonykim1 added a commit that referenced this issue Aug 7, 2024
Resolves: #23727 

Allow users to launch Native REPL via command palette.

Will also be handling
#23821 in this PR. --
setting proper workspace directory.
Related: #23656 

Covering scenarios:
- Provide selection option if user is in multi-workspace scenario
(already included in PR)
- Automatically pick workspace as directory for context of REPL if user
is in single-workspace scenario (already included in PR)
- Handle case where user does not open any workspace and attempt to
launch native REPL from plain/empty VS Code instance via command palette
option (already included in PR)
@anthonykim1
Copy link

Hi folks. As promisedm we are NOW setting the directory properly for 3 different scenarios as a result of #23912 (got merged about two days ago), so please give this a try after updating to the latest pre-release version of Python extension.

3 different scenario should cover:

  1. Single workspace scenario
  2. Multi workspace scenario (we will give you quick selection option)
  3. No workspace scenario (empty vs code)
print(os.getcwd())

should yield expected workspace directory, following same trend as terminal.

As far as OPTION to more explicitly choose directory for REPL launch (if you think the result of PR is not enough), please give this issue an upvote so we can see the interest.

FYI

os.chdir('/path/to/your/desired/directory') 

will also allow you to easily navigate through whichever subdirectory or directory of your chose if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-repl feature-request Request for new features or functionality needs community feedback Awaiting community feedback
Projects
None yet
Development

No branches or pull requests

4 participants