Skip to content

Commit b237906

Browse files
committed
improve python uspport
1 parent bfe828b commit b237906

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

examples/python/flask/.napirc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"entrypoint": "app.py",
33
"out": "napi_dist",
4+
"include": ["app.py", "api/**"],
45
"openaiApiKeyFilePath": "../../.OPENAIKEY",
56
"audit": {
67
"targetMaxCharInFile": 5000,

examples/python/flask/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def hello_world():
1515
def liveness():
1616
return {"status": "ok"}
1717

18-
# @nanoapi path:readiness method:GET
18+
# @nanoapi method:GET path:readiness
1919
@app.get("/readiness")
2020
def readiness():
2121
return {"status": "ok"}

packages/app/src/pages/splitConfigure/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default function SplitConfigure() {
2020
setBusy(true);
2121
setIsOutOfSynced(true);
2222

23+
console.log(111111111111, endpoint, group);
24+
2325
const targetEndpoint = endpoints.find(
2426
(e) => e.path === endpoint.path && e.method === endpoint.method,
2527
);

packages/cli/src/audit/projectOverview.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "fs";
44
import { getLanguagePlugin } from "../languagesPlugins";
55
import { localConfigSchema } from "../config/localConfig";
66
import z from "zod";
7+
import UnknownPlugin from "../languagesPlugins/unknown";
78

89
export class ProjectOverview {
910
files: AuditFile[] = [];
@@ -15,9 +16,15 @@ export class ProjectOverview {
1516
#init(dir: string, config: z.infer<typeof localConfigSchema>) {
1617
const files = this.#getFiles(dir);
1718

18-
this.files = files.map((file) => {
19+
files.forEach((file) => {
1920
const plugin = getLanguagePlugin(file.path, file.path);
2021

22+
if (plugin.constructor === UnknownPlugin) {
23+
// TODO log something
24+
console.log(1111111111111, file.path);
25+
return;
26+
}
27+
2128
const tree = plugin.parser.parse(file.sourceCode);
2229

2330
const depImports = plugin.getImports(file.path, tree.rootNode);
@@ -26,7 +33,7 @@ export class ProjectOverview {
2633
.filter((depImport) => !depImport.isExternal)
2734
.map((depImport) => depImport.source);
2835

29-
return {
36+
this.files.push({
3037
path: file.path,
3138
sourceCode: file.sourceCode,
3239
importSources,
@@ -59,7 +66,7 @@ export class ProjectOverview {
5966
isUnused: false,
6067
circularDependencySources: [],
6168
},
62-
};
69+
});
6370
});
6471

6572
this.#checkForUnusedFiles();

packages/cli/src/config/localConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { z } from "zod";
55
export const localConfigSchema = z.object({
66
entrypoint: z.string(),
77
out: z.string(),
8+
include: z.array(z.string()).optional(),
9+
exclude: z.array(z.string()).optional(),
810
openai: z
911
.object({
1012
apiKey: z.string().optional(),

packages/cli/src/languagesPlugins/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import JavascriptPlugin from "./javascript";
22
import PythonPlugin from "./python";
33
import { LanguagePlugin } from "./types";
4+
import UnknownPlugin from "./unknown";
45

56
export function getLanguagePlugin(
67
entryPointPath: string,
@@ -16,6 +17,6 @@ export function getLanguagePlugin(
1617
case "py":
1718
return new PythonPlugin(entryPointPath);
1819
default:
19-
throw new Error(`Unsupported file type: ${ext}`);
20+
return new UnknownPlugin(entryPointPath);
2021
}
2122
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Parser from "tree-sitter";
2+
import { DepExport, DepImport, LanguagePlugin } from "./types";
3+
import { Group } from "../dependencyManager/types";
4+
5+
class UnknownPlugin implements LanguagePlugin {
6+
parser: Parser;
7+
entryPointPath: string;
8+
9+
constructor(entryPointPath: string) {
10+
this.entryPointPath = entryPointPath;
11+
this.parser = new Parser();
12+
}
13+
14+
commentPrefix = "";
15+
annotationRegex = /$^/;
16+
17+
getAnnotationNodes(): Parser.SyntaxNode[] {
18+
return [];
19+
}
20+
21+
removeAnnotationFromOtherGroups(
22+
sourceCode: string,
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
_groupToKeep: Group,
25+
): string {
26+
return sourceCode;
27+
}
28+
29+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
30+
getImports(_filePath: string, _node: Parser.SyntaxNode): DepImport[] {
31+
return [];
32+
}
33+
34+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
35+
getExports(_groupToKeepnode: Parser.SyntaxNode): DepExport[] {
36+
return [];
37+
}
38+
39+
cleanupInvalidImports(
40+
_filePath: string,
41+
sourceCode: string,
42+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
43+
_exportMap: Map<string, DepExport[]>,
44+
): string {
45+
return sourceCode;
46+
}
47+
48+
cleanupUnusedImports(_filePath: string, sourceCode: string): string {
49+
return sourceCode;
50+
}
51+
}
52+
53+
export default UnknownPlugin;

0 commit comments

Comments
 (0)