flask-projects


Nameflask-projects JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/ababbabbb/flask_project_core
Summaryflask projects系列快速开发手脚架
upload_time2024-05-18 11:15:22
maintainerNone
docs_urlNone
authorbichuantao
requires_python>=3.6
licenseMIT
keywords python flask projects rapid development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Flask_Project系列



## 项目进度



进行中



## 项目介绍



* 本项目基于flask及其生态

* 本项目属于手脚架性质

* 借助本项目以及后续补充甚至自定义的扩展,可以快速开发工程化业务代码



## 环境依赖



* 本项目开发时使用的python版本为3.8

* 核心部分代码依赖flask、click(flask最新版本已包含对click的安装需要,仅安装flask即可顺带完成对click的安装),可直接执行`pip install flask`完成安装

* 临时文件夹(tamp)中的扩展(extends)中,restful扩展依赖flask_restful,可直接执行`pip install flask-restful`完成安装



## 项目结构



```│

│  README.md

│

├─core

│  │  __init__.py

│  │

│  ├─order

│  │  │  executor.py

│  │  │  __init__.py

│  │  │

│  │  └─unity

│  │        run.py

│  │        shell.py

│  │        __init__.py

│  │

│  ├─proj

│  │     abs.py

│  │     project.py

│  │     __init__.py

│  │

│  └─vars

│        abs.py

│        application.py

│        extends.py

│        http.py

│        info.py

│        others.py

│        __init__.py

│

├─default

│  │  __init__.py

│  │

│  ├─app

│  │     factory.py

│  │     __init__.py

│  │

│  ├─business

│  │     __init__.py

│  │

│  ├─configuration

│  │  │  convention.py

│  │  │  NameFactory.py

│  │  │  __init__.py

│  │  │

│  │  ├─plan_1

│  │  │      __init__.py

│  │  │

│  │  └─plan_default

│  │        container.py

│  │        logic.py

│  │        scanner.py

│  │        __init__.py

│  │

│  ├─resource

│  │     __init__.py

│  │

│  └─router

│     │  convention.py

│     │  NameFactory.py

│     │  __init__.py

│     │

│     └─plan_0

│           container.py

│           logic.py

│           order.py

│           scanner.py

│           __init__.py

│

├─example

│  │  main.py

│  │

│  ├─business

│  │  └─router

│  │         Restful.py

│  │         Unity.py

│  │         __init__.py

│  │

│  └─resource

│      └─test

│            example.http

│

└─tamp

│  __init__.py

│

└──extends

    │  │  __init__.py

    │  │

    │  ├─ddd

    │  │      __init__.py

    │  │

    │  ├─health

    │  │      __init__.py

    │  │

    │  ├─mvc

    │  │      __init__.py

    │  │

    │  └─restful

    │        container.py

    │        convertion.py

    │        logic.py

    │        scanner.py

    │        __init__.py

    │

    │

    └─interface

          base.py

          container.py

          factory.py

          logic.py

          order.py

          scanner.py

          init__.py



```



## 设计概述



* 本项目主要围绕extend——扩展的概念展开设计,项目本身仅提供core、default两个模块

* core模块作为项目运行的核心,尽可能削减了运行时,除扩展以外所需要的一切外部依赖,其在flask提供的基础网络能力的基础上,参考django的设计,提供了以下模块及其对应的能力:

  * proj:

    * proj即project的缩写,旨在为项目的运行提供机制

    * 其内仅包含两个文件,abs、project,abs是project模块的抽象基类,project则是当前提供机制的根本模块

  * order:

    * order即命令,其设计参考django的指令设计,基于click为本项目提供了命令行执行的能力

    * 其内部由executor与unity两个部分组成,其中,executor为项目集成命令行能力提供了基础,使得project能够借此为项目添加各式各样的命令行,同时,unity也为项目提供了一些内置的命令(run、shell,run用于运行项目,shell则可以使开发人员将现有的代码设计作为依赖,通过命令行的形式对设计进行验证)

    * order除去使用内置指令之外,也可以通过extend的方式进行增加

  * vars:

    * vars即变量,参考flask对于app各种扩展的绑定机制,为项目在其内部提供了变量的概念,一切的扩展、数据、信息,均统一存放在各式各样的变量当中,并集成到project,以此为项目的运行提供支持

    * abs,一切项目变量最根本的抽象基类,为变量规定了所必须具备的能力(插入、查询、删除);由此也可以看出,变量的概念,其实一定程度上,是为了让project能够使用为各种数据、信息专门定制的数据结构/数据容器对项目进行管理而演变出来的

    * application:管理flask app的变量绑定

    * extends:管理项目运行所需的扩展

    * http:管理项目中与http通讯相关的数据,如:url

    * info:管理项目本身的一些基础信息

    * others:管理一些不成体系,但又必须记录的数据/信息

    * 所有的变量均采用单例的设计,即在该项目运行的进程内,仅会存在一个对应类型的变量

    * 变量是支持开发人员自行增加的(但不支持删减),可以通过extends,在其真正绑定和影响项目时,为其添加变量,为快速开发提供便利

* defualt模块中存放的主要是内置的扩展(即extends),包括app、配置、目录结构、路由能力等

  * app:为flask app提供支持,同时方便在特殊情况下,使用第三方所写就的更多类型的app进行替换

  * business、resource:规定该扩展规定了业务代码中必须包含business、resource两个文件目录,具体原因及设计初衷可见该扩展的注释

  * configuration:为业务代码所必须要进行的配置提供统一的支持与管理

  * router:为项目提供最基本的路由能力

* tamp仅作为临时目录,存放当前开发进行中所需的依赖,如自定义扩展所需实现的接口、目前已实现的,但不适合作为内置扩展的extend,后续将分别将其打做第三方包的形式为项目提供支持,目前仅作便利考虑,存放在本项目源代码目录中

* extend,作为项目的核心概念,其参考spring生态、flask生态、日常业务代码开发的各种小工具,为项目提供各式各样的能力,期望在此基础上,借助扩展的力量,实现业务代码的工程化和业务代码开发的便捷化;其本身要求必须依照规定的接口进行实现,包括scanner、container、logic、order

  * scanner:扫描器,用于扫描项目中指定位置的模块/文件,并读取目标数据/信息,以提供给container

  * container:存放扩展所需管理/操作的数据,建议在这一步当中,组合上述vars的能力,方便进行统一管理,同时,该概念本身也如同var一样,从某种程度上是为了方便定制该扩展对应数据所需的数据结构而产生

  * logic:对container所保存的数据进行统一处理,同时也是真正意义上扩展的能力集成到项目中这一过程的代码实现

  * order(可选):该接口是否需要实现由扩展开发者自行决定;order本身是借助click,为项目添加各式各样命令行所用

  * extend有一个子类替代的机制,即:当在后续绑定到项目的扩展,出现了已有扩展的子类,且该子类的扩展名称变量name与父类相同(倘若name不同,则不会出现子类替代的现象),则直接到该父类在var变量中的位置进行替换,而不在变量中进行追加



## 使用说明



* 项目运行:

  * 必须确保项目中,main文件同级存在resource、business两个文件夹/模块包(内置扩展business、resource规定)                              ![img_0.png](assets/img_0.png?t=1715328226489)

  * main文件必须导入并配置project,而后调用byorder方法

    ```

    from core import project





    project.setter_args(

        ip='0.0.0.0',

        port='8080',

        path=__file__

    )





    if __name__ == '__main__':

        project.byOrder()

    ```

  * 在命令行使用`python main.py run`运行项目,或者使用`python main.py shell`进入python shell进行验证,同时,也可以通过`python main.py --help`查看当前项目所支持的命令行

  * 也可以通过pycharm,为main文件添加脚本参数run/shell/--help直接进行运行或调试

* 扩展配置

  * 扩展配置可以通过调用project提供的setter_extend方法完成,且可以多次调用



    ```

    from core import project

    from tamp.extends.restful.container import RestfulContainer

    from tamp.extends.restful.logic import RestfulLogic

    from tamp.extends.restful.scanner import RestfulScanner





    project.setter_args(

        ip='0.0.0.0',

        port='8080',

        path=__file__

    ).setter_extend(

        RestfulScanner,

        RestfulContainer,

        RestfulLogic

    )





    if __name__ == '__main__':

        project.byOrder()



    ```

* app替换、参数配置可参考project初始化方法

  * ![image_1.png](assets/image_1.png?t=1715326870305)

* 所有setter方法均参考方法链思想,返回值均为对象本身,可连续调用

* 扩展编写(以restful举例)

  * scanner

    ```scanner.py

    import importlib

    import os

    import traceback



    from default.router.convention import RouterBasic

    from default.router.plan_0.scanner import Plan0RouterScanner

    from tamp.extends.restful.convertion import RestfulRouterBasic





    class RestfulScanner(Plan0RouterScanner):



        def scan(self, path_dir: str):

            cls_route = []



            for r, d, filenames in os.walk(path_dir):

                if 'business' not in r or 'router' not in r:

                    continue



                for filename in filenames:

                    if filename == '__init__.py' or not filename.endswith('.py'):

                        continue



                    try:

                        module = importlib.machinery.SourceFileLoader(

                            filename.replace(',py', ''), os.path.join(r, filename)

                        ).load_module()



                        class_imported = getattr(module, filename.replace('.py', ''))

                        if issubclass(class_imported, RouterBasic) or issubclass(class_imported, RestfulRouterBasic):

                            cls_route.append(class_imported)



                    except Exception:

                        print(traceback.format_exc())



            return cls_route



    ```

  * contaniner(借用了子类重载机制)

    ```container.py

    from default.router.plan_0.container import Plan0RouterContainer





    class RestfulContainer(Plan0RouterContainer):



        ...



    ```

  * logic(借用了子类重载机制)

    ```logic.py

    from default.router.plan_0.logic import Plan0RouterLogic





    class RestfulLogic(Plan0RouterLogic):



        ...



    ```

  * order(以内置模块router为例)

    ```order.py

    import click



    from core.vars.http import http

    from default.router.NameFactory import name_extend

    from tamp.interface.order import OrderAbs





    @click.command('routes')

    def routes():



        for route in http.query_router():



            click.echo(route)





    orders = [routes]





    class Plan0RouterOrder(OrderAbs):

        name = name_extend



        def get_orders(self) -> list:



            return orders



    ```



## 后续计划



* 补充内置extend——middle,为中间件的编写提供基础能力支持

* 参考spring生态各类集成,逐步增加各种extend

* 将扩展接口作为第三方包,支持pip下载,便于在不依赖本项目的前提下开发外部extend,并对当前项目做出对应调整

* 将tamp中的各类extends打作第三方包,支持pip下载


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ababbabbb/flask_project_core",
    "name": "flask-projects",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "python, flask, projects, Rapid development",
    "author": "bichuantao",
    "author_email": "17826066203@163.com",
    "download_url": "https://files.pythonhosted.org/packages/eb/65/3afa7873ffaaf30ba439088e58e5987691aba3a6457a4984c584a2b64827/flask-projects-0.0.3.tar.gz",
    "platform": null,
    "description": "\r\n# Flask_Project\u7cfb\u5217\r\r\n\r\r\n## \u9879\u76ee\u8fdb\u5ea6\r\r\n\r\r\n\u8fdb\u884c\u4e2d\r\r\n\r\r\n## \u9879\u76ee\u4ecb\u7ecd\r\r\n\r\r\n* \u672c\u9879\u76ee\u57fa\u4e8eflask\u53ca\u5176\u751f\u6001\r\r\n* \u672c\u9879\u76ee\u5c5e\u4e8e\u624b\u811a\u67b6\u6027\u8d28\r\r\n* \u501f\u52a9\u672c\u9879\u76ee\u4ee5\u53ca\u540e\u7eed\u8865\u5145\u751a\u81f3\u81ea\u5b9a\u4e49\u7684\u6269\u5c55\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u53d1\u5de5\u7a0b\u5316\u4e1a\u52a1\u4ee3\u7801\r\r\n\r\r\n## \u73af\u5883\u4f9d\u8d56\r\r\n\r\r\n* \u672c\u9879\u76ee\u5f00\u53d1\u65f6\u4f7f\u7528\u7684python\u7248\u672c\u4e3a3.8\r\r\n* \u6838\u5fc3\u90e8\u5206\u4ee3\u7801\u4f9d\u8d56flask\u3001click(flask\u6700\u65b0\u7248\u672c\u5df2\u5305\u542b\u5bf9click\u7684\u5b89\u88c5\u9700\u8981\uff0c\u4ec5\u5b89\u88c5flask\u5373\u53ef\u987a\u5e26\u5b8c\u6210\u5bf9click\u7684\u5b89\u88c5)\uff0c\u53ef\u76f4\u63a5\u6267\u884c`pip install flask`\u5b8c\u6210\u5b89\u88c5\r\r\n* \u4e34\u65f6\u6587\u4ef6\u5939(tamp)\u4e2d\u7684\u6269\u5c55(extends)\u4e2d\uff0crestful\u6269\u5c55\u4f9d\u8d56flask_restful\uff0c\u53ef\u76f4\u63a5\u6267\u884c`pip install flask-restful`\u5b8c\u6210\u5b89\u88c5\r\r\n\r\r\n## \u9879\u76ee\u7ed3\u6784\r\r\n\r\r\n```\u2502\r\r\n\u2502  README.md\r\r\n\u2502\r\r\n\u251c\u2500core\r\r\n\u2502  \u2502  __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500order\r\r\n\u2502  \u2502  \u2502  executor.py\r\r\n\u2502  \u2502  \u2502  __init__.py\r\r\n\u2502  \u2502  \u2502\r\r\n\u2502  \u2502  \u2514\u2500unity\r\r\n\u2502  \u2502        run.py\r\r\n\u2502  \u2502        shell.py\r\r\n\u2502  \u2502        __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500proj\r\r\n\u2502  \u2502     abs.py\r\r\n\u2502  \u2502     project.py\r\r\n\u2502  \u2502     __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u2514\u2500vars\r\r\n\u2502        abs.py\r\r\n\u2502        application.py\r\r\n\u2502        extends.py\r\r\n\u2502        http.py\r\r\n\u2502        info.py\r\r\n\u2502        others.py\r\r\n\u2502        __init__.py\r\r\n\u2502\r\r\n\u251c\u2500default\r\r\n\u2502  \u2502  __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500app\r\r\n\u2502  \u2502     factory.py\r\r\n\u2502  \u2502     __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500business\r\r\n\u2502  \u2502     __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500configuration\r\r\n\u2502  \u2502  \u2502  convention.py\r\r\n\u2502  \u2502  \u2502  NameFactory.py\r\r\n\u2502  \u2502  \u2502  __init__.py\r\r\n\u2502  \u2502  \u2502\r\r\n\u2502  \u2502  \u251c\u2500plan_1\r\r\n\u2502  \u2502  \u2502      __init__.py\r\r\n\u2502  \u2502  \u2502\r\r\n\u2502  \u2502  \u2514\u2500plan_default\r\r\n\u2502  \u2502        container.py\r\r\n\u2502  \u2502        logic.py\r\r\n\u2502  \u2502        scanner.py\r\r\n\u2502  \u2502        __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500resource\r\r\n\u2502  \u2502     __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u2514\u2500router\r\r\n\u2502     \u2502  convention.py\r\r\n\u2502     \u2502  NameFactory.py\r\r\n\u2502     \u2502  __init__.py\r\r\n\u2502     \u2502\r\r\n\u2502     \u2514\u2500plan_0\r\r\n\u2502           container.py\r\r\n\u2502           logic.py\r\r\n\u2502           order.py\r\r\n\u2502           scanner.py\r\r\n\u2502           __init__.py\r\r\n\u2502\r\r\n\u251c\u2500example\r\r\n\u2502  \u2502  main.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u251c\u2500business\r\r\n\u2502  \u2502  \u2514\u2500router\r\r\n\u2502  \u2502         Restful.py\r\r\n\u2502  \u2502         Unity.py\r\r\n\u2502  \u2502         __init__.py\r\r\n\u2502  \u2502\r\r\n\u2502  \u2514\u2500resource\r\r\n\u2502      \u2514\u2500test\r\r\n\u2502            example.http\r\r\n\u2502\r\r\n\u2514\u2500tamp\r\r\n\u2502  __init__.py\r\r\n\u2502\r\r\n\u2514\u2500\u2500extends\r\r\n    \u2502  \u2502  __init__.py\r\r\n    \u2502  \u2502\r\r\n    \u2502  \u251c\u2500ddd\r\r\n    \u2502  \u2502      __init__.py\r\r\n    \u2502  \u2502\r\r\n    \u2502  \u251c\u2500health\r\r\n    \u2502  \u2502      __init__.py\r\r\n    \u2502  \u2502\r\r\n    \u2502  \u251c\u2500mvc\r\r\n    \u2502  \u2502      __init__.py\r\r\n    \u2502  \u2502\r\r\n    \u2502  \u2514\u2500restful\r\r\n    \u2502        container.py\r\r\n    \u2502        convertion.py\r\r\n    \u2502        logic.py\r\r\n    \u2502        scanner.py\r\r\n    \u2502        __init__.py\r\r\n    \u2502\r\r\n    \u2502\r\r\n    \u2514\u2500interface\r\r\n          base.py\r\r\n          container.py\r\r\n          factory.py\r\r\n          logic.py\r\r\n          order.py\r\r\n          scanner.py\r\r\n          init__.py\r\r\n\r\r\n```\r\r\n\r\r\n## \u8bbe\u8ba1\u6982\u8ff0\r\r\n\r\r\n* \u672c\u9879\u76ee\u4e3b\u8981\u56f4\u7ed5extend\u2014\u2014\u6269\u5c55\u7684\u6982\u5ff5\u5c55\u5f00\u8bbe\u8ba1\uff0c\u9879\u76ee\u672c\u8eab\u4ec5\u63d0\u4f9bcore\u3001default\u4e24\u4e2a\u6a21\u5757\r\r\n* core\u6a21\u5757\u4f5c\u4e3a\u9879\u76ee\u8fd0\u884c\u7684\u6838\u5fc3\uff0c\u5c3d\u53ef\u80fd\u524a\u51cf\u4e86\u8fd0\u884c\u65f6\uff0c\u9664\u6269\u5c55\u4ee5\u5916\u6240\u9700\u8981\u7684\u4e00\u5207\u5916\u90e8\u4f9d\u8d56\uff0c\u5176\u5728flask\u63d0\u4f9b\u7684\u57fa\u7840\u7f51\u7edc\u80fd\u529b\u7684\u57fa\u7840\u4e0a\uff0c\u53c2\u8003django\u7684\u8bbe\u8ba1\uff0c\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u6a21\u5757\u53ca\u5176\u5bf9\u5e94\u7684\u80fd\u529b\uff1a\r\r\n  * proj\uff1a\r\r\n    * proj\u5373project\u7684\u7f29\u5199\uff0c\u65e8\u5728\u4e3a\u9879\u76ee\u7684\u8fd0\u884c\u63d0\u4f9b\u673a\u5236\r\r\n    * \u5176\u5185\u4ec5\u5305\u542b\u4e24\u4e2a\u6587\u4ef6\uff0cabs\u3001project\uff0cabs\u662fproject\u6a21\u5757\u7684\u62bd\u8c61\u57fa\u7c7b\uff0cproject\u5219\u662f\u5f53\u524d\u63d0\u4f9b\u673a\u5236\u7684\u6839\u672c\u6a21\u5757\r\r\n  * order\uff1a\r\r\n    * order\u5373\u547d\u4ee4\uff0c\u5176\u8bbe\u8ba1\u53c2\u8003django\u7684\u6307\u4ee4\u8bbe\u8ba1\uff0c\u57fa\u4e8eclick\u4e3a\u672c\u9879\u76ee\u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u6267\u884c\u7684\u80fd\u529b\r\r\n    * \u5176\u5185\u90e8\u7531executor\u4e0eunity\u4e24\u4e2a\u90e8\u5206\u7ec4\u6210\uff0c\u5176\u4e2d\uff0cexecutor\u4e3a\u9879\u76ee\u96c6\u6210\u547d\u4ee4\u884c\u80fd\u529b\u63d0\u4f9b\u4e86\u57fa\u7840\uff0c\u4f7f\u5f97project\u80fd\u591f\u501f\u6b64\u4e3a\u9879\u76ee\u6dfb\u52a0\u5404\u5f0f\u5404\u6837\u7684\u547d\u4ee4\u884c\uff0c\u540c\u65f6\uff0cunity\u4e5f\u4e3a\u9879\u76ee\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u7684\u547d\u4ee4(run\u3001shell\uff0crun\u7528\u4e8e\u8fd0\u884c\u9879\u76ee\uff0cshell\u5219\u53ef\u4ee5\u4f7f\u5f00\u53d1\u4eba\u5458\u5c06\u73b0\u6709\u7684\u4ee3\u7801\u8bbe\u8ba1\u4f5c\u4e3a\u4f9d\u8d56\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u7684\u5f62\u5f0f\u5bf9\u8bbe\u8ba1\u8fdb\u884c\u9a8c\u8bc1)\r\r\n    * order\u9664\u53bb\u4f7f\u7528\u5185\u7f6e\u6307\u4ee4\u4e4b\u5916\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7extend\u7684\u65b9\u5f0f\u8fdb\u884c\u589e\u52a0\r\r\n  * vars\uff1a\r\r\n    * vars\u5373\u53d8\u91cf\uff0c\u53c2\u8003flask\u5bf9\u4e8eapp\u5404\u79cd\u6269\u5c55\u7684\u7ed1\u5b9a\u673a\u5236\uff0c\u4e3a\u9879\u76ee\u5728\u5176\u5185\u90e8\u63d0\u4f9b\u4e86\u53d8\u91cf\u7684\u6982\u5ff5\uff0c\u4e00\u5207\u7684\u6269\u5c55\u3001\u6570\u636e\u3001\u4fe1\u606f\uff0c\u5747\u7edf\u4e00\u5b58\u653e\u5728\u5404\u5f0f\u5404\u6837\u7684\u53d8\u91cf\u5f53\u4e2d\uff0c\u5e76\u96c6\u6210\u5230project\uff0c\u4ee5\u6b64\u4e3a\u9879\u76ee\u7684\u8fd0\u884c\u63d0\u4f9b\u652f\u6301\r\r\n    * abs\uff0c\u4e00\u5207\u9879\u76ee\u53d8\u91cf\u6700\u6839\u672c\u7684\u62bd\u8c61\u57fa\u7c7b\uff0c\u4e3a\u53d8\u91cf\u89c4\u5b9a\u4e86\u6240\u5fc5\u987b\u5177\u5907\u7684\u80fd\u529b(\u63d2\u5165\u3001\u67e5\u8be2\u3001\u5220\u9664)\uff1b\u7531\u6b64\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0c\u53d8\u91cf\u7684\u6982\u5ff5\uff0c\u5176\u5b9e\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\uff0c\u662f\u4e3a\u4e86\u8ba9project\u80fd\u591f\u4f7f\u7528\u4e3a\u5404\u79cd\u6570\u636e\u3001\u4fe1\u606f\u4e13\u95e8\u5b9a\u5236\u7684\u6570\u636e\u7ed3\u6784/\u6570\u636e\u5bb9\u5668\u5bf9\u9879\u76ee\u8fdb\u884c\u7ba1\u7406\u800c\u6f14\u53d8\u51fa\u6765\u7684\r\r\n    * application\uff1a\u7ba1\u7406flask app\u7684\u53d8\u91cf\u7ed1\u5b9a\r\r\n    * extends\uff1a\u7ba1\u7406\u9879\u76ee\u8fd0\u884c\u6240\u9700\u7684\u6269\u5c55\r\r\n    * http\uff1a\u7ba1\u7406\u9879\u76ee\u4e2d\u4e0ehttp\u901a\u8baf\u76f8\u5173\u7684\u6570\u636e\uff0c\u5982\uff1aurl\r\r\n    * info\uff1a\u7ba1\u7406\u9879\u76ee\u672c\u8eab\u7684\u4e00\u4e9b\u57fa\u7840\u4fe1\u606f\r\r\n    * others\uff1a\u7ba1\u7406\u4e00\u4e9b\u4e0d\u6210\u4f53\u7cfb\uff0c\u4f46\u53c8\u5fc5\u987b\u8bb0\u5f55\u7684\u6570\u636e/\u4fe1\u606f\r\r\n    * \u6240\u6709\u7684\u53d8\u91cf\u5747\u91c7\u7528\u5355\u4f8b\u7684\u8bbe\u8ba1\uff0c\u5373\u5728\u8be5\u9879\u76ee\u8fd0\u884c\u7684\u8fdb\u7a0b\u5185\uff0c\u4ec5\u4f1a\u5b58\u5728\u4e00\u4e2a\u5bf9\u5e94\u7c7b\u578b\u7684\u53d8\u91cf\r\r\n    * \u53d8\u91cf\u662f\u652f\u6301\u5f00\u53d1\u4eba\u5458\u81ea\u884c\u589e\u52a0\u7684(\u4f46\u4e0d\u652f\u6301\u5220\u51cf)\uff0c\u53ef\u4ee5\u901a\u8fc7extends\uff0c\u5728\u5176\u771f\u6b63\u7ed1\u5b9a\u548c\u5f71\u54cd\u9879\u76ee\u65f6\uff0c\u4e3a\u5176\u6dfb\u52a0\u53d8\u91cf\uff0c\u4e3a\u5feb\u901f\u5f00\u53d1\u63d0\u4f9b\u4fbf\u5229\r\r\n* defualt\u6a21\u5757\u4e2d\u5b58\u653e\u7684\u4e3b\u8981\u662f\u5185\u7f6e\u7684\u6269\u5c55(\u5373extends)\uff0c\u5305\u62ecapp\u3001\u914d\u7f6e\u3001\u76ee\u5f55\u7ed3\u6784\u3001\u8def\u7531\u80fd\u529b\u7b49\r\r\n  * app\uff1a\u4e3aflask app\u63d0\u4f9b\u652f\u6301\uff0c\u540c\u65f6\u65b9\u4fbf\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u7b2c\u4e09\u65b9\u6240\u5199\u5c31\u7684\u66f4\u591a\u7c7b\u578b\u7684app\u8fdb\u884c\u66ff\u6362\r\r\n  * business\u3001resource\uff1a\u89c4\u5b9a\u8be5\u6269\u5c55\u89c4\u5b9a\u4e86\u4e1a\u52a1\u4ee3\u7801\u4e2d\u5fc5\u987b\u5305\u542bbusiness\u3001resource\u4e24\u4e2a\u6587\u4ef6\u76ee\u5f55\uff0c\u5177\u4f53\u539f\u56e0\u53ca\u8bbe\u8ba1\u521d\u8877\u53ef\u89c1\u8be5\u6269\u5c55\u7684\u6ce8\u91ca\r\r\n  * configuration\uff1a\u4e3a\u4e1a\u52a1\u4ee3\u7801\u6240\u5fc5\u987b\u8981\u8fdb\u884c\u7684\u914d\u7f6e\u63d0\u4f9b\u7edf\u4e00\u7684\u652f\u6301\u4e0e\u7ba1\u7406\r\r\n  * router\uff1a\u4e3a\u9879\u76ee\u63d0\u4f9b\u6700\u57fa\u672c\u7684\u8def\u7531\u80fd\u529b\r\r\n* tamp\u4ec5\u4f5c\u4e3a\u4e34\u65f6\u76ee\u5f55\uff0c\u5b58\u653e\u5f53\u524d\u5f00\u53d1\u8fdb\u884c\u4e2d\u6240\u9700\u7684\u4f9d\u8d56\uff0c\u5982\u81ea\u5b9a\u4e49\u6269\u5c55\u6240\u9700\u5b9e\u73b0\u7684\u63a5\u53e3\u3001\u76ee\u524d\u5df2\u5b9e\u73b0\u7684\uff0c\u4f46\u4e0d\u9002\u5408\u4f5c\u4e3a\u5185\u7f6e\u6269\u5c55\u7684extend\uff0c\u540e\u7eed\u5c06\u5206\u522b\u5c06\u5176\u6253\u505a\u7b2c\u4e09\u65b9\u5305\u7684\u5f62\u5f0f\u4e3a\u9879\u76ee\u63d0\u4f9b\u652f\u6301\uff0c\u76ee\u524d\u4ec5\u4f5c\u4fbf\u5229\u8003\u8651\uff0c\u5b58\u653e\u5728\u672c\u9879\u76ee\u6e90\u4ee3\u7801\u76ee\u5f55\u4e2d\r\r\n* extend\uff0c\u4f5c\u4e3a\u9879\u76ee\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5176\u53c2\u8003spring\u751f\u6001\u3001flask\u751f\u6001\u3001\u65e5\u5e38\u4e1a\u52a1\u4ee3\u7801\u5f00\u53d1\u7684\u5404\u79cd\u5c0f\u5de5\u5177\uff0c\u4e3a\u9879\u76ee\u63d0\u4f9b\u5404\u5f0f\u5404\u6837\u7684\u80fd\u529b\uff0c\u671f\u671b\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u501f\u52a9\u6269\u5c55\u7684\u529b\u91cf\uff0c\u5b9e\u73b0\u4e1a\u52a1\u4ee3\u7801\u7684\u5de5\u7a0b\u5316\u548c\u4e1a\u52a1\u4ee3\u7801\u5f00\u53d1\u7684\u4fbf\u6377\u5316\uff1b\u5176\u672c\u8eab\u8981\u6c42\u5fc5\u987b\u4f9d\u7167\u89c4\u5b9a\u7684\u63a5\u53e3\u8fdb\u884c\u5b9e\u73b0\uff0c\u5305\u62ecscanner\u3001container\u3001logic\u3001order\r\r\n  * scanner\uff1a\u626b\u63cf\u5668\uff0c\u7528\u4e8e\u626b\u63cf\u9879\u76ee\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u7684\u6a21\u5757/\u6587\u4ef6\uff0c\u5e76\u8bfb\u53d6\u76ee\u6807\u6570\u636e/\u4fe1\u606f\uff0c\u4ee5\u63d0\u4f9b\u7ed9container\r\r\n  * container\uff1a\u5b58\u653e\u6269\u5c55\u6240\u9700\u7ba1\u7406/\u64cd\u4f5c\u7684\u6570\u636e\uff0c\u5efa\u8bae\u5728\u8fd9\u4e00\u6b65\u5f53\u4e2d\uff0c\u7ec4\u5408\u4e0a\u8ff0vars\u7684\u80fd\u529b\uff0c\u65b9\u4fbf\u8fdb\u884c\u7edf\u4e00\u7ba1\u7406\uff0c\u540c\u65f6\uff0c\u8be5\u6982\u5ff5\u672c\u8eab\u4e5f\u5982\u540cvar\u4e00\u6837\uff0c\u4ece\u67d0\u79cd\u7a0b\u5ea6\u4e0a\u662f\u4e3a\u4e86\u65b9\u4fbf\u5b9a\u5236\u8be5\u6269\u5c55\u5bf9\u5e94\u6570\u636e\u6240\u9700\u7684\u6570\u636e\u7ed3\u6784\u800c\u4ea7\u751f\r\r\n  * logic\uff1a\u5bf9container\u6240\u4fdd\u5b58\u7684\u6570\u636e\u8fdb\u884c\u7edf\u4e00\u5904\u7406\uff0c\u540c\u65f6\u4e5f\u662f\u771f\u6b63\u610f\u4e49\u4e0a\u6269\u5c55\u7684\u80fd\u529b\u96c6\u6210\u5230\u9879\u76ee\u4e2d\u8fd9\u4e00\u8fc7\u7a0b\u7684\u4ee3\u7801\u5b9e\u73b0\r\r\n  * order(\u53ef\u9009)\uff1a\u8be5\u63a5\u53e3\u662f\u5426\u9700\u8981\u5b9e\u73b0\u7531\u6269\u5c55\u5f00\u53d1\u8005\u81ea\u884c\u51b3\u5b9a\uff1border\u672c\u8eab\u662f\u501f\u52a9click\uff0c\u4e3a\u9879\u76ee\u6dfb\u52a0\u5404\u5f0f\u5404\u6837\u547d\u4ee4\u884c\u6240\u7528\r\r\n  * extend\u6709\u4e00\u4e2a\u5b50\u7c7b\u66ff\u4ee3\u7684\u673a\u5236\uff0c\u5373\uff1a\u5f53\u5728\u540e\u7eed\u7ed1\u5b9a\u5230\u9879\u76ee\u7684\u6269\u5c55\uff0c\u51fa\u73b0\u4e86\u5df2\u6709\u6269\u5c55\u7684\u5b50\u7c7b\uff0c\u4e14\u8be5\u5b50\u7c7b\u7684\u6269\u5c55\u540d\u79f0\u53d8\u91cfname\u4e0e\u7236\u7c7b\u76f8\u540c(\u5018\u82e5name\u4e0d\u540c\uff0c\u5219\u4e0d\u4f1a\u51fa\u73b0\u5b50\u7c7b\u66ff\u4ee3\u7684\u73b0\u8c61)\uff0c\u5219\u76f4\u63a5\u5230\u8be5\u7236\u7c7b\u5728var\u53d8\u91cf\u4e2d\u7684\u4f4d\u7f6e\u8fdb\u884c\u66ff\u6362\uff0c\u800c\u4e0d\u5728\u53d8\u91cf\u4e2d\u8fdb\u884c\u8ffd\u52a0\r\r\n\r\r\n## \u4f7f\u7528\u8bf4\u660e\r\r\n\r\r\n* \u9879\u76ee\u8fd0\u884c\uff1a\r\r\n  * \u5fc5\u987b\u786e\u4fdd\u9879\u76ee\u4e2d\uff0cmain\u6587\u4ef6\u540c\u7ea7\u5b58\u5728resource\u3001business\u4e24\u4e2a\u6587\u4ef6\u5939/\u6a21\u5757\u5305(\u5185\u7f6e\u6269\u5c55business\u3001resource\u89c4\u5b9a)                              ![img_0.png](assets/img_0.png?t=1715328226489)\r\r\n  * main\u6587\u4ef6\u5fc5\u987b\u5bfc\u5165\u5e76\u914d\u7f6eproject\uff0c\u800c\u540e\u8c03\u7528byorder\u65b9\u6cd5\r\r\n    ```\r\r\n    from core import project\r\r\n\r\r\n\r\r\n    project.setter_args(\r\r\n        ip='0.0.0.0',\r\r\n        port='8080',\r\r\n        path=__file__\r\r\n    )\r\r\n\r\r\n\r\r\n    if __name__ == '__main__':\r\r\n        project.byOrder()\r\r\n    ```\r\r\n  * \u5728\u547d\u4ee4\u884c\u4f7f\u7528`python main.py run`\u8fd0\u884c\u9879\u76ee\uff0c\u6216\u8005\u4f7f\u7528`python main.py shell`\u8fdb\u5165python shell\u8fdb\u884c\u9a8c\u8bc1\uff0c\u540c\u65f6\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7`python main.py --help`\u67e5\u770b\u5f53\u524d\u9879\u76ee\u6240\u652f\u6301\u7684\u547d\u4ee4\u884c\r\r\n  * \u4e5f\u53ef\u4ee5\u901a\u8fc7pycharm\uff0c\u4e3amain\u6587\u4ef6\u6dfb\u52a0\u811a\u672c\u53c2\u6570run/shell/--help\u76f4\u63a5\u8fdb\u884c\u8fd0\u884c\u6216\u8c03\u8bd5\r\r\n* \u6269\u5c55\u914d\u7f6e\r\r\n  * \u6269\u5c55\u914d\u7f6e\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528project\u63d0\u4f9b\u7684setter_extend\u65b9\u6cd5\u5b8c\u6210\uff0c\u4e14\u53ef\u4ee5\u591a\u6b21\u8c03\u7528\r\r\n\r\r\n    ```\r\r\n    from core import project\r\r\n    from tamp.extends.restful.container import RestfulContainer\r\r\n    from tamp.extends.restful.logic import RestfulLogic\r\r\n    from tamp.extends.restful.scanner import RestfulScanner\r\r\n\r\r\n\r\r\n    project.setter_args(\r\r\n        ip='0.0.0.0',\r\r\n        port='8080',\r\r\n        path=__file__\r\r\n    ).setter_extend(\r\r\n        RestfulScanner,\r\r\n        RestfulContainer,\r\r\n        RestfulLogic\r\r\n    )\r\r\n\r\r\n\r\r\n    if __name__ == '__main__':\r\r\n        project.byOrder()\r\r\n\r\r\n    ```\r\r\n* app\u66ff\u6362\u3001\u53c2\u6570\u914d\u7f6e\u53ef\u53c2\u8003project\u521d\u59cb\u5316\u65b9\u6cd5\r\r\n  * ![image_1.png](assets/image_1.png?t=1715326870305)\r\r\n* \u6240\u6709setter\u65b9\u6cd5\u5747\u53c2\u8003\u65b9\u6cd5\u94fe\u601d\u60f3\uff0c\u8fd4\u56de\u503c\u5747\u4e3a\u5bf9\u8c61\u672c\u8eab\uff0c\u53ef\u8fde\u7eed\u8c03\u7528\r\r\n* \u6269\u5c55\u7f16\u5199(\u4ee5restful\u4e3e\u4f8b)\r\r\n  * scanner\r\r\n    ```scanner.py\r\r\n    import importlib\r\r\n    import os\r\r\n    import traceback\r\r\n\r\r\n    from default.router.convention import RouterBasic\r\r\n    from default.router.plan_0.scanner import Plan0RouterScanner\r\r\n    from tamp.extends.restful.convertion import RestfulRouterBasic\r\r\n\r\r\n\r\r\n    class RestfulScanner(Plan0RouterScanner):\r\r\n\r\r\n        def scan(self, path_dir: str):\r\r\n            cls_route = []\r\r\n\r\r\n            for r, d, filenames in os.walk(path_dir):\r\r\n                if 'business' not in r or 'router' not in r:\r\r\n                    continue\r\r\n\r\r\n                for filename in filenames:\r\r\n                    if filename == '__init__.py' or not filename.endswith('.py'):\r\r\n                        continue\r\r\n\r\r\n                    try:\r\r\n                        module = importlib.machinery.SourceFileLoader(\r\r\n                            filename.replace(',py', ''), os.path.join(r, filename)\r\r\n                        ).load_module()\r\r\n\r\r\n                        class_imported = getattr(module, filename.replace('.py', ''))\r\r\n                        if issubclass(class_imported, RouterBasic) or issubclass(class_imported, RestfulRouterBasic):\r\r\n                            cls_route.append(class_imported)\r\r\n\r\r\n                    except Exception:\r\r\n                        print(traceback.format_exc())\r\r\n\r\r\n            return cls_route\r\r\n\r\r\n    ```\r\r\n  * contaniner(\u501f\u7528\u4e86\u5b50\u7c7b\u91cd\u8f7d\u673a\u5236)\r\r\n    ```container.py\r\r\n    from default.router.plan_0.container import Plan0RouterContainer\r\r\n\r\r\n\r\r\n    class RestfulContainer(Plan0RouterContainer):\r\r\n\r\r\n        ...\r\r\n\r\r\n    ```\r\r\n  * logic(\u501f\u7528\u4e86\u5b50\u7c7b\u91cd\u8f7d\u673a\u5236)\r\r\n    ```logic.py\r\r\n    from default.router.plan_0.logic import Plan0RouterLogic\r\r\n\r\r\n\r\r\n    class RestfulLogic(Plan0RouterLogic):\r\r\n\r\r\n        ...\r\r\n\r\r\n    ```\r\r\n  * order(\u4ee5\u5185\u7f6e\u6a21\u5757router\u4e3a\u4f8b)\r\r\n    ```order.py\r\r\n    import click\r\r\n\r\r\n    from core.vars.http import http\r\r\n    from default.router.NameFactory import name_extend\r\r\n    from tamp.interface.order import OrderAbs\r\r\n\r\r\n\r\r\n    @click.command('routes')\r\r\n    def routes():\r\r\n\r\r\n        for route in http.query_router():\r\r\n\r\r\n            click.echo(route)\r\r\n\r\r\n\r\r\n    orders = [routes]\r\r\n\r\r\n\r\r\n    class Plan0RouterOrder(OrderAbs):\r\r\n        name = name_extend\r\r\n\r\r\n        def get_orders(self) -> list:\r\r\n\r\r\n            return orders\r\r\n\r\r\n    ```\r\r\n\r\r\n## \u540e\u7eed\u8ba1\u5212\r\r\n\r\r\n* \u8865\u5145\u5185\u7f6eextend\u2014\u2014middle\uff0c\u4e3a\u4e2d\u95f4\u4ef6\u7684\u7f16\u5199\u63d0\u4f9b\u57fa\u7840\u80fd\u529b\u652f\u6301\r\r\n* \u53c2\u8003spring\u751f\u6001\u5404\u7c7b\u96c6\u6210\uff0c\u9010\u6b65\u589e\u52a0\u5404\u79cdextend\r\r\n* \u5c06\u6269\u5c55\u63a5\u53e3\u4f5c\u4e3a\u7b2c\u4e09\u65b9\u5305\uff0c\u652f\u6301pip\u4e0b\u8f7d\uff0c\u4fbf\u4e8e\u5728\u4e0d\u4f9d\u8d56\u672c\u9879\u76ee\u7684\u524d\u63d0\u4e0b\u5f00\u53d1\u5916\u90e8extend\uff0c\u5e76\u5bf9\u5f53\u524d\u9879\u76ee\u505a\u51fa\u5bf9\u5e94\u8c03\u6574\r\r\n* \u5c06tamp\u4e2d\u7684\u5404\u7c7bextends\u6253\u4f5c\u7b2c\u4e09\u65b9\u5305\uff0c\u652f\u6301pip\u4e0b\u8f7d\r\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "flask projects\u7cfb\u5217\u5feb\u901f\u5f00\u53d1\u624b\u811a\u67b6",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/ababbabbb/flask_project_core"
    },
    "split_keywords": [
        "python",
        " flask",
        " projects",
        " rapid development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb653afa7873ffaaf30ba439088e58e5987691aba3a6457a4984c584a2b64827",
                "md5": "a480f282e19cb26d0872c2e6a087c251",
                "sha256": "759225d3d4e882c7684c87c0ea8cd1ee5e336ce05fa86038deb46ca3b1adc967"
            },
            "downloads": -1,
            "filename": "flask-projects-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a480f282e19cb26d0872c2e6a087c251",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 25765,
            "upload_time": "2024-05-18T11:15:22",
            "upload_time_iso_8601": "2024-05-18T11:15:22.310646Z",
            "url": "https://files.pythonhosted.org/packages/eb/65/3afa7873ffaaf30ba439088e58e5987691aba3a6457a4984c584a2b64827/flask-projects-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-18 11:15:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ababbabbb",
    "github_project": "flask_project_core",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flask-projects"
}
        
Elapsed time: 0.26723s