Skip to content

python.terminal.executeInFileDir doesn't work if file is on another drive from working directory #14730

Description

Environment data

  • VS Code version: 1.51.1
  • Extension version (available under the Extensions sidebar): 2020.11.358366026
  • OS and version: Windows 10.0.19042
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.6.12 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: NA
  • Relevant/affected Python-related VS Code extensions and their versions: NA
  • Value of the python.languageServer setting: Pylance

Expected behaviour

Expect that if the file directory is on a different drive to the working directory and "python.terminal.executeInFileDir" is set to true, that the terminal will change drive, then change directory, then run python file

Actual behaviour

Terminal opens, changes directory and then runs python file

Steps to reproduce:

  1. Have python.terminal.executeInFileDir = True
  2. Open python file on drive other than working directory
  3. Run python file in terminal

Terminal will open, run the 'cd FileDir' command but not change drive, and then run the python file

Related Code

Related code appears to be in terminalCodeExecution.ts

if ((!wkspace || fileDirPath !== wkspace.uri.fsPath) && fileDirPath.length > 0) { await this.getTerminalService(file).sendText(`cd ${fileDirPath.fileToCommandArgument()}`); }

Activity

  1. added
    triage-needed
    bug
    on Nov 13, 2020
  2. ghost removed
    triage-needed
    on Nov 16, 2020
  3. karthiknadig commented on Nov 16, 2020

    @karthiknadig
    Member

    peachthief (@peachthiefmedia) Thanks for identifying the issue. Yes, this is a problem if the file you are tying to use is on a different drive.

  4. karrtikr commented on Oct 22, 2021

    @karrtikr

    The issue is here:

    . Identify if it's in a different drive and then figure out what command to send accordingly. For eg. if workspace folder is currently on c: drive, and file to run is on d:. Send d: to terminal to switch the drive first. (details)

  5. afikrim commented on Oct 28, 2021

    @afikrim

    I'd like to start solving this issue

  6. added
    verification-needed
    on Oct 30, 2021
  7. locked as resolved and limited conversation to collaborators on Nov 30, 2021
  8. karthiknadig commented on Dec 1, 2021

    @karthiknadig
    Member

    Verification steps:

    1. You will need a windows machine with two drives, you can use a USB drive as the second drive.
    2. Set python.terminal.executeInFileDir = True
    3. Open a workspace in say "C:" drive.
    4. Open a python file in the same VS Code window, but the file should be in say "D:" drive
    5. Run the python file using the "Run python file" button at the top right of the editor tab.

    Extension should switch to the drive where the file exists, and then to the directory where the file exists, and finally execute the file.

  9. karthiknadig commented on Dec 1, 2021

    @karthiknadig
    Member

    I see an issue here, running a file in a different drive works. but then when you run a file in the same dir as the workspace, it does not work. It does not restore the directory.

    After step 5 of verification, run a python file from the workspace. it sends a cd but not a drive change.

  10. added
    verification-found
    and removed
    verification-needed
    on Dec 1, 2021
  11. added
    triage-needed
    on Dec 1, 2021
  12. removed
    triage-needed
    on Dec 2, 2021
  13. added
    verification-needed
    and removed
    verification-found
    on Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbuggood first issueverification-needed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions