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

python.terminal.executeInFileDir doesn't seem to have any effect #1062

Closed
jkyeung opened this issue Mar 13, 2018 · 6 comments
Closed

python.terminal.executeInFileDir doesn't seem to have any effect #1062

jkyeung opened this issue Mar 13, 2018 · 6 comments
Assignees
Labels
area-terminal feature-request Request for new features or functionality

Comments

@jkyeung
Copy link

jkyeung commented Mar 13, 2018

Environment data

  • VS Code version: 1.21.0
  • Extension version (available under the Extensions sidebar): 2018.2.1
  • OS and version: Windows 7 Pro
  • Python version: 3.6.2, 64-bit
  • Type of virtual environment used (if applicable): N/A
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

When I issue the command Python: Run Python File in Terminal, it always starts in the open folder, rather than in the file directory, despite the fact that I have "python.terminal.executeInFileDir": true in my user settings.

This has been a problem since forever; this setting has never worked for me on any previous version.

Expected behavior

The terminal starts in the file directory of the Python script I'm executing.

Steps to reproduce:

  1. Open a Python source file.
  2. Use the command palette to issue Python: Run Python File in Terminal.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

I don't understand those instructions. If I do ViewOutput, there is no Python in the drop-down. However, there is a Python in the terminal. (If this is what you mean, then the template for the bug report should reflect that.)

Suffice it to say that within the Python script, os.getcwd() is the open folder, when I am expecting it to be the same as sys.path[0] instead.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

This is empty, unless I choose Verbose.

@DonJayamanne
Copy link

I'm unable to replicate this at my end.

I don't understand those instructions. If I do View→Output, there is no Python in the drop-down

This is where you need to look for it.
screen shot 2018-03-13 at 11 51 42 am

Please could you:

  • Send a copy of your .vscode/settings.json
  • Screenshot of the terminal window when you run the python file using the command Python: Run Python File in Terminal.

The terminal should have a command that'll set the path to the directory containing the script file. I'd like to check what's output into the terminal window.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster area-terminal labels Mar 13, 2018
@jkyeung
Copy link
Author

jkyeung commented Mar 13, 2018

settings.json:

{
    // "editor.fontFamily": "Consolas, 'Courier New', monospace",
    "editor.fontFamily": "Verdana",
    // "editor.fontSize": 16,
    "terminal.integrated.fontFamily": "Consolas",
    "editor.suggestOnTriggerCharacters": false,
    "editor.acceptSuggestionOnEnter": "off",
    "editor.find.autoFindInSelection": true,
    "python.formatting.provider": "none",
    "python.linting.enabled": false,
    "python.terminal.executeInFileDir": true,
    "files.autoSave": "off",
    "files.trimTrailingWhitespace": true,
    "files.insertFinalNewline": true,
    "editor.renderWhitespace": "none",
    "editor.renderControlCharacters": false,
    "editor.renderLineHighlight": "all",
    "editor.rulers": [80],
    "editor.autoClosingBrackets": false,
    "editor.minimap.showSlider": "always",
    "editor.cursorStyle": "line-thin",
    "workbench.colorTheme": "Solarized Dark",
    "workbench.colorCustomizations": {
        "editorCursor.foreground": "#44ffaacc",
        "editor.selectionBackground": "#ffdddd3a",
        "editor.selectionHighlightBackground": "#0088aa2a",
        "editorWhitespace.foreground": "#ffffff2a",
        "editorLineNumber.foreground": "#608070"
    },
    "editor.tokenColorCustomizations": {
        "numbers": "#40c0c0",
        "textMateRules": [
            {
                "name": "Default",
                "scope": [
                    "source",
                    "variable.parameter",
                    "entity.other.inherited-class",
                    "constant.other", // all-caps "constant"
                    "meta.function-call"
                ],
                "settings": {
                    "foreground": "#cccccc"
                }
            },
            {
                "name": "Keywords",
                "scope": [
                    "keyword",
                    "keyword.operator.logical",
                    "storage.type.function", // `def` and `lambda`
                    "storage.type.class", // `class`
                    "storage.modifier.declaration" // `global`, `nonlocal`
                ],
                "settings": {
                    "fontStyle": "",
                    "foreground": "#cccc60"
                }
            },
            {
                "name": "Operators",
                "scope": "keyword.operator",
                "settings": {
                    "foreground": "#dddddd"
                }
            },
            {
                "name": "Decorators",
                "scope": "entity.name.function.decorator",
                "settings": {
                    "fontStyle": "",
                    "foreground": "#bb6000"
                }
            },
            {
                "name": "Functions",
                "scope": "entity.name.function",
                "settings": {
                    "fontStyle": "bold"
                }
            },
            {
                "name": "Classes",
                "scope": "entity.name.type",
                "settings": {
                    "fontStyle": "bold",
                    "foreground": "#60d296"
                }
            },
            {
                "name": "Self",
                "scope": "variable.language.special",
                "settings": {
                    "foreground": "#aaaadd"
                }
            },
            {
                "name": "Built-in dunder methods",
                "scope": "support.function.magic",
                "settings": {
                    "fontStyle": "bold",
                    "foreground": "#8888dd"
                }
            },
            {
                "name": "Built-in functions",
                "scope": "support.function",
                "settings": {
                    "foreground": "#8888dd"
                }
            },
            {
                "name": "Type",
                "scope": "support.type",
                "settings": {
                    "foreground": "#60bb80"
                }
            },
            {
                "name": "Constant",
                "scope": "constant.language",
                "settings": {
                    "foreground": "#ccaa00"
                }
            },
            {
                "name": "Comments",
                "scope": "comment",
                "settings": {
                    "foreground": "#808080"
                }
            },
            {
                "name": "Formats",
                "scope": "storage.type.format",
                "settings": {
                    "fontStyle": "",
                    "foreground": "#66cc66"
                }
            }
        ]
    },
    // "python.pythonPath": "C:\\Users\\jyeung\\AppData\\Local\\Programs\\Python\\Launcher\\py",
    "python.pythonPath": "py",
    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python",
                "type": "python",
                "request": "launch",
                "stopOnEntry": false,
                "pythonPath": "${config:python.pythonPath}",
                "program": "${relativeFile}",
                "cwd": "",
                "env": {},
                "envFile": "${workspaceRoot}/.env",
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit",
                    "RedirectOutput"
                ]
            }
        ]
    },
    // "editor.matchBrackets": false,
    // "subtleBrackets.styles": {
    //     "global": {
    //         "borderWidth": "1px",
    //         "borderStyle": "none none solid none"
    //     }
    // },
    // "bracketPairColorizer.consecutivePairColors": [
    //     "()",
    //     "[]",
    //     "{}",
    //     [
    //         "#cccccc"
    //     ],
    //     "Red"
    // ],
    "bracketPairColorizer.colorMode": "Independent",
    "bracketPairColorizer.independentPairColors": [
        [
            "()",
            [
                "#cccccc"
            ],
            "Red"
        ],
        [
            "[]",
            [
                "#cccccc"
            ],
            "Red"
        ],
        [
            "{}",
            [
                "#cccccc"
            ],
            "Red"
        ]
    ],
    "editor.multiCursorModifier": "ctrlCmd"
}

Screenshot to illustrate that I really don't have Python in output:

no python in output

Screenshot to show Python in terminal:

python in terminal

@DonJayamanne
Copy link

Ok, here's the problem, the file you have opened is not part of the workspace, hence the settings for the workspace are not getting picked up.

We'll have to introduce a change to get this feature working.

@DonJayamanne DonJayamanne added needs PR and removed info-needed Issue requires more information from poster bug Issue identified by VS Code Team member as probable bug labels Mar 13, 2018
@DonJayamanne
Copy link

DonJayamanne commented Mar 13, 2018

@brettcannon @qubitron
Here's a summary of the issue:

  • Open a workspace 'a'
  • Enable the setting "python.terminal.executeInFileDir"
  • Open a file that does not belong to the above workspace
  • Execute the file using Python: Run Python File in Terminal

Current behavior

  • If file does not belong to the workspace then we're not setting the current directory

Proposed behavior

  • If file does not belong to the workspace then set the current directory

I'm not sure why, but we currently have tests to avoid this particular situation (possibly a test to retain the behavior inherited from old code).

@brettcannon
Copy link
Member

To help manage our issues and to better communicate what the team plans to work on we are closing issues that we don't plan to work on but would accept a pull request from a volunteer for. To be clear, closing this issue does not mean we won't consider a pull request for this enhancement as outlined in our contributing guide, just that the development team has no plans to work on it themselves.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 18, 2018
@DonJayamanne DonJayamanne reopened this Jul 18, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jul 18, 2019
@DonJayamanne DonJayamanne added this to the 2019 - July Sprint 14 milestone Jul 18, 2019
@DonJayamanne DonJayamanne added unplanned and removed triage-needed Needs assignment to the proper sub-team labels Jul 18, 2019
@kimadeline
Copy link

✅ validated

@ghost ghost removed the needs PR label Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants