Skip to content

Commit

Permalink
fix[PyProject.toml]: Fixed incorrect node linking in dependency graph. (
Browse files Browse the repository at this point in the history
  • Loading branch information
kadirkaang authored Jul 26, 2024
1 parent 1bfe646 commit 6b81218
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 32 deletions.
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to the "dependi" extension will be documented in this file.

- Fixed resolved issue where outdated packages appeared as up-to-date. [Issue #60](https://github.com/filllabs/dependi/issues/60)

- Fixed incorrect node linking in dependency graph. [Issue #66](https://github.com/filllabs/dependi/issues/66)

## 0.7.5

### Bug Fixes
Expand Down
42 changes: 41 additions & 1 deletion vscode/src/core/parsers/PyProjectParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Settings } from "../../config";
import Item from "../Item";
import { State, TomlParser } from "./TomlParser";
import { clearText, isBoolean, parsePackage, parseVersion, State, TomlParser } from "./TomlParser";

export class PyProjectParser extends TomlParser {
constructor() {
Expand All @@ -19,4 +19,44 @@ export class PyProjectParser extends TomlParser {
items.push(state.currentItem);
state.currentItem = new Item();
}

parsePair(line: string, row: number): Item | undefined {
const item = new Item();
let eqIndex = line.indexOf("=");
if (eqIndex === -1) {
return undefined;
}
row = eqIndex + 1;
const commentIndex = line.indexOf("#");
item.key = clearText(line.substring(0, eqIndex));
item.key = item.key.replace(".version", "");
item.value = clearText(
line.substring(eqIndex + 1, commentIndex > -1 ? commentIndex : line.length)
);
if (isBoolean(item.value) || item.value.includes("path")) {
return undefined;
}
if (line.indexOf("{") > -1) {
// json object
parsePackage(line, item);
parseVersion(line, item);
return item.start > -1 ? item : undefined;
}

item.start = line.indexOf(item.value);
item.end = item.start + item.value.length;

if (line[eqIndex - 1] === "~" || line[eqIndex - 1] === ">") {
let lastIndexOf = item.value.lastIndexOf(".");
const lastString = item.value.substring(lastIndexOf + 1);
if (isNaN(parseInt(lastString[0]))) {
lastIndexOf = item.value.substring(0, lastIndexOf).lastIndexOf(".");
}
if (lastIndexOf > -1) {
item.value = item.value.substring(0, lastIndexOf) + ".*";
}
}

return item.start > -1 ? item : undefined;
}
}
62 changes: 31 additions & 31 deletions vscode/src/core/parsers/TomlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class TomlParser implements Parser {
}
if (state.isMultipleDepTable) {
// if it is multiple dependency table, we need to read pairs until we find another table
const pair = parsePair(line.text, row);
const pair = this.parsePair(line.text, row);
if (!pair) {
continue;
}
Expand All @@ -86,7 +86,7 @@ export class TomlParser implements Parser {
continue;
} else {
// we neet 2 things, version and package name from next rows until we find another table
const pair = parsePair(line.text, row);
const pair = this.parsePair(line.text, row);
if (!pair) {
continue;
}
Expand Down Expand Up @@ -127,37 +127,37 @@ export class TomlParser implements Parser {
items.push(state.currentItem);
state.currentItem = new Item();
}
}

function parsePair(line: string, row: number): Item | undefined {
const item = new Item();
let eqIndex = line.indexOf("=");
if (eqIndex === -1) {
return undefined;
}
row = eqIndex + 1;
const commentIndex = line.indexOf("#");
item.key = clearText(line.substring(0, eqIndex));
item.key = item.key.replace(".version", "");
item.value = clearText(
line.substring(eqIndex + 1, commentIndex > -1 ? commentIndex : line.length)
);

if (isBoolean(item.value) || item.value.includes("path")) {
return undefined;
}
if (line.indexOf("{") > -1) {
// json object
parsePackage(line, item);
parseVersion(line, item);
parsePair(line: string, row: number): Item | undefined {
const item = new Item();
let eqIndex = line.indexOf("=");
if (eqIndex === -1) {
return undefined;
}
row = eqIndex + 1;
const commentIndex = line.indexOf("#");
item.key = clearText(line.substring(0, eqIndex));
item.key = item.key.replace(".version", "");
item.value = clearText(
line.substring(eqIndex + 1, commentIndex > -1 ? commentIndex : line.length)
);

if (isBoolean(item.value) || item.value.includes("path")) {
return undefined;
}
if (line.indexOf("{") > -1) {
// json object
parsePackage(line, item);
parseVersion(line, item);
return item.start > -1 ? item : undefined;
}
item.start = line.indexOf(item.value);
item.end = item.start + item.value.length;
return item.start > -1 ? item : undefined;
}
item.start = line.indexOf(item.value);
item.end = item.start + item.value.length;
return item.start > -1 ? item : undefined;
}

function parseVersion(line: string, item: Item) {
export function parseVersion(line: string, item: Item) {
let i = item.start;
let eqIndex = line.indexOf("version");
if (eqIndex === -1) {
Expand Down Expand Up @@ -211,7 +211,7 @@ function parseVersionValue(line: string, item: Item) {
item.end = item.start + item.value.length;
}

function parsePackage(line: string, item: Item) {
export function parsePackage(line: string, item: Item) {
let i = item.start;
let eqIndex = line.indexOf("package");
if (eqIndex == -1) {
Expand Down Expand Up @@ -257,10 +257,10 @@ function isDependencySingle(line: string): boolean {
return line.includes("dependencies.");
}

function isBoolean(value: string): boolean {
export function isBoolean(value: string): boolean {
return value === "true" || value === "false";
}
function clearText(text: string) {
export function clearText(text: string) {
return text.replace(/[^a-zA-Z0-9-_.*]/g, "").trim();
}

Expand Down

0 comments on commit 6b81218

Please sign in to comment.