From 8890978ad3adfdf75c15d65d29727469761dfcb0 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Sat, 22 Jun 2024 09:54:25 +0800 Subject: [PATCH] chore: use singular style in config class name (#5489) --- api/app.py | 4 +- api/configs/{app_configs.py => app_config.py} | 22 ++--- api/configs/deploy/__init__.py | 2 +- api/configs/enterprise/__init__.py | 2 +- api/configs/extra/__init__.py | 10 +-- .../{notion_configs.py => notion_config.py} | 2 +- .../{sentry_configs.py => sentry_config.py} | 2 +- api/configs/feature/__init__.py | 90 +++++++++---------- api/configs/middleware/__init__.py | 6 +- .../{redis_configs.py => redis_config.py} | 2 +- .../test_dify_config.py} | 22 ++--- 11 files changed, 82 insertions(+), 82 deletions(-) rename api/configs/{app_configs.py => app_config.py} (63%) rename api/configs/extra/{notion_configs.py => notion_config.py} (96%) rename api/configs/extra/{sentry_configs.py => sentry_config.py} (93%) rename api/configs/middleware/{redis_configs.py => redis_config.py} (96%) rename api/tests/unit_tests/{settings/test_dify_settings.py => configs/test_dify_config.py} (69%) diff --git a/api/app.py b/api/app.py index 82ec64e6b7..40a90fdfa7 100644 --- a/api/app.py +++ b/api/app.py @@ -1,6 +1,6 @@ import os -from configs.app_configs import DifyConfigs +from configs.app_config import DifyConfig if not os.environ.get("DEBUG") or os.environ.get("DEBUG", "false").lower() != 'true': from gevent import monkey @@ -83,7 +83,7 @@ def create_flask_app_with_configs() -> Flask: """ dify_app = DifyApp(__name__) dify_app.config.from_object(Config()) - dify_app.config.from_mapping(DifyConfigs().model_dump()) + dify_app.config.from_mapping(DifyConfig().model_dump()) return dify_app diff --git a/api/configs/app_configs.py b/api/configs/app_config.py similarity index 63% rename from api/configs/app_configs.py rename to api/configs/app_config.py index 96352e43d0..4467b84c86 100644 --- a/api/configs/app_configs.py +++ b/api/configs/app_config.py @@ -1,14 +1,14 @@ from pydantic_settings import BaseSettings, SettingsConfigDict -from configs.deploy import DeploymentConfigs -from configs.enterprise import EnterpriseFeatureConfigs -from configs.extra import ExtraServiceConfigs -from configs.feature import FeatureConfigs -from configs.middleware import MiddlewareConfigs +from configs.deploy import DeploymentConfig +from configs.enterprise import EnterpriseFeatureConfig +from configs.extra import ExtraServiceConfig +from configs.feature import FeatureConfig +from configs.middleware import MiddlewareConfig from configs.packaging import PackagingInfo -class DifyConfigs( +class DifyConfig( # based on pydantic-settings BaseSettings, @@ -16,20 +16,20 @@ class DifyConfigs( PackagingInfo, # Deployment configs - DeploymentConfigs, + DeploymentConfig, # Feature configs - FeatureConfigs, + FeatureConfig, # Middleware configs - MiddlewareConfigs, + MiddlewareConfig, # Extra service configs - ExtraServiceConfigs, + ExtraServiceConfig, # Enterprise feature configs # **Before using, please contact business@dify.ai by email to inquire about licensing matters.** - EnterpriseFeatureConfigs, + EnterpriseFeatureConfig, ): model_config = SettingsConfigDict( diff --git a/api/configs/deploy/__init__.py b/api/configs/deploy/__init__.py index 9a1c1b84d7..f7b118201f 100644 --- a/api/configs/deploy/__init__.py +++ b/api/configs/deploy/__init__.py @@ -1,7 +1,7 @@ from pydantic import BaseModel, Field -class DeploymentConfigs(BaseModel): +class DeploymentConfig(BaseModel): """ Deployment configs """ diff --git a/api/configs/enterprise/__init__.py b/api/configs/enterprise/__init__.py index 37164ba2e3..39983036eb 100644 --- a/api/configs/enterprise/__init__.py +++ b/api/configs/enterprise/__init__.py @@ -1,7 +1,7 @@ from pydantic import BaseModel, Field -class EnterpriseFeatureConfigs(BaseModel): +class EnterpriseFeatureConfig(BaseModel): """ Enterprise feature configs. **Before using, please contact business@dify.ai by email to inquire about licensing matters.** diff --git a/api/configs/extra/__init__.py b/api/configs/extra/__init__.py index f248fcb47a..358c12d63a 100644 --- a/api/configs/extra/__init__.py +++ b/api/configs/extra/__init__.py @@ -1,12 +1,12 @@ from pydantic import BaseModel -from configs.extra.notion_configs import NotionConfigs -from configs.extra.sentry_configs import SentryConfigs +from configs.extra.notion_config import NotionConfig +from configs.extra.sentry_config import SentryConfig -class ExtraServiceConfigs( +class ExtraServiceConfig( # place the configs in alphabet order - NotionConfigs, - SentryConfigs, + NotionConfig, + SentryConfig, ): pass diff --git a/api/configs/extra/notion_configs.py b/api/configs/extra/notion_config.py similarity index 96% rename from api/configs/extra/notion_configs.py rename to api/configs/extra/notion_config.py index da96b3c8c5..f8df28cefd 100644 --- a/api/configs/extra/notion_configs.py +++ b/api/configs/extra/notion_config.py @@ -3,7 +3,7 @@ from typing import Optional from pydantic import BaseModel, Field -class NotionConfigs(BaseModel): +class NotionConfig(BaseModel): """ Notion integration configs """ diff --git a/api/configs/extra/sentry_configs.py b/api/configs/extra/sentry_config.py similarity index 93% rename from api/configs/extra/sentry_configs.py rename to api/configs/extra/sentry_config.py index 33924199a3..8cdb8cf45a 100644 --- a/api/configs/extra/sentry_configs.py +++ b/api/configs/extra/sentry_config.py @@ -3,7 +3,7 @@ from typing import Optional from pydantic import BaseModel, Field, NonNegativeFloat -class SentryConfigs(BaseModel): +class SentryConfig(BaseModel): """ Sentry configs """ diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index e820761b06..4d7d0dcd1e 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -3,7 +3,7 @@ from typing import Optional from pydantic import AliasChoices, BaseModel, Field, NonNegativeInt, PositiveInt -class SecurityConfigs(BaseModel): +class SecurityConfig(BaseModel): """ Secret Key configs """ @@ -16,7 +16,7 @@ class SecurityConfigs(BaseModel): ) -class AppExecutionConfigs(BaseModel): +class AppExecutionConfig(BaseModel): """ App Execution configs """ @@ -26,7 +26,7 @@ class AppExecutionConfigs(BaseModel): ) -class CodeExecutionSandboxConfigs(BaseModel): +class CodeExecutionSandboxConfig(BaseModel): """ Code Execution Sandbox configs """ @@ -41,7 +41,7 @@ class CodeExecutionSandboxConfigs(BaseModel): ) -class EndpointConfigs(BaseModel): +class EndpointConfig(BaseModel): """ Module URL configs """ @@ -70,7 +70,7 @@ class EndpointConfigs(BaseModel): ) -class FileAccessConfigs(BaseModel): +class FileAccessConfig(BaseModel): """ File Access configs """ @@ -89,7 +89,7 @@ class FileAccessConfigs(BaseModel): ) -class FileUploadConfigs(BaseModel): +class FileUploadConfig(BaseModel): """ File Uploading configs """ @@ -114,7 +114,7 @@ class FileUploadConfigs(BaseModel): ) -class HttpConfigs(BaseModel): +class HttpConfig(BaseModel): """ HTTP configs """ @@ -124,7 +124,7 @@ class HttpConfigs(BaseModel): ) -class InnerAPIConfigs(BaseModel): +class InnerAPIConfig(BaseModel): """ Inner API configs """ @@ -139,7 +139,7 @@ class InnerAPIConfigs(BaseModel): ) -class LoggingConfigs(BaseModel): +class LoggingConfig(BaseModel): """ Logging configs """ @@ -171,7 +171,7 @@ class LoggingConfigs(BaseModel): ) -class ModelLoadBalanceConfigs(BaseModel): +class ModelLoadBalanceConfig(BaseModel): """ Model load balance configs """ @@ -181,7 +181,7 @@ class ModelLoadBalanceConfigs(BaseModel): ) -class BillingConfigs(BaseModel): +class BillingConfig(BaseModel): """ Platform Billing Configurations """ @@ -191,7 +191,7 @@ class BillingConfigs(BaseModel): ) -class UpdateConfigs(BaseModel): +class UpdateConfig(BaseModel): """ Update configs """ @@ -201,7 +201,7 @@ class UpdateConfigs(BaseModel): ) -class WorkflowConfigs(BaseModel): +class WorkflowConfig(BaseModel): """ Workflow feature configs """ @@ -222,7 +222,7 @@ class WorkflowConfigs(BaseModel): ) -class OAuthConfigs(BaseModel): +class OAuthConfig(BaseModel): """ oauth configs """ @@ -252,7 +252,7 @@ class OAuthConfigs(BaseModel): ) -class ModerationConfigs(BaseModel): +class ModerationConfig(BaseModel): """ Moderation in app configs. """ @@ -264,7 +264,7 @@ class ModerationConfigs(BaseModel): ) -class ToolConfigs(BaseModel): +class ToolConfig(BaseModel): """ Tool configs """ @@ -275,7 +275,7 @@ class ToolConfigs(BaseModel): ) -class MailConfigs(BaseModel): +class MailConfig(BaseModel): """ Mail Configurations """ @@ -331,7 +331,7 @@ class MailConfigs(BaseModel): ) -class RagEtlConfigs(BaseModel): +class RagEtlConfig(BaseModel): """ RAG ETL Configurations. """ @@ -357,7 +357,7 @@ class RagEtlConfigs(BaseModel): ) -class DataSetConfigs(BaseModel): +class DataSetConfig(BaseModel): """ Dataset configs """ @@ -368,7 +368,7 @@ class DataSetConfigs(BaseModel): ) -class WorkspaceConfigs(BaseModel): +class WorkspaceConfig(BaseModel): """ Workspace configs """ @@ -379,7 +379,7 @@ class WorkspaceConfigs(BaseModel): ) -class IndexingConfigs(BaseModel): +class IndexingConfig(BaseModel): """ Indexing configs. """ @@ -390,36 +390,36 @@ class IndexingConfigs(BaseModel): ) -class ImageFormatConfigs(BaseModel): +class ImageFormatConfig(BaseModel): MULTIMODAL_SEND_IMAGE_FORMAT: str = Field( description='multi model send image format, support base64, url, default is base64', default='base64', ) -class FeatureConfigs( +class FeatureConfig( # place the configs in alphabet order - AppExecutionConfigs, - BillingConfigs, - CodeExecutionSandboxConfigs, - DataSetConfigs, - EndpointConfigs, - FileAccessConfigs, - FileUploadConfigs, - HttpConfigs, - ImageFormatConfigs, - InnerAPIConfigs, - IndexingConfigs, - LoggingConfigs, - MailConfigs, - ModelLoadBalanceConfigs, - ModerationConfigs, - OAuthConfigs, - RagEtlConfigs, - SecurityConfigs, - ToolConfigs, - UpdateConfigs, - WorkflowConfigs, - WorkspaceConfigs, + AppExecutionConfig, + BillingConfig, + CodeExecutionSandboxConfig, + DataSetConfig, + EndpointConfig, + FileAccessConfig, + FileUploadConfig, + HttpConfig, + ImageFormatConfig, + InnerAPIConfig, + IndexingConfig, + LoggingConfig, + MailConfig, + ModelLoadBalanceConfig, + ModerationConfig, + OAuthConfig, + RagEtlConfig, + SecurityConfig, + ToolConfig, + UpdateConfig, + WorkflowConfig, + WorkspaceConfig, ): pass diff --git a/api/configs/middleware/__init__.py b/api/configs/middleware/__init__.py index 7aa6e9ccd5..f2093b918d 100644 --- a/api/configs/middleware/__init__.py +++ b/api/configs/middleware/__init__.py @@ -2,7 +2,7 @@ from typing import Optional from pydantic import BaseModel, Field -from configs.middleware.redis_configs import RedisConfigs +from configs.middleware.redis_config import RedisConfig from configs.middleware.vdb.chroma_configs import ChromaConfigs from configs.middleware.vdb.milvus_configs import MilvusConfigs from configs.middleware.vdb.opensearch_configs import OpenSearchConfigs @@ -44,10 +44,10 @@ class KeywordStoreConfigs(BaseModel): ) -class MiddlewareConfigs( +class MiddlewareConfig( # place the configs in alphabet order KeywordStoreConfigs, - RedisConfigs, + RedisConfig, StorageConfigs, # configs of vdb and vdb providers diff --git a/api/configs/middleware/redis_configs.py b/api/configs/middleware/redis_config.py similarity index 96% rename from api/configs/middleware/redis_configs.py rename to api/configs/middleware/redis_config.py index 9f98e7cabf..4cc40bbe6d 100644 --- a/api/configs/middleware/redis_configs.py +++ b/api/configs/middleware/redis_config.py @@ -3,7 +3,7 @@ from typing import Optional from pydantic import BaseModel, Field, NonNegativeInt, PositiveInt -class RedisConfigs(BaseModel): +class RedisConfig(BaseModel): """ Redis configs """ diff --git a/api/tests/unit_tests/settings/test_dify_settings.py b/api/tests/unit_tests/configs/test_dify_config.py similarity index 69% rename from api/tests/unit_tests/settings/test_dify_settings.py rename to api/tests/unit_tests/configs/test_dify_config.py index b5400d5c2c..b2e958b4d3 100644 --- a/api/tests/unit_tests/settings/test_dify_settings.py +++ b/api/tests/unit_tests/configs/test_dify_config.py @@ -3,7 +3,7 @@ from textwrap import dedent import pytest from flask import Flask -from configs.app_configs import DifyConfigs +from configs.app_config import DifyConfig EXAMPLE_ENV_FILENAME = '.env' @@ -19,32 +19,32 @@ def example_env_file(tmp_path, monkeypatch) -> str: return str(file_path) -def test_dify_configs_undefined_entry(example_env_file): +def test_dify_config_undefined_entry(example_env_file): # load dotenv file with pydantic-settings - settings = DifyConfigs(_env_file=example_env_file) + config = DifyConfig(_env_file=example_env_file) # entries not defined in app settings with pytest.raises(TypeError): # TypeError: 'AppSettings' object is not subscriptable - assert settings['LOG_LEVEL'] == 'INFO' + assert config['LOG_LEVEL'] == 'INFO' -def test_dify_configs(example_env_file): +def test_dify_config(example_env_file): # load dotenv file with pydantic-settings - settings = DifyConfigs(_env_file=example_env_file) + config = DifyConfig(_env_file=example_env_file) # constant values - assert settings.COMMIT_SHA == '' + assert config.COMMIT_SHA == '' # default values - assert settings.EDITION == 'SELF_HOSTED' - assert settings.API_COMPRESSION_ENABLED is False - assert settings.SENTRY_TRACES_SAMPLE_RATE == 1.0 + assert config.EDITION == 'SELF_HOSTED' + assert config.API_COMPRESSION_ENABLED is False + assert config.SENTRY_TRACES_SAMPLE_RATE == 1.0 def test_flask_configs(example_env_file): flask_app = Flask('app') - flask_app.config.from_mapping(DifyConfigs(_env_file=example_env_file).model_dump()) + flask_app.config.from_mapping(DifyConfig(_env_file=example_env_file).model_dump()) config = flask_app.config # configs read from dotenv directly