From a8149ab7a8ce637e90aed3d54f42005db0d0da39 Mon Sep 17 00:00:00 2001 From: StardustDL Date: Mon, 1 Apr 2024 16:49:03 +0800 Subject: [PATCH] fix frontend model slots --- scripts/format.py | 10 +++++++--- src/aexpy/extracting/base.py | 6 +++++- src/aexpy/models/__init__.py | 5 +++-- src/aexpy/models/description.py | 7 ++++++- src/aexpy/models/difference.py | 3 ++- src/servers/api/__init__.py | 6 ++++-- src/servers/cli.py | 6 ++++-- src/servers/entrypoint.py | 2 +- src/web/src/components/entries/ApiEntryViewer.vue | 6 +++--- src/web/src/models/description.ts | 6 ++++-- 10 files changed, 39 insertions(+), 18 deletions(-) diff --git a/scripts/format.py b/scripts/format.py index d270f87..68557b7 100644 --- a/scripts/format.py +++ b/scripts/format.py @@ -2,15 +2,19 @@ import subprocess ROOT = Path(__file__).parent.parent.resolve() -PYTHON_SRC = ROOT / "src" / "aexpy" +AEXPY_SRC = ROOT / "src" / "aexpy" +SERVER_SRC = ROOT / "src" / "servers" +SRCS = [AEXPY_SRC, SERVER_SRC] def black(): - subprocess.run(["black", str(PYTHON_SRC)], check=True) + for src in SRCS: + subprocess.run(["black", str(src)], check=True) def isort(): - subprocess.run(["isort", str(PYTHON_SRC)], check=True) + for src in SRCS: + subprocess.run(["isort", str(src)], check=True) if __name__ == "__main__": diff --git a/src/aexpy/extracting/base.py b/src/aexpy/extracting/base.py index a4d7f93..507413a 100644 --- a/src/aexpy/extracting/base.py +++ b/src/aexpy/extracting/base.py @@ -55,7 +55,11 @@ def extractInEnv(self, /, result, runner): continue for member, target in mod.members.items(): entry = result[target] - if entry is not None and entry.parent == mod.id and len(entry.alias) == 0: + if ( + entry is not None + and entry.parent == mod.id + and len(entry.alias) == 0 + ): entry.private = member not in mod.slots result.calcSubclasses() diff --git a/src/aexpy/models/__init__.py b/src/aexpy/models/__init__.py index 0180c8c..186d322 100644 --- a/src/aexpy/models/__init__.py +++ b/src/aexpy/models/__init__.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod from datetime import datetime, timedelta -from enum import IntEnum +from enum import IntEnum, unique from functools import cached_property from pathlib import Path from typing import override @@ -54,6 +54,7 @@ def fromId(cls, /, id: str): return cls(old=old, new=new) +@unique class ProduceState(IntEnum): Pending = 0 Success = 1 @@ -281,7 +282,7 @@ def calcSubclasses(self, /): entry = self[base] if isinstance(entry, ClassEntry): entry.subclasses = list(subclass) - + def calcAliases(self): alias: dict[str, set[str]] = {} working: set[str] = set() diff --git a/src/aexpy/models/description.py b/src/aexpy/models/description.py index bc1f7fc..92d2068 100644 --- a/src/aexpy/models/description.py +++ b/src/aexpy/models/description.py @@ -1,4 +1,4 @@ -from enum import IntEnum, IntFlag +from enum import IntEnum, IntFlag, unique from functools import cached_property from typing import Annotated, Any, Literal @@ -43,6 +43,7 @@ def aliasMembers(self, /): return {k: v for k, v in self.members.items() if v != f"{self.id}.{k}"} +@unique class ItemScope(IntEnum): Static = 0 Class = 1 @@ -54,6 +55,7 @@ class ItemEntry(ApiEntry): type: Annotated[TypeType, Field(discriminator="form")] | None = None +@unique class SpecialKind(IntEnum): Unknown = 0 Empty = 1 @@ -69,6 +71,7 @@ class ModuleEntry(CollectionEntry): form: Literal["module"] = "module" +@unique class ClassFlag(IntFlag): Empty = 0 Abstract = 1 << 0 @@ -95,6 +98,7 @@ class AttributeEntry(ItemEntry): property: bool = False +@unique class ParameterKind(IntEnum): Positional = 0 PositionalOrKeyword = 1 @@ -134,6 +138,7 @@ def isVar(self, /): return self.kind in {ParameterKind.VarKeyword, ParameterKind.VarPositional} +@unique class FunctionFlag(IntFlag): Empty = 0 Abstract = 1 << 0 diff --git a/src/aexpy/models/difference.py b/src/aexpy/models/difference.py index fc4ecc5..c1fe88c 100644 --- a/src/aexpy/models/difference.py +++ b/src/aexpy/models/difference.py @@ -1,4 +1,4 @@ -from enum import IntEnum +from enum import IntEnum, unique from typing import Annotated, Any from pydantic import BaseModel, Field @@ -6,6 +6,7 @@ from .description import ApiEntryType +@unique class BreakingRank(IntEnum): Unknown = -1 Compatible = 0 diff --git a/src/servers/api/__init__.py b/src/servers/api/__init__.py index b2b5137..3f335ed 100644 --- a/src/servers/api/__init__.py +++ b/src/servers/api/__init__.py @@ -1,6 +1,8 @@ import os from pathlib import Path -from flask import Blueprint, Response, jsonify, request, send_file, send_from_directory + +from flask import (Blueprint, Response, jsonify, request, send_file, + send_from_directory) WWW_DATA = Path(__file__).parent.parent.joinpath("wwwdata") @@ -27,7 +29,7 @@ def diff(): @api.route("/info", methods=["GET"]) def info(): - from aexpy import COMMIT_ID, BUILD_DATE + from aexpy import BUILD_DATE, COMMIT_ID return jsonify( { diff --git a/src/servers/cli.py b/src/servers/cli.py index b592fc4..066cd34 100644 --- a/src/servers/cli.py +++ b/src/servers/cli.py @@ -1,6 +1,7 @@ -import click from pathlib import Path +import click + @click.command() @click.option( @@ -20,6 +21,7 @@ @click.option("-p", "--port", type=int, default=8008, help="Port to listen on.") def serve(data: Path | None = None, debug: bool = False, port: int = 8008): """Serve web server.""" - from .entrypoint import serve as inner, buildApp + from .entrypoint import buildApp + from .entrypoint import serve as inner inner(buildApp(data), debug, port) diff --git a/src/servers/entrypoint.py b/src/servers/entrypoint.py index 40a35de..baec1a8 100644 --- a/src/servers/entrypoint.py +++ b/src/servers/entrypoint.py @@ -1,6 +1,6 @@ import os -from pathlib import Path import shutil +from pathlib import Path import click import tornado.httpserver diff --git a/src/web/src/components/entries/ApiEntryViewer.vue b/src/web/src/components/entries/ApiEntryViewer.vue index 408e683..0e56065 100644 --- a/src/web/src/components/entries/ApiEntryViewer.vue +++ b/src/web/src/components/entries/ApiEntryViewer.vue @@ -20,7 +20,7 @@ const memberColumns: DataTableColumns<{ key: string, value: string }> = [ key: 'key', sorter: 'default', render(row) { - if (props.entry instanceof CollectionEntry && props.entry.slots.size > 0 && props.entry.slots.has(row.key)) { + if (props.entry instanceof CollectionEntry && props.entry.slots != null && props.entry.slots.size > 0 && props.entry.slots.has(row.key)) { return h(NText, { type: "info" }, { default: () => row.key }); } return row.key; @@ -321,7 +321,7 @@ const parameterColumns = computed(() => { + v-if="(entry instanceof FunctionEntry && (entry.callers.length > 0 || entry.callees.length > 0)) || (entry instanceof CollectionEntry && entry.slots != null && entry.slots.size > 0) || (entry.src.length > 0) || (entry.alias.length > 0) || (entry.docs.length > 0) || (entry.comments.length > 0)">