From cee6ab0cfbdd7a99ffb4abf104bf85c237624a0b Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Sun, 9 Jun 2024 23:33:43 +0800 Subject: [PATCH 1/3] refactor: move src package into memos_wbhook --- main.py | 8 ++++---- {src => memos_webhook}/__init__.py | 0 {src => memos_webhook}/app.py | 19 ++++++++++--------- {src => memos_webhook}/dependencies/config.py | 10 ++++++---- .../dependencies/memos_cli.py | 2 +- .../dependencies/plugin_manager.py | 4 ++-- {src => memos_webhook}/plugins/__init__.py | 0 {src => memos_webhook}/plugins/base_plugin.py | 6 +++--- .../plugins/base_plugin_test.py | 6 +++--- .../plugins/you_get_plugin.py | 6 +++--- .../plugins/you_get_plugin_test.py | 0 {src => memos_webhook}/utils/__init__.py | 0 .../utils/config_decorators/__init__.py | 0 .../utils/config_decorators/common.py | 0 .../utils/config_decorators/from_args.py | 0 .../utils/config_decorators/from_args_test.py | 0 .../utils/config_decorators/from_env.py | 0 .../utils/config_decorators/from_env_test.py | 0 .../utils/config_decorators/from_unmarshal.py | 0 .../config_decorators/from_unmarshal_test.py | 0 {src => memos_webhook}/utils/logger.py | 0 {src => memos_webhook}/webhook/__init__.py | 0 .../webhook/types/__init__.py | 0 .../webhook/types/common.py | 0 .../webhook/types/google_protobuf.py | 0 .../webhook/types/markdown_service.py | 0 .../webhook/types/memo_relation_service.py | 0 .../webhook/types/memo_service.py | 0 .../webhook/types/reaction.py | 0 .../webhook/types/resource_service.py | 0 .../webhook/types/webhook_payload.py | 0 pyproject.toml | 2 +- 32 files changed, 33 insertions(+), 30 deletions(-) rename {src => memos_webhook}/__init__.py (100%) rename {src => memos_webhook}/app.py (70%) rename {src => memos_webhook}/dependencies/config.py (85%) rename {src => memos_webhook}/dependencies/memos_cli.py (94%) rename {src => memos_webhook}/dependencies/plugin_manager.py (88%) rename {src => memos_webhook}/plugins/__init__.py (100%) rename {src => memos_webhook}/plugins/base_plugin.py (97%) rename {src => memos_webhook}/plugins/base_plugin_test.py (95%) rename {src => memos_webhook}/plugins/you_get_plugin.py (95%) rename {src => memos_webhook}/plugins/you_get_plugin_test.py (100%) rename {src => memos_webhook}/utils/__init__.py (100%) rename {src => memos_webhook}/utils/config_decorators/__init__.py (100%) rename {src => memos_webhook}/utils/config_decorators/common.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_args.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_args_test.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_env.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_env_test.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_unmarshal.py (100%) rename {src => memos_webhook}/utils/config_decorators/from_unmarshal_test.py (100%) rename {src => memos_webhook}/utils/logger.py (100%) rename {src => memos_webhook}/webhook/__init__.py (100%) rename {src => memos_webhook}/webhook/types/__init__.py (100%) rename {src => memos_webhook}/webhook/types/common.py (100%) rename {src => memos_webhook}/webhook/types/google_protobuf.py (100%) rename {src => memos_webhook}/webhook/types/markdown_service.py (100%) rename {src => memos_webhook}/webhook/types/memo_relation_service.py (100%) rename {src => memos_webhook}/webhook/types/memo_service.py (100%) rename {src => memos_webhook}/webhook/types/reaction.py (100%) rename {src => memos_webhook}/webhook/types/resource_service.py (100%) rename {src => memos_webhook}/webhook/types/webhook_payload.py (100%) diff --git a/main.py b/main.py index bc57b25..93e6e9f 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,9 @@ import asyncio -from src.app import app -from src.dependencies.config import new_config -from src.utils.logger import logger as util_logger -from src.utils.logger import logging_config +from memos_webhook.app import app +from memos_webhook.dependencies.config import new_config +from memos_webhook.utils.logger import logger as util_logger +from memos_webhook.utils.logger import logging_config logger = util_logger.getChild("main") diff --git a/src/__init__.py b/memos_webhook/__init__.py similarity index 100% rename from src/__init__.py rename to memos_webhook/__init__.py diff --git a/src/app.py b/memos_webhook/app.py similarity index 70% rename from src/app.py rename to memos_webhook/app.py index 0c0d0b3..1b4682a 100644 --- a/src/app.py +++ b/memos_webhook/app.py @@ -7,15 +7,16 @@ from fastapi import BackgroundTasks, Depends, FastAPI import proto.gen.memos.api.v1 as v1 -from src.dependencies.config import get_config, new_config -from src.dependencies.memos_cli import MemosCli, get_memos_cli, new_memos_cli -from src.dependencies.plugin_manager import (get_plugin_executor, - new_plugin_executor) -from src.plugins.base_plugin import PluginExecutor -from src.plugins.you_get_plugin import YouGetPlugin -from src.utils.logger import logger as util_logger -from src.utils.logger import logging_config -from src.webhook.types.webhook_payload import WebhookPayload +from memos_webhook.dependencies.config import get_config, new_config +from memos_webhook.dependencies.memos_cli import (MemosCli, get_memos_cli, + new_memos_cli) +from memos_webhook.dependencies.plugin_manager import (get_plugin_executor, + new_plugin_executor) +from memos_webhook.plugins.base_plugin import PluginExecutor +from memos_webhook.plugins.you_get_plugin import YouGetPlugin +from memos_webhook.utils.logger import logger as util_logger +from memos_webhook.utils.logger import logging_config +from memos_webhook.webhook.types.webhook_payload import WebhookPayload logger = util_logger.getChild("app") diff --git a/src/dependencies/config.py b/memos_webhook/dependencies/config.py similarity index 85% rename from src/dependencies/config.py rename to memos_webhook/dependencies/config.py index 3eb783a..43bd58c 100644 --- a/src/dependencies/config.py +++ b/memos_webhook/dependencies/config.py @@ -1,9 +1,11 @@ from pydantic import BaseModel -from src.utils.config_decorators import (ArgsConfigProvider, BaseArgsConfig, - BaseDotenvConfig, BaseUnmarshalConfig, - default, from_env, from_unmarshal, - it_is) +from memos_webhook.utils.config_decorators import (ArgsConfigProvider, + BaseArgsConfig, + BaseDotenvConfig, + BaseUnmarshalConfig, + default, from_env, + from_unmarshal, it_is) class YouGetPluginConfig(BaseModel): diff --git a/src/dependencies/memos_cli.py b/memos_webhook/dependencies/memos_cli.py similarity index 94% rename from src/dependencies/memos_cli.py rename to memos_webhook/dependencies/memos_cli.py index 590931a..bcd0535 100644 --- a/src/dependencies/memos_cli.py +++ b/memos_webhook/dependencies/memos_cli.py @@ -4,7 +4,7 @@ from grpclib.client import Channel import proto.gen.memos.api.v1 as v1 -from src.utils.logger import logger as util_logger +from memos_webhook.utils.logger import logger as util_logger from .config import Config diff --git a/src/dependencies/plugin_manager.py b/memos_webhook/dependencies/plugin_manager.py similarity index 88% rename from src/dependencies/plugin_manager.py rename to memos_webhook/dependencies/plugin_manager.py index 5c41af9..b5c5ec9 100644 --- a/src/dependencies/plugin_manager.py +++ b/memos_webhook/dependencies/plugin_manager.py @@ -1,5 +1,5 @@ -from src.plugins.base_plugin import PluginExecutor, PluginProtocol -from src.plugins.you_get_plugin import YouGetPlugin +from memos_webhook.plugins.base_plugin import PluginExecutor, PluginProtocol +from memos_webhook.plugins.you_get_plugin import YouGetPlugin from .config import Config, PluginConfig, YouGetPluginConfig from .memos_cli import MemosCli diff --git a/src/plugins/__init__.py b/memos_webhook/plugins/__init__.py similarity index 100% rename from src/plugins/__init__.py rename to memos_webhook/plugins/__init__.py diff --git a/src/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py similarity index 97% rename from src/plugins/base_plugin.py rename to memos_webhook/plugins/base_plugin.py index 3b9df6d..2b121d2 100644 --- a/src/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -4,10 +4,10 @@ import betterproto.lib.google.protobuf as pb +from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.utils.logger import logger +from memos_webhook.webhook.types.webhook_payload import WebhookPayload from proto.gen.memos.api import v1 -from src.dependencies.memos_cli import MemosCli -from src.utils.logger import logger -from src.webhook.types.webhook_payload import WebhookPayload pluginLogger = logger.getChild("plugin") diff --git a/src/plugins/base_plugin_test.py b/memos_webhook/plugins/base_plugin_test.py similarity index 95% rename from src/plugins/base_plugin_test.py rename to memos_webhook/plugins/base_plugin_test.py index 2978425..8a75995 100644 --- a/src/plugins/base_plugin_test.py +++ b/memos_webhook/plugins/base_plugin_test.py @@ -1,10 +1,10 @@ import unittest from typing import TypedDict, override -import src.webhook.types.memo_service as webhook_types +import memos_webhook.webhook.types.memo_service as webhook_types +from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.webhook.types.webhook_payload import WebhookPayload from proto.gen.memos.api import v1 -from src.dependencies.memos_cli import MemosCli -from src.webhook.types.webhook_payload import WebhookPayload from .base_plugin import BasePlugin diff --git a/src/plugins/you_get_plugin.py b/memos_webhook/plugins/you_get_plugin.py similarity index 95% rename from src/plugins/you_get_plugin.py rename to memos_webhook/plugins/you_get_plugin.py index 0dd9e96..e8e93b8 100644 --- a/src/plugins/you_get_plugin.py +++ b/memos_webhook/plugins/you_get_plugin.py @@ -8,10 +8,10 @@ import aiofiles.os import betterproto.lib.google.protobuf as pb +from memos_webhook.dependencies.config import YouGetPluginConfig +from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.webhook.types.webhook_payload import WebhookPayload from proto.gen.memos.api import v1 -from src.dependencies.config import YouGetPluginConfig -from src.dependencies.memos_cli import MemosCli -from src.webhook.types.webhook_payload import WebhookPayload from .base_plugin import BasePlugin, pluginLogger diff --git a/src/plugins/you_get_plugin_test.py b/memos_webhook/plugins/you_get_plugin_test.py similarity index 100% rename from src/plugins/you_get_plugin_test.py rename to memos_webhook/plugins/you_get_plugin_test.py diff --git a/src/utils/__init__.py b/memos_webhook/utils/__init__.py similarity index 100% rename from src/utils/__init__.py rename to memos_webhook/utils/__init__.py diff --git a/src/utils/config_decorators/__init__.py b/memos_webhook/utils/config_decorators/__init__.py similarity index 100% rename from src/utils/config_decorators/__init__.py rename to memos_webhook/utils/config_decorators/__init__.py diff --git a/src/utils/config_decorators/common.py b/memos_webhook/utils/config_decorators/common.py similarity index 100% rename from src/utils/config_decorators/common.py rename to memos_webhook/utils/config_decorators/common.py diff --git a/src/utils/config_decorators/from_args.py b/memos_webhook/utils/config_decorators/from_args.py similarity index 100% rename from src/utils/config_decorators/from_args.py rename to memos_webhook/utils/config_decorators/from_args.py diff --git a/src/utils/config_decorators/from_args_test.py b/memos_webhook/utils/config_decorators/from_args_test.py similarity index 100% rename from src/utils/config_decorators/from_args_test.py rename to memos_webhook/utils/config_decorators/from_args_test.py diff --git a/src/utils/config_decorators/from_env.py b/memos_webhook/utils/config_decorators/from_env.py similarity index 100% rename from src/utils/config_decorators/from_env.py rename to memos_webhook/utils/config_decorators/from_env.py diff --git a/src/utils/config_decorators/from_env_test.py b/memos_webhook/utils/config_decorators/from_env_test.py similarity index 100% rename from src/utils/config_decorators/from_env_test.py rename to memos_webhook/utils/config_decorators/from_env_test.py diff --git a/src/utils/config_decorators/from_unmarshal.py b/memos_webhook/utils/config_decorators/from_unmarshal.py similarity index 100% rename from src/utils/config_decorators/from_unmarshal.py rename to memos_webhook/utils/config_decorators/from_unmarshal.py diff --git a/src/utils/config_decorators/from_unmarshal_test.py b/memos_webhook/utils/config_decorators/from_unmarshal_test.py similarity index 100% rename from src/utils/config_decorators/from_unmarshal_test.py rename to memos_webhook/utils/config_decorators/from_unmarshal_test.py diff --git a/src/utils/logger.py b/memos_webhook/utils/logger.py similarity index 100% rename from src/utils/logger.py rename to memos_webhook/utils/logger.py diff --git a/src/webhook/__init__.py b/memos_webhook/webhook/__init__.py similarity index 100% rename from src/webhook/__init__.py rename to memos_webhook/webhook/__init__.py diff --git a/src/webhook/types/__init__.py b/memos_webhook/webhook/types/__init__.py similarity index 100% rename from src/webhook/types/__init__.py rename to memos_webhook/webhook/types/__init__.py diff --git a/src/webhook/types/common.py b/memos_webhook/webhook/types/common.py similarity index 100% rename from src/webhook/types/common.py rename to memos_webhook/webhook/types/common.py diff --git a/src/webhook/types/google_protobuf.py b/memos_webhook/webhook/types/google_protobuf.py similarity index 100% rename from src/webhook/types/google_protobuf.py rename to memos_webhook/webhook/types/google_protobuf.py diff --git a/src/webhook/types/markdown_service.py b/memos_webhook/webhook/types/markdown_service.py similarity index 100% rename from src/webhook/types/markdown_service.py rename to memos_webhook/webhook/types/markdown_service.py diff --git a/src/webhook/types/memo_relation_service.py b/memos_webhook/webhook/types/memo_relation_service.py similarity index 100% rename from src/webhook/types/memo_relation_service.py rename to memos_webhook/webhook/types/memo_relation_service.py diff --git a/src/webhook/types/memo_service.py b/memos_webhook/webhook/types/memo_service.py similarity index 100% rename from src/webhook/types/memo_service.py rename to memos_webhook/webhook/types/memo_service.py diff --git a/src/webhook/types/reaction.py b/memos_webhook/webhook/types/reaction.py similarity index 100% rename from src/webhook/types/reaction.py rename to memos_webhook/webhook/types/reaction.py diff --git a/src/webhook/types/resource_service.py b/memos_webhook/webhook/types/resource_service.py similarity index 100% rename from src/webhook/types/resource_service.py rename to memos_webhook/webhook/types/resource_service.py diff --git a/src/webhook/types/webhook_payload.py b/memos_webhook/webhook/types/webhook_payload.py similarity index 100% rename from src/webhook/types/webhook_payload.py rename to memos_webhook/webhook/types/webhook_payload.py diff --git a/pyproject.toml b/pyproject.toml index b56a928..b2f7187 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,5 +26,5 @@ dependencies = { file = ["requirements.txt"] } [tool.setuptools.packages.find] where = ["."] -include = ["proto*", "src*"] +include = ["proto*", "memos_webhook*"] exclude = ["*_test.py"] From 4da82aeb665c69dc73e22ca8a40e38372327480f Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Sun, 9 Jun 2024 23:37:25 +0800 Subject: [PATCH 2/3] refactor: generate proto into memos webhook --- memos_webhook/.gitattributes | 1 + memos_webhook/app.py | 2 +- memos_webhook/dependencies/memos_cli.py | 2 +- memos_webhook/plugins/base_plugin.py | 2 +- memos_webhook/plugins/base_plugin_test.py | 2 +- memos_webhook/plugins/you_get_plugin.py | 2 +- {proto => memos_webhook/proto_gen/google}/__init__.py | 0 {proto/gen => memos_webhook/proto_gen}/google/api/__init__.py | 0 {proto/gen => memos_webhook/proto_gen/memos}/__init__.py | 0 .../google => memos_webhook/proto_gen/memos/api}/__init__.py | 0 {proto/gen => memos_webhook/proto_gen}/memos/api/v1/__init__.py | 0 proto/buf.gen.yaml | 2 +- proto/gen/memos/__init__.py | 0 proto/gen/memos/api/__init__.py | 0 14 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 memos_webhook/.gitattributes rename {proto => memos_webhook/proto_gen/google}/__init__.py (100%) rename {proto/gen => memos_webhook/proto_gen}/google/api/__init__.py (100%) rename {proto/gen => memos_webhook/proto_gen/memos}/__init__.py (100%) rename {proto/gen/google => memos_webhook/proto_gen/memos/api}/__init__.py (100%) rename {proto/gen => memos_webhook/proto_gen}/memos/api/v1/__init__.py (100%) delete mode 100644 proto/gen/memos/__init__.py delete mode 100644 proto/gen/memos/api/__init__.py diff --git a/memos_webhook/.gitattributes b/memos_webhook/.gitattributes new file mode 100644 index 0000000..8795aca --- /dev/null +++ b/memos_webhook/.gitattributes @@ -0,0 +1 @@ +proto_gen/** linguist-generated diff --git a/memos_webhook/app.py b/memos_webhook/app.py index 1b4682a..d519e81 100644 --- a/memos_webhook/app.py +++ b/memos_webhook/app.py @@ -6,7 +6,7 @@ from fastapi import BackgroundTasks, Depends, FastAPI -import proto.gen.memos.api.v1 as v1 +import memos_webhook.proto_gen.memos.api.v1 as v1 from memos_webhook.dependencies.config import get_config, new_config from memos_webhook.dependencies.memos_cli import (MemosCli, get_memos_cli, new_memos_cli) diff --git a/memos_webhook/dependencies/memos_cli.py b/memos_webhook/dependencies/memos_cli.py index bcd0535..49da7c7 100644 --- a/memos_webhook/dependencies/memos_cli.py +++ b/memos_webhook/dependencies/memos_cli.py @@ -3,7 +3,7 @@ from grpclib.client import Channel -import proto.gen.memos.api.v1 as v1 +import memos_webhook.proto_gen.memos.api.v1 as v1 from memos_webhook.utils.logger import logger as util_logger from .config import Config diff --git a/memos_webhook/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py index 2b121d2..fc6984e 100644 --- a/memos_webhook/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -5,9 +5,9 @@ import betterproto.lib.google.protobuf as pb from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.proto_gen.memos.api import v1 from memos_webhook.utils.logger import logger from memos_webhook.webhook.types.webhook_payload import WebhookPayload -from proto.gen.memos.api import v1 pluginLogger = logger.getChild("plugin") diff --git a/memos_webhook/plugins/base_plugin_test.py b/memos_webhook/plugins/base_plugin_test.py index 8a75995..b4e08ac 100644 --- a/memos_webhook/plugins/base_plugin_test.py +++ b/memos_webhook/plugins/base_plugin_test.py @@ -3,8 +3,8 @@ import memos_webhook.webhook.types.memo_service as webhook_types from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.proto_gen.memos.api import v1 from memos_webhook.webhook.types.webhook_payload import WebhookPayload -from proto.gen.memos.api import v1 from .base_plugin import BasePlugin diff --git a/memos_webhook/plugins/you_get_plugin.py b/memos_webhook/plugins/you_get_plugin.py index e8e93b8..2838027 100644 --- a/memos_webhook/plugins/you_get_plugin.py +++ b/memos_webhook/plugins/you_get_plugin.py @@ -10,8 +10,8 @@ from memos_webhook.dependencies.config import YouGetPluginConfig from memos_webhook.dependencies.memos_cli import MemosCli +from memos_webhook.proto_gen.memos.api import v1 from memos_webhook.webhook.types.webhook_payload import WebhookPayload -from proto.gen.memos.api import v1 from .base_plugin import BasePlugin, pluginLogger diff --git a/proto/__init__.py b/memos_webhook/proto_gen/google/__init__.py similarity index 100% rename from proto/__init__.py rename to memos_webhook/proto_gen/google/__init__.py diff --git a/proto/gen/google/api/__init__.py b/memos_webhook/proto_gen/google/api/__init__.py similarity index 100% rename from proto/gen/google/api/__init__.py rename to memos_webhook/proto_gen/google/api/__init__.py diff --git a/proto/gen/__init__.py b/memos_webhook/proto_gen/memos/__init__.py similarity index 100% rename from proto/gen/__init__.py rename to memos_webhook/proto_gen/memos/__init__.py diff --git a/proto/gen/google/__init__.py b/memos_webhook/proto_gen/memos/api/__init__.py similarity index 100% rename from proto/gen/google/__init__.py rename to memos_webhook/proto_gen/memos/api/__init__.py diff --git a/proto/gen/memos/api/v1/__init__.py b/memos_webhook/proto_gen/memos/api/v1/__init__.py similarity index 100% rename from proto/gen/memos/api/v1/__init__.py rename to memos_webhook/proto_gen/memos/api/v1/__init__.py diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml index 12f074c..2863fc2 100644 --- a/proto/buf.gen.yaml +++ b/proto/buf.gen.yaml @@ -13,4 +13,4 @@ plugins: # https://github.com/danielgtaylor/python-betterproto/issues/574 - local: protoc-gen-python_betterproto # https://github.com/danielgtaylor/python-betterproto - out: gen + out: ../memos_webhook/proto_gen diff --git a/proto/gen/memos/__init__.py b/proto/gen/memos/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/proto/gen/memos/api/__init__.py b/proto/gen/memos/api/__init__.py deleted file mode 100644 index e69de29..0000000 From 3c11575e3f51a92ebcaeaa39667b5fd221785947 Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Sun, 9 Jun 2024 23:38:19 +0800 Subject: [PATCH 3/3] chore: change test command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d81967f..95ed265 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ freeze: @pip freeze > requirements.txt test: - @python -m unittest discover -p "*_test.py" src + @python -m unittest discover -p "*_test.py" memos_webhook .PHONY: package_build package_clean package_publish