Skip to content

Fix problems with a python kernel not handling json with numbers#12293

Merged
rchiodo merged 5 commits into
masterfrom
rchiodo/env_problems
Jun 11, 2020
Merged

Fix problems with a python kernel not handling json with numbers#12293
rchiodo merged 5 commits into
masterfrom
rchiodo/env_problems

Conversation

@rchiodo
Copy link
Copy Markdown

@rchiodo rchiodo commented Jun 11, 2020

For #11749

Essentially if you have this:

{
  "argv": [
    "C:\\Users\\rchiodo.REDMOND\\AppData\\Local\\Continuum\\miniconda3\\envs\\test36\\python.exe",
    "-m",
    "ipykernel_launcher",
    "-f",
    "{connection_file}"
  ],
  "display_name": "Python Test",
  "language": "python",
  "env": {
    "GOOFY_VAR_2": 2222
  }
}

A kernel will fail on startup saying non string environment is not allowed. THis might only happen with 3.7 and earlier, but easier to just prevent this.

// tslint:disable-next-line: no-var-requires no-require-imports
const NamedRegexp = require('named-js-regexp') as typeof import('named-js-regexp');

import { JSONObject } from '@phosphor/coreutils';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this type? Why not just use any or {} or similar.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess not. Any is essentially the same thing

Copy link
Copy Markdown

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd try to remove the use of @phosphor/coreutils.

// Scrub the environment of the specmodel to make sure it has allowed values (they all must be strings)
// See this issue here: https://github.com/microsoft/vscode-python/issues/11749
if (specModel.env) {
specModel = cleanEnvironment(specModel);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass the specModel.env instead of passing specModel, at the end of the day that's what needs to be cleane dup.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the above comment, I know now why its required.

// See this issue here: https://github.com/microsoft/vscode-python/issues/11749
const keys = Object.keys(copy.env);
keys.forEach((k) => {
if (copy.env) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don' think this check is required.

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rchiodo rchiodo merged commit daa467d into master Jun 11, 2020
@rchiodo rchiodo deleted the rchiodo/env_problems branch June 11, 2020 23:56
@lock lock Bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants