Skip to content

${workspaceFolder} & . not being resolved in settings in some cases #11671

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

Closed
karrtikr opened this issue May 7, 2020 · 5 comments
Closed

${workspaceFolder} & . not being resolved in settings in some cases #11671

karrtikr opened this issue May 7, 2020 · 5 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@karrtikr
Copy link

karrtikr commented May 7, 2020

Resolving ${workspaceFolder}

Having

     "python.testing.unittestArgs": [
        "-p",
        "*test.py",
        "-s",
        "${workspaceFolder}/src",
    ]

instead of

     "python.testing.unittestArgs": [
        "-p",
        "*test.py",
        "-s",
        "./src",
    ]

doesn't work.

Resolving .

This problem arises when using forward slashes in path.

"python.pythonPath": "./.venv/Scripts/python.exe" doesn't work but "python.pythonPath": ".\\.venv\\Scripts\\python.exe" does.

     "python.testing.unittestArgs": [
        "-p",
        "*test.py",
        "-s",
        "./src",
    ],
    "python.testing.cwd": "./test"

doesn't search for tests in ./test/src directory

@karrtikr karrtikr added bug Issue identified by VS Code Team member as probable bug needs PR area-testing triage-needed Needs assignment to the proper sub-team regression Bug didn't exist in a previous release labels May 7, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 7, 2020
@martingbrown

This comment has been minimized.

@karrtikr

This comment has been minimized.

@karrtikr karrtikr changed the title ${workspaceFolder} & . not being resolved in testing settings ${workspaceFolder} & . not being resolved in settings in some cases Jul 30, 2020
@karrtikr
Copy link
Author

karrtikr commented Jul 30, 2020

This problem arises when using forward slashes in path.

For this particular case, we use child_process.exec which uses cmd shells to run ./.venv/Scripts/python.exe which fails, hence we're not able to resolve relative paths with forward slashes. However using full path with forward slashes work. Two possible solutions,

  • Use child_process.spawn to run commands which return the result, which apparently doesn't use shell (?) cc @int19h
  • Resolve all relative paths to absolute before using them. This is already being done, except for cases where the relative path contains forward slashes on Windows.

function getAbsolutePath(pathToCheck: string, rootDir: string | undefined): string {
if (!rootDir) {
rootDir = __dirname;
}
// tslint:disable-next-line:prefer-type-cast no-unsafe-any
pathToCheck = untildify(pathToCheck) as string;
if (isTestExecution() && !pathToCheck) {
return rootDir;
}
if (pathToCheck.indexOf(path.sep) === -1) {
return pathToCheck;
}
return path.isAbsolute(pathToCheck) ? pathToCheck : path.resolve(rootDir, pathToCheck);
}

We can change this line

if (pathToCheck.indexOf(path.sep) === -1) {

to

if (pathToCheck.indexOf('\\') === -1 || pathToCheck.indexOf('/') === -1) {

@int19h
Copy link

int19h commented Jul 30, 2020

The real problem here is command line escaping, or lack thereof. Briefly, in cmd.exe, for historical reasons, the following is valid:

del/s/q foo

and is the same as:

del /s /q foo

There are many convoluted rules there that affect this behavior, and it's not really worthwhile trying to figure them all out. We should just avoid APIs like exec() that take command line argument as a single string - those should do appropriate quoting.

So, basically, always either execFile() or spawn() (with shell: true if needed - it defaults to false for both). But exec() should be an extremely rare case - I doubt we have any scenarios where it's necessary. Any scenario that does justify it, also justifies a lengthy code comment explaining why it's needed :)

And shell: true should only be set if needed, because it's expensive to spawn shells, and they introduce more moving bits that can potentially fail. Like, in this case, it would be needed because we're running a batch script on Windows (but perhaps we can avoid that?).

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@eleanorjboyd eleanorjboyd self-assigned this Dec 4, 2023
@eleanorjboyd
Copy link
Member

Tried this and it is working for me on the rewrite, please reopen if this is not the case and anyone thinks the problem still exists.

Thanks

@github-actions github-actions bot removed the needs PR Ready to be worked on label Dec 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

4 participants