-
Notifications
You must be signed in to change notification settings - Fork 301
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
python.dataScience.notebookFileRoot
needs an option to launch with CWD = current file path
#3605
Comments
@fkjogu The notebookFileRoot setting does do some, but not all of what you are looking for. The VSCode variables are specific to task and debug configuration files (launch.json and task.json). We've specifically added code to recognize ${workspaceFolder} for our settings page but we don't recognize other VSCode variables in there. So you can put a specific path in there (and save it at the workspace level to affect only that folder) but you can't use ${fileDirname} in there to always get the path of the file. While we don't currently support that I do think that this could be a reasonable option (currently vscode defaults to the workspace root as cwd, which we copied while Jupyter defaults to the path of the file) so I'm keeping this issue open to look into that. |
python.dataScience.notebookFileRoot
is not respected in the interactive sessionpython.dataScience.notebookFileRoot
needs an option to launch with CWD = current file path
I did change the title quick to make it more clear the work that we are considering. |
What is the reason behind not regocognizing the built-in variables? I kinda expected them to work everywhere in the settings. |
@fkjogu I'm not fully sure on the reasoning for VSCode as a whole not supporting this. But it is specifically mentioned here: They are not created for use in the settings files. For the python extension we just specifically had use for ${workspaceFolder} so we coded up manually tracking the current workspace folder as part of our extension so that we could use it in our settings. |
it always get first dir when there are many dir,but set "python.dataScience.notebookFileRoot": "${workspaceFolder}/dd",it will change dd dir. |
Yes please. When working interactively, I always want the kernel to start in the directory of the file I'm executing. If it is starting elsewhere it will mess up my imports unless I add file's directory to PATH manually.. |
yes please(!) I love to work with python files directly instead of the notebook format, but Ive multiple times forgot to remove the changedir commands at the start. Or if Im starting a new python file I need to remember the command. Could a possible fix be something like "if opening interactive window from a file (through shift+enter), do the folder changing command as the first command"? |
yes - this would be helpful |
+1 on this, launching with current file path wont make imports a mess possible related #3141 |
Most likely it only worked for you by chance. The kernel seems to start in the directory of the project that appears first in your explorer. Did you only have one project? For me it still doesnt work, with or without variables set in Notebook File Root. |
This should be in our current release. |
Could you confirm once this is released and what the exact setting should be to launch with cwd? It doesn't seem to work yet in version 1.39.2 using |
I change "python.dataScience.notebookFileRoot" to |
It seems to work as expected (with v2019.10.44104) when launching the interactive window for the first time since opening VS Code. But if I want to then use the interactive window from a python file in another folder, the root directory does not change, even after closing the interactive window tab. For the root directory to change to the new cwd you have to interrupt/restart the kernel (or close VS Code). |
Yes we don't restart the kernel when closing the interactive window. Maybe we should. We do that for notebooks. |
We also have a work item to allow 1 interactive window per file started. That would also alleviate this problem. |
Environment data
Expected behaviour
Having a Python script with cell markers
#%%
, I'd expect that settingpython.dataScience.notebookFileRoot = ${fileDirname}
makes the interactive session start in the directory the file resides.Maybe I misunderstand that setting? At least, it is what
calculateWorkingDirectory
is supposed to do, isn't it?Also see this Stack Overflow question
Actual behaviour
The interactive session starts from the workspace directory.
Steps to reproduce:
Having a structure like this
and a
file.py
:the output in the interactive session is the absolute path of the
workingDir
.The text was updated successfully, but these errors were encountered: