Skip to content

Commit

Permalink
update core
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Dec 5, 2023
1 parent 9c73a55 commit dfc2822
Show file tree
Hide file tree
Showing 46 changed files with 1,701 additions and 447 deletions.
1 change: 1 addition & 0 deletions core/aexpy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cache
25 changes: 24 additions & 1 deletion core/aexpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from datetime import datetime
import logging
import os
Expand All @@ -6,7 +23,9 @@
__version__ = "0.2.0"


LOGGING_FORMAT = "%(levelname)s %(asctime)s %(name)s [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s\n"
LOGGING_FORMAT = (
"%(levelname)s %(asctime)s %(name)s [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s\n"
)
LOGGING_DATEFMT = "%Y-%m-%d,%H:%M:%S"


Expand Down Expand Up @@ -37,3 +56,7 @@ def getBuildDate() -> datetime:
return datetime.fromisoformat(os.getenv("BUILD_DATE", "unknown"))
except:
return datetime.now()


def getPythonExe() -> str:
return os.getenv("AEXPY_PYTHON_EXE", "python")
41 changes: 31 additions & 10 deletions core/aexpy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import code
import logging
import pathlib
import sys

import click

from aexpy.models import ProduceMode
from aexpy.models import ProduceMode, ProduceState
from aexpy.caching import FileProduceCache
from aexpy.services import ServiceProvider

Expand Down Expand Up @@ -120,9 +138,8 @@ def preprocess(
output: pathlib.Path,
view: bool,
):
assert view or (
rootpath and modules
), "Please give the input file or use the view mode."
"""Generate a release definition."""
assert view or (rootpath and modules), "Please give the input file or use the view mode."

mode = ProduceMode.Read if view else ProduceMode.Write

Expand All @@ -138,6 +155,8 @@ def preprocess(
if FLAG_interact:
code.interact(banner="", local=locals())

assert result.state == ProduceState.Success, "Failed to process."


@main.command()
@click.argument(
Expand Down Expand Up @@ -182,6 +201,8 @@ def extract(file: pathlib.Path, output: pathlib.Path, view: bool):
if FLAG_interact:
code.interact(banner="", local=locals())

assert result.state == ProduceState.Success, "Failed to process."


@main.command()
@click.argument(
Expand Down Expand Up @@ -227,16 +248,12 @@ def diff(old: pathlib.Path, new: pathlib.Path, output: pathlib.Path, view: bool)
mode = ProduceMode.Read if view else ProduceMode.Write

oldData = (
services.extract(
FileProduceCache("", old), getUnknownDistribution(), ProduceMode.Read
)
services.extract(FileProduceCache("", old), getUnknownDistribution(), ProduceMode.Read)
if not view
else ApiDescription(distribution=getUnknownDistribution())
)
newData = (
services.extract(
FileProduceCache("", new), getUnknownDistribution(), ProduceMode.Read
)
services.extract(FileProduceCache("", new), getUnknownDistribution(), ProduceMode.Read)
if not view
else ApiDescription(distribution=getUnknownDistribution())
)
Expand All @@ -247,6 +264,8 @@ def diff(old: pathlib.Path, new: pathlib.Path, output: pathlib.Path, view: bool)
if FLAG_interact:
code.interact(banner="", local=locals())

assert result.state == ProduceState.Success, "Failed to process."


@main.command()
@click.argument(
Expand Down Expand Up @@ -297,6 +316,8 @@ def report(file: pathlib.Path, output: pathlib.Path, view: bool):
if FLAG_interact:
code.interact(banner="", local=locals())

assert result.state == ProduceState.Success, "Failed to process."


if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions core/aexpy/caching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from abc import ABC, abstractmethod
from pathlib import Path

Expand Down
17 changes: 17 additions & 0 deletions core/aexpy/diffing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from ..models import ApiDescription, ApiDifference
from ..producers import Producer

Expand Down
21 changes: 20 additions & 1 deletion core/aexpy/diffing/default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from logging import Logger
from pathlib import Path
from uuid import uuid1
Expand All @@ -14,7 +31,9 @@
class DefaultDiffer(Differ):
def diff(self, old: "ApiDescription", new: "ApiDescription", product: "ApiDifference"):
from .differs.default import DefaultDiffer

DefaultDiffer(self.logger).diff(old, new, product)

from .evaluators.default import DefaultEvaluator
DefaultEvaluator(self.logger).diff(old, new, product)

DefaultEvaluator(self.logger).diff(old, new, product)
16 changes: 16 additions & 0 deletions core/aexpy/diffing/differs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
40 changes: 34 additions & 6 deletions core/aexpy/diffing/differs/checkers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import dataclasses
from dataclasses import dataclass, field
from typing import Any, Callable, TypeVar
Expand All @@ -17,12 +34,20 @@ class DiffConstraint:
checker: def checker(a: ApiEntry | None, b: ApiEntry | None, old=oldApiDescription, new=newApiDescription) -> RuleCheckResult | bool: pass
"""

def __init__(self, kind: "str" = "", checker: "Callable[[T_ApiEntry | None, T_ApiEntry | None, ApiDescription, ApiDescription], list[DiffEntry]] | None" = None) -> None:
def __init__(
self,
kind: "str" = "",
checker: "Callable[[T_ApiEntry | None, T_ApiEntry | None, ApiDescription, ApiDescription], list[DiffEntry]] | None" = None,
) -> None:
if checker is None:

def tchecker(a: Any, b: Any, old: Any, new: Any):
return []

checker = tchecker
self.checker: "Callable[[T_ApiEntry | None, T_ApiEntry | None, ApiDescription, ApiDescription], list[DiffEntry]]" = checker
self.checker: "Callable[[T_ApiEntry | None, T_ApiEntry | None, ApiDescription, ApiDescription], list[DiffEntry]]" = (
checker
)
self.kind = kind

def askind(self, kind: "str"):
Expand Down Expand Up @@ -55,10 +80,11 @@ def checker(a, b, **kwargs):
return self

def __call__(self, old, new, oldCollection, newCollection) -> "list[DiffEntry]":
result = self.checker(
old, new, old=oldCollection, new=newCollection) # type: ignore
result = self.checker(old, new, old=oldCollection, new=newCollection) # type: ignore
if result:
return [dataclasses.replace(entry, kind=self.kind, old=old, new=new) for entry in result]
return [
dataclasses.replace(entry, kind=self.kind, old=old, new=new) for entry in result
]
else:
return []

Expand All @@ -74,7 +100,9 @@ def cons(self, constraint: "DiffConstraint"):
return constraint


def diffcons(checker: "Callable[[T_ApiEntry, T_ApiEntry, ApiDescription, ApiDescription], list[DiffEntry]]") -> "DiffConstraint":
def diffcons(
checker: "Callable[[T_ApiEntry, T_ApiEntry, ApiDescription, ApiDescription], list[DiffEntry]]",
) -> "DiffConstraint":
"""Create a DiffConstraint on a function."""

return DiffConstraint(checker.__name__, checker) # type: ignore
Expand Down
49 changes: 42 additions & 7 deletions core/aexpy/diffing/differs/contraints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import functools
import itertools
from itertools import zip_longest
from typing import Callable, OrderedDict
from aexpy.models import ApiDescription

from aexpy.models.description import (ApiEntry, AttributeEntry, ClassEntry,
CollectionEntry, FunctionEntry, ItemEntry,
ModuleEntry, Parameter, ParameterKind,
SpecialEntry, SpecialKind)
from aexpy.models.description import (
ApiEntry,
AttributeEntry,
ClassEntry,
CollectionEntry,
FunctionEntry,
ItemEntry,
ModuleEntry,
Parameter,
ParameterKind,
SpecialEntry,
SpecialKind,
)
from aexpy.models.difference import DiffEntry


def add(a: "ApiEntry | None", b: "ApiEntry | None", old: "ApiDescription", new: "ApiDescription"):
if a is None and b is not None:
return [DiffEntry(message=f"Add {b.__class__.__name__.removesuffix('Entry').lower()} ({b.parent}): {b.name}.")]
return [
DiffEntry(
message=f"Add {b.__class__.__name__.removesuffix('Entry').lower()} ({b.parent}): {b.name}."
)
]
return []


def remove(a: "ApiEntry | None", b: "ApiEntry | None", old: "ApiDescription", new: "ApiDescription"):
def remove(
a: "ApiEntry | None", b: "ApiEntry | None", old: "ApiDescription", new: "ApiDescription"
):
if a is not None and b is None:
if a.parent in old.entries and a.parent not in new.entries:
# only report if parent exisits
return []
return [DiffEntry(message=f"Remove {a.__class__.__name__.removesuffix('Entry').lower()} ({a.parent}): {a.name}.")]
return [
DiffEntry(
message=f"Remove {a.__class__.__name__.removesuffix('Entry').lower()} ({a.parent}): {a.name}."
)
]
return []
Loading

0 comments on commit dfc2822

Please sign in to comment.