Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:coverage": "jest --forceExit --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html --coverageReporters=json"
},
"dependencies": {
"@iarna/toml": "2.2.5",
"smol-toml": "^1.6.1",
"@yarnpkg/fslib": "2.10.1",
"@yarnpkg/libzip": "2.2.4",
"chalk": "^4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Python files.
*/

import * as TOML from '@iarna/toml';
import * as TOML from 'smol-toml';
import * as JSONC from 'jsonc-parser';
import {
AbstractCancellationTokenSource,
Expand Down Expand Up @@ -1072,9 +1072,9 @@ export class AnalyzerService {
private _parsePyprojectTomlFile(pyprojectPath: string): object | undefined {
return this._attemptParseFile(pyprojectPath, (fileContents, attemptCount) => {
try {
const configObj = TOML.parse(fileContents);
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) {
return (configObj.tool as TOML.JsonMap).pyright as object;
const configObj = TOML.parse(fileContents) as Record<string, any>;
if (configObj && configObj.tool && configObj.tool.pyright) {
return configObj.tool.pyright as object;
}
} catch (e: any) {
this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-scip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"webpack-cli": "^4.9.1"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"smol-toml": "^1.6.1",
"command-exists": "^1.2.9",
"commander": "^9.2.0",
"diff": "^5.0.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/pyright-scip/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as TOML from '@iarna/toml';
import * as TOML from 'smol-toml';
import * as JSONC from 'jsonc-parser';
import { findPythonSearchPaths, getTypeShedFallbackPath } from 'pyright-internal/analyzer/pythonPathUtils';

Expand Down Expand Up @@ -427,14 +427,14 @@ export class ScipPyrightConfig {
return this._attemptParseFile(pyprojectPath, (fileContents, attemptCount) => {
try {
// First, try and load tool.scip section
const configObj = TOML.parse(fileContents);
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).scip) {
return (configObj.tool as TOML.JsonMap).scip as object;
const configObj = TOML.parse(fileContents) as Record<string, any>;
if (configObj && configObj.tool && configObj.tool.scip) {
return configObj.tool.scip as object;
}

// Fall back to tool.pyright section
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) {
return (configObj.tool as TOML.JsonMap).pyright as object;
if (configObj && configObj.tool && configObj.tool.pyright) {
return configObj.tool.pyright as object;
}
} catch (e: any) {
this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`);
Expand Down
10 changes: 5 additions & 5 deletions packages/pyright-scip/src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as child_process from 'child_process';
import * as path from 'path';
import * as TOML from '@iarna/toml';
import * as TOML from 'smol-toml';
import { Event } from 'vscode-languageserver/lib/common/api';

import { Program } from 'pyright-internal/analyzer/program';
Expand Down Expand Up @@ -39,18 +39,18 @@ export class Indexer {
try {
const pyprojectTomlContents = getPyprojectTomlContents();
if (pyprojectTomlContents) {
const tomlMap = TOML.parse(pyprojectTomlContents);
const tomlMap = TOML.parse(pyprojectTomlContents) as Record<string, any>;
// See: https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#specification
let project = tomlMap['project'] as TOML.JsonMap | undefined;
let project = tomlMap['project'];
if (project) {
name = project['name'];
version = project['version'];
}
if (!name || !version) {
// See: https://python-poetry.org/docs/pyproject/
let tool = tomlMap['tool'] as TOML.JsonMap | undefined;
let tool = tomlMap['tool'];
if (tool) {
let toolPoetry = tool['poetry'] as TOML.JsonMap | undefined;
let toolPoetry = tool['poetry'];
if (toolPoetry) {
name = name ?? toolPoetry['name'];
version = version ?? toolPoetry['version'];
Expand Down