Giter Club home page Giter Club logo

weops-framework's Introduction

WeOPS-Framework

更多资料/工具包下载可见“蓝鲸 S-mart市场”

https://bk.tencent.com/s-mart/application/282/detail

更多问题欢迎添加“小嘉”微信,加入官方沟通群

嘉为蓝鲸WeOPS基础框架使用说明

开发使用

框架目录

├── apps # 内置应用代码
├── apps_other # 自定义添加应用代码
├── base_index # 首页入口文件
├── blueapps # 蓝鲸内置应用
├── blueking # 蓝鲸API网关接口
├── config  # 配置文件
│    ├── template # 首页变量模板
│    ├── __init__.py # 基础配置文件
│    ├── default.py # 基础配置文件
│    ├── dev.py # 本地开发配置文件
│    ├── envs.json # 环境变量配置
│    ├── prod.py # 正式环境配置文件
│    ├── stag.py # 测试环境配置文件
├── locale # 语言包
├── packages # drf 配置
├── scripts # 脚本文件
│    ├── check_migrate # 校验提交模型字段
│    ├── check_commit_message.py # 校验提交信息是否包含规范的前缀
│    ├── check_requirements # 校验 requirements 是否符合要求
├── templates
├── utils # 内置工具包
├── .flake8 # flake8 效验规则配置
├── .gitignore
├── .isort.cfg # isort 规则
├── .pre-commit-config.yaml # pre-commit 配置
├── __init__.py
├── LICENSE
├── manage.py # 入口文件
├── pyproject.toml 
├── README.md
├── requirements.txt # 应用依赖包
├── runtime.txt # 应用运行python版本要求
├── settings.py # 应用基础配置文件
├── urls.py # 路由文件
├── wsgi.py # wsgi 配置启动

分支管理

  • main

main 是主分支。

集成工具说明

pre-commit

pre-commit 是基于 Git Hooks 的本地开发套件,支持通过插件扩展能力。目前支持 PEP8 规范检查、代码格式化、commit 信息检查、 requirements.txt 包检查等功能。

功能开发

环境安装

可使用pipenv,virtualenv,anaconda,此处仅演示anaconda

# 创建3.6虚拟环境
conda create --name auto-mate python=3.6
# 进入虚拟环境
conda activate venv
# 安装环境所需pip包
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 安装pre-commit
pip install pre-commit
pre-commit install --allow-missing-config
pre-commit install --hook-type commit-msg --allow-missing-config

正式开发

1、在apps_other目录下新建python包,包名必须以app_ 开头 新建python包 2、在对应包下新建config.py文件,需要包含以下内容:

app_name = "apps_other.app_test" # 应用名称,与新建的python包名保持一致并添加前缀apps_other.即可
celery_tasks = ("apps_other.test.celery_tasks",) # celery后台任务文件路径,如果不需要,可以不需要这个变量
add_middleware = ("apps_other.test.middleware.TestMiddleware",) # app自定义中间件,不需要可以不要这个变量
# 这里可以将app需要的其它变量配置到这里,注意变量命名须以 APP_ 开头

config.py

3、环境变量配置 如果开发过程中需要使用到环境变量,可以按照如下,选择一个.env文件添加 config.py 文件内容格式如下:

APP_ID=WEOPS
APP_TOKEN=123456

4、注意事项 开发过程中不要修改除apps_other目录外的其它文件 本地开发时,可以在根目录新建local_settings.py文件,并将database相关的配置信息写在里面

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "",  # noqa
        "USER": "",
        "PASSWORD": "",
        "HOST": "",
        "PORT": "",
        # 单元测试 DB 配置,建议不改动
        "TEST": {"NAME": "test_db", "CHARSET": "utf8", "COLLATION": "utf8_general_ci"},
    },
}

weops-framework's People

Contributors

baiyf-git avatar ericchencw avatar etherfurnace avatar xiaomaijiang avatar zhmf7408 avatar

weops-framework's Issues

执行python ./manage migrate 报错

执行python ./manage migrate 报错,错误提示如下:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/venv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/venv/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/blueapps/account/models.py", line 29, in <module>
    from blueapps.account.utils import sms
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/blueapps/account/utils/sms.py", line 15, in <module>
    from blueapps.utils import client
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/blueapps/utils/__init__.py", line 16, in <module>
    from blueapps.utils.esbclient import backend_client, client, get_client_by_request, get_client_by_user
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/blueapps/utils/esbclient.py", line 211, in <module>
    client = SDKClient()
  File "/Users/kira/Documents/workspaces/opensource/weops-framework/blueapps/utils/esbclient.py", line 84, in __new__
    raise ImportError("{} is not installed: {}".format(ESB_SDK_NAME, e))
ImportError: blueking.component is not installed: No module named 'utils.performance'

ModuleNotFoundError: No module named 'apps.app_tests'

When I try to add the package app_tests into app_others and run python manage.py runserver dev.weops.com:8000, an exception is raised.

File "xxx\weops-framework\urls.py", line 34, in <module>
  urlpatterns.append(url(r"^{}/".format(i), include(f"apps.{i}.urls")))  # noqa
File "xxx\weops-framework\venv\lib\site-packages\django\urls\conf.py", line 34, in include
  urlconf_module = import_module(urlconf_module)
File "xxx\weops-framework\lib\importlib\__init__.py", line 126, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apps.app_tests'

It seems that the following code is unable to import the urls from the app_test app correctly.

for i in dir_list:
    urlpatterns.append(url(r"^{}/".format(i), include(f"apps.{i}.urls")))  # noqa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.