Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .changeset/itchy-countries-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@plutolang/pyright-deducer": patch
---

fix(deducer): correct package directory resolution and METADATA parsing

This commit addresses two separate issues identified in the deducer:

- The deducer incorrectly searched for distribution information within the stub type directory, which lacks the required dist info. The resolution has been updated to check for the presence of `nonStubImportResult` within the `ImportResult`. If present, it is now utilized to determine the correct package directory.
- The parsing of the `dist-info/METADATA` file was flawed due to the possibility of encountering multiple `Name` lines. The parser has been adjusted to only consider lines that begin with `Name:` and are not preceded by any spaces.
22 changes: 11 additions & 11 deletions components/deducers/python-pyright/src/import-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class ImportVisitor extends ParseTreeWalker {
}

function getModulePath(module: ImportResult) {
if (module.nonStubImportResult) {
module = module.nonStubImportResult;
}

const dirpath = module.packageDirectory?.key;
const filepath = module.resolvedUris.length > 0 ? module.resolvedUris[0].key : undefined;
return dirpath || filepath;
Expand Down Expand Up @@ -293,17 +297,13 @@ function getAllDistInfos(pkgPath: string): DistInfo[] {
// Read the "METADATA" file to get the distribution's name and version.
const metadataPath = path.join(pkgPath, distInfoDirName, "METADATA");
const metadata = fs.readFileSync(metadataPath);
const lines = metadata.toString().split("\n");
for (const line of lines) {
const [key, value] = line.split(":");
switch (key.trim()) {
case "Name":
distName = value.trim();
break;
case "Version":
distVersion = value.trim();
break;
}

// Fetch the name and version from the "METADATA" file using RegExp.
const nameMatch = metadata.toString().match(/^Name: (.*)/m);
const versionMatch = metadata.toString().match(/^Version: (.*)/m);
if (nameMatch && versionMatch) {
distName = nameMatch[1].trim();
distVersion = versionMatch[1].trim();
}

if (!distName || !distVersion) {
Expand Down