Skip to content

Commit

Permalink
fix frontend model slots
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Apr 1, 2024
1 parent 4943816 commit a8149ab
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 18 deletions.
10 changes: 7 additions & 3 deletions scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
6 changes: 5 additions & 1 deletion src/aexpy/extracting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 3 additions & 2 deletions src/aexpy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,6 +54,7 @@ def fromId(cls, /, id: str):
return cls(old=old, new=new)


@unique
class ProduceState(IntEnum):
Pending = 0
Success = 1
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion src/aexpy/models/description.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -54,6 +55,7 @@ class ItemEntry(ApiEntry):
type: Annotated[TypeType, Field(discriminator="form")] | None = None


@unique
class SpecialKind(IntEnum):
Unknown = 0
Empty = 1
Expand All @@ -69,6 +71,7 @@ class ModuleEntry(CollectionEntry):
form: Literal["module"] = "module"


@unique
class ClassFlag(IntFlag):
Empty = 0
Abstract = 1 << 0
Expand All @@ -95,6 +98,7 @@ class AttributeEntry(ItemEntry):
property: bool = False


@unique
class ParameterKind(IntEnum):
Positional = 0
PositionalOrKeyword = 1
Expand Down Expand Up @@ -134,6 +138,7 @@ def isVar(self, /):
return self.kind in {ParameterKind.VarKeyword, ParameterKind.VarPositional}


@unique
class FunctionFlag(IntFlag):
Empty = 0
Abstract = 1 << 0
Expand Down
3 changes: 2 additions & 1 deletion src/aexpy/models/difference.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from enum import IntEnum
from enum import IntEnum, unique
from typing import Annotated, Any

from pydantic import BaseModel, Field

from .description import ApiEntryType


@unique
class BreakingRank(IntEnum):
Unknown = -1
Compatible = 0
Expand Down
6 changes: 4 additions & 2 deletions src/servers/api/__init__.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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(
{
Expand Down
6 changes: 4 additions & 2 deletions src/servers/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
from pathlib import Path

import click


@click.command()
@click.option(
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/servers/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
import shutil
from pathlib import Path

import click
import tornado.httpserver
Expand Down
6 changes: 3 additions & 3 deletions src/web/src/components/entries/ApiEntryViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -321,7 +321,7 @@ const parameterColumns = computed(() => {
</n-popover>
</n-descriptions-item>
<n-descriptions-item
v-if="(entry instanceof FunctionEntry && (entry.callers.length > 0 || entry.callees.length > 0)) || (entry instanceof CollectionEntry && entry.slots.size > 0) || (entry.src.length > 0) || (entry.alias.length > 0) || (entry.docs.length > 0) || (entry.comments.length > 0)">
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)">

<template #label>
<n-h6 type="info" prefix="bar">
Expand All @@ -336,7 +336,7 @@ const parameterColumns = computed(() => {
</n-flex>
</n-collapse-item>
<n-collapse-item :title="`Slots (${entry.slots.size})`"
v-if="(entry instanceof CollectionEntry && entry.slots.size > 0)">
v-if="(entry instanceof CollectionEntry && entry.slots != null && entry.slots.size > 0)">
<n-flex vertical :align="'start'">
<n-text v-for="item in entry.slots" :key="item">{{ item }}</n-text>
</n-flex>
Expand Down
6 changes: 4 additions & 2 deletions src/web/src/models/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export class ApiEntry {
export class CollectionEntry extends ApiEntry {
members: { [key: string]: string } = {};
annotations: { [key: string]: string } = {};
slots: Set<string> = new Set<string>();
slots: Set<string> | null = null;

from(data: any) {
super.from(data);
this.members = data.members ?? {};
this.annotations = data.annotations ?? {};
this.slots = new Set<string>(data.slots ?? []);
if (data.slots != undefined && data.slots != null) {
this.slots = new Set<string>(data.slots ?? []);
}
return this;
}
}
Expand Down

0 comments on commit a8149ab

Please sign in to comment.