【发布时间】:2015-06-05 00:23:39
【问题描述】:
所以Pylint (1.4.3) 正在报告循环导入,这没有多大意义。
首先,report 文件没有 import 语句。
第二个没有文件导入参考文件。 __init__.py 文件从 development_config (有问题的文件)加载配置值,但没有文件
导入上述文件。
那么为什么 Pylint 会给我这个警告呢?
Pylint 警告
************* Module heart_beat.development_config
R: 1, 0: Cyclic import (heart_beat -> heart_beat.views -> heart_beat.models) (cyclic-import)
R: 1, 0: Cyclic import (heart_beat -> heart_beat.views) (cyclic-import)
development_config
""" -------------------------- DATA BASE CONFINGURATION --------------------"""
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
SQLALCHEMY_ECHO = False
""" -------------------------- Flask Application Config --------------------"""
THREADS_PER_PAGE = 8
VERSION = "0.1"
__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
#from register_assets import register_all
app = Flask(__name__, static_url_path='/static')
# the environment variable LIMBO_SETTINGS is set in runserver, run_unit_tests
# or limbo.wsgi.
def load_configs():
"""Take all configs found in development_config.py."""
app.config.from_pyfile("development_config.py", silent=False)
load_configs()
# global SQLAlchemy configuration
db = SQLAlchemy(app)
#Create and register all static asset bundles.
#register_all(app)
#NOTE: DON'T LISTEN TO YOUR IDE! heart_beat.views is used and required.
import heart_beat.views # views contains all URL routes, Importing sets routes.
def setup_db():
"""Database creation in a file rather then a statement for easier tests."""
db.create_all()
def teardown_db():
"""Database deletion in a file rather then a statement for easier tests."""
db.drop_all()
setup_db()
views.py
from flask import request
from . import app
from . import db
from . import models
from . import exceptions as ex
models.py
import datetime
from . import exceptions
from . import db
from . import app
【问题讨论】:
-
我不确定它为什么专门调用 development_config,但你确实有循环导入(应用程序(
__init__.py)导入视图,视图导入应用程序)。通常在烧瓶中,人们会使用蓝图在单独的文件中定义视图。这个大型烧瓶项目组织得很好,值得一看:github.com/masom/bluemonk
标签: python python-3.x flask pylint