Skip to content

Commit a8790a2

Browse files
author
Scott TALLEC
committed
fix: replace @iarna/toml with smol-toml for TOML 1.0 and PEP 735 support
1 parent 8b60bbc commit a8790a2

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

packages/pyright-internal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test:coverage": "jest --forceExit --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html --coverageReporters=json"
1616
},
1717
"dependencies": {
18-
"@iarna/toml": "2.2.5",
18+
"smol-toml": "^1.6.1",
1919
"@yarnpkg/fslib": "2.10.1",
2020
"@yarnpkg/libzip": "2.2.4",
2121
"chalk": "^4.1.2",

packages/pyright-internal/src/analyzer/service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Python files.
99
*/
1010

11-
import * as TOML from '@iarna/toml';
11+
import * as TOML from 'smol-toml';
1212
import * as JSONC from 'jsonc-parser';
1313
import {
1414
AbstractCancellationTokenSource,
@@ -1072,9 +1072,9 @@ export class AnalyzerService {
10721072
private _parsePyprojectTomlFile(pyprojectPath: string): object | undefined {
10731073
return this._attemptParseFile(pyprojectPath, (fileContents, attemptCount) => {
10741074
try {
1075-
const configObj = TOML.parse(fileContents);
1076-
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) {
1077-
return (configObj.tool as TOML.JsonMap).pyright as object;
1075+
const configObj = TOML.parse(fileContents) as Record<string, any>;
1076+
if (configObj && configObj.tool && configObj.tool.pyright) {
1077+
return configObj.tool.pyright as object;
10781078
}
10791079
} catch (e: any) {
10801080
this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`);

packages/pyright-scip/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"webpack-cli": "^4.9.1"
4747
},
4848
"dependencies": {
49-
"@iarna/toml": "^2.2.5",
49+
"smol-toml": "^1.6.1",
5050
"command-exists": "^1.2.9",
5151
"commander": "^9.2.0",
5252
"diff": "^5.0.0",

packages/pyright-scip/src/config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as TOML from '@iarna/toml';
1+
import * as TOML from 'smol-toml';
22
import * as JSONC from 'jsonc-parser';
33
import { findPythonSearchPaths, getTypeShedFallbackPath } from 'pyright-internal/analyzer/pythonPathUtils';
44

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

435435
// Fall back to tool.pyright section
436-
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) {
437-
return (configObj.tool as TOML.JsonMap).pyright as object;
436+
if (configObj && configObj.tool && configObj.tool.pyright) {
437+
return configObj.tool.pyright as object;
438438
}
439439
} catch (e: any) {
440440
this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`);

packages/pyright-scip/src/indexer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as child_process from 'child_process';
22
import * as path from 'path';
3-
import * as TOML from '@iarna/toml';
3+
import * as TOML from 'smol-toml';
44
import { Event } from 'vscode-languageserver/lib/common/api';
55

66
import { Program } from 'pyright-internal/analyzer/program';
@@ -39,18 +39,18 @@ export class Indexer {
3939
try {
4040
const pyprojectTomlContents = getPyprojectTomlContents();
4141
if (pyprojectTomlContents) {
42-
const tomlMap = TOML.parse(pyprojectTomlContents);
42+
const tomlMap = TOML.parse(pyprojectTomlContents) as Record<string, any>;
4343
// See: https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#specification
44-
let project = tomlMap['project'] as TOML.JsonMap | undefined;
44+
let project = tomlMap['project'];
4545
if (project) {
4646
name = project['name'];
4747
version = project['version'];
4848
}
4949
if (!name || !version) {
5050
// See: https://python-poetry.org/docs/pyproject/
51-
let tool = tomlMap['tool'] as TOML.JsonMap | undefined;
51+
let tool = tomlMap['tool'];
5252
if (tool) {
53-
let toolPoetry = tool['poetry'] as TOML.JsonMap | undefined;
53+
let toolPoetry = tool['poetry'];
5454
if (toolPoetry) {
5555
name = name ?? toolPoetry['name'];
5656
version = version ?? toolPoetry['version'];

0 commit comments

Comments
 (0)