systematic use of from __future__ import absolute_import. it eliminates import NAME confusion with very common names (eg. import ldap is very ambiguous: can be a ldap module from realms-wiki, a ldap module from flask-ldap-login, or python-ldap module.

also cleant up a bit the import towards PEP8: builtin modules first, then 3rd party python packages, then local packages
This commit is contained in:
stef 2016-08-20 00:48:00 +02:00 committed by Stephane Martin
parent 2919be6b87
commit 2731531768
38 changed files with 156 additions and 42 deletions

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
import functools
import sys
@ -9,8 +11,10 @@ sys.setdefaultencoding('utf-8')
import base64
import time
import json
import httplib
import traceback
import six.moves.http_client as httplib
from functools import update_wrapper
import click
from flask import Flask, request, render_template, url_for, redirect, g
from flask_cache import Cache
@ -18,7 +22,6 @@ from flask_login import LoginManager, current_user
from flask_sqlalchemy import SQLAlchemy
from flask_assets import Environment, Bundle
from flask_ldap_login import LDAPLoginManager
from functools import update_wrapper
from werkzeug.routing import BaseConverter
from werkzeug.exceptions import HTTPException
from sqlalchemy.ext.declarative import declarative_base

View file

@ -1,14 +1,18 @@
from realms import config, create_app, db, __version__, cli, cache
from realms.lib.util import random_string, in_virtualenv, green, yellow, red
from subprocess import call, Popen
from multiprocessing import cpu_count
import click
from __future__ import absolute_import
import json
import sys
import os
import pip
import time
import subprocess
from subprocess import call, Popen
from multiprocessing import cpu_count
import click
import pip
from . import config, create_app, db, __version__, cli, cache
from .lib.util import random_string, in_virtualenv, green, yellow, red
config = config.conf

View file

@ -1,9 +1,12 @@
from __future__ import absolute_import
import json
import os
import sys
from urlparse import urlparse
from realms.lib.util import in_vagrant
from six.moves.urllib.parse import urlparse
from ..lib.util import in_vagrant
class Config(object):

View file

@ -0,0 +1,2 @@
from __future__ import absolute_import

View file

@ -1,7 +1,10 @@
from flask_sqlalchemy import DeclarativeMeta
from __future__ import absolute_import
from functools import wraps
from flask_sqlalchemy import DeclarativeMeta
def hook_func(name, fn):
@wraps(fn)

View file

@ -1,7 +1,11 @@
from __future__ import absolute_import
import json
from sqlalchemy import not_, and_
from datetime import datetime
from realms import db
from sqlalchemy import not_, and_
from .. import db
class Model(db.Model):

View file

@ -1,7 +1,11 @@
from __future__ import absolute_import
import os
import shutil
import tempfile
from flask_testing import TestCase
from realms.lib.util import random_string
from realms import create_app

View file

@ -1,4 +1,5 @@
import click
from __future__ import absolute_import
import re
import os
import hashlib
@ -6,6 +7,8 @@ import json
import string
import random
import sys
import click
from jinja2 import Template

View file

@ -0,0 +1 @@
from __future__ import absolute_import

View file

@ -1,7 +1,10 @@
from realms import login_manager
from __future__ import absolute_import
from flask import request, flash, redirect
from flask_login import login_url
from ... import login_manager
modules = set()
@login_manager.unauthorized_handler

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from ..models import Auth
Auth.register('ldap')

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from flask_wtf import Form
from wtforms import StringField, PasswordField, validators

View file

@ -1,7 +1,10 @@
from __future__ import absolute_import
from flask import render_template
from flask_login import login_user
from realms import ldap
from flask_ldap_login import LDAPLoginForm
from realms import ldap
from ..models import BaseUser

View file

@ -1,7 +1,15 @@
<<<<<<< HEAD
from flask import current_app, request, redirect, Blueprint, flash, url_for, session
from ..ldap.models import User
=======
from __future__ import absolute_import
from flask import current_app, request, redirect, Blueprint, flash, url_for
>>>>>>> systematic use of `from __future__ import absolute_import`. it eliminates `import NAME` confusion with very common names (eg. `import ldap` is very ambiguous: can be a ldap module from realms-wiki, a ldap module from flask-ldap-login, or `python-ldap` module.
from flask_ldap_login import LDAPLoginForm
from .models import User
blueprint = Blueprint('auth.ldap', __name__)

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from ..models import Auth
Auth.register('local')

View file

@ -1,8 +1,11 @@
from __future__ import absolute_import
import click
from realms.lib.util import random_string
from realms.modules.auth.local.models import User
from realms.lib.util import green, red, yellow
from realms import cli_group
from .models import User
from ....lib.util import random_string
from ....lib.util import green, red, yellow
from .... import cli_group
@cli_group(short_help="Auth Module")

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from flask_wtf import Form
from wtforms import StringField, PasswordField, validators

View file

@ -1,5 +1,8 @@
from __future__ import absolute_import
from flask import current_app
from flask_wtf import RecaptchaField
from .forms import RegistrationForm

View file

@ -1,11 +1,15 @@
from __future__ import absolute_import
from hashlib import sha256
from flask import current_app, render_template
from flask_login import logout_user, login_user
from itsdangerous import URLSafeSerializer, BadSignature
from realms import login_manager, db
from realms.lib.model import Model
from ..models import BaseUser
from .forms import LoginForm
from itsdangerous import URLSafeSerializer, BadSignature
from hashlib import sha256
@login_manager.token_loader

View file

@ -1,6 +1,10 @@
from __future__ import absolute_import
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for, session
from realms.modules.auth.local.models import User
from realms.modules.auth.local.forms import LoginForm, RegistrationForm
from .models import User
from .forms import LoginForm, RegistrationForm
blueprint = Blueprint('auth.local', __name__)

View file

@ -1,12 +1,16 @@
from __future__ import absolute_import
import importlib
from hashlib import sha256
from flask import current_app
from flask_login import UserMixin, logout_user, AnonymousUserMixin
from itsdangerous import URLSafeSerializer, BadSignature
import bcrypt
from realms import login_manager
from realms.lib.util import gravatar_url
from itsdangerous import URLSafeSerializer, BadSignature
from hashlib import sha256
from . import modules
import bcrypt
import importlib
@login_manager.user_loader

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from ..models import Auth
Auth.register('oauth')

View file

@ -1,8 +1,10 @@
from __future__ import absolute_import
from flask import session
from flask_login import login_user
from flask_oauthlib.client import OAuth
from realms import config
from .... import config
from ..models import BaseUser
config = config.conf

View file

@ -1,3 +1,5 @@
from __future__ import absolute_import
from flask import Blueprint, url_for, request, flash, redirect, session, current_app
from .models import User

View file

@ -0,0 +1 @@
from __future__ import absolute_import

View file

@ -1,7 +1,11 @@
from __future__ import absolute_import
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for, session
from flask_login import logout_user
from realms.modules.auth.models import Auth
blueprint = Blueprint('auth', __name__, template_folder='templates')

View file

@ -0,0 +1 @@
from __future__ import absolute_import

View file

@ -1,7 +1,10 @@
from __future__ import absolute_import
import click
from flask import current_app
from realms import search, cli_group
from realms.modules.wiki.models import Wiki
from ... import search, cli_group
from ..wiki.models import Wiki
@cli_group(short_help="Search Module")

View file

@ -1,5 +1,7 @@
from realms.modules.wiki.models import WikiPage
from realms import search
from __future__ import absolute_import
from ..wiki.models import WikiPage
from ... import search
@WikiPage.after('write')

View file

@ -1,8 +1,11 @@
from __future__ import absolute_import
import re
import sys
from flask import g, current_app
from realms.lib.util import filename_to_cname
from ...lib.util import filename_to_cname
def simple(app):

View file

@ -1,7 +1,11 @@
from __future__ import absolute_import
from flask import render_template, request, Blueprint, current_app
from flask_login import current_user
from realms import search as search_engine
blueprint = Blueprint('search', __name__, template_folder='templates')

View file

@ -1,6 +1,9 @@
from __future__ import absolute_import
import os
import sys
from realms.modules.wiki.models import Wiki
from .models import Wiki
def init(app):

View file

@ -1,4 +1,6 @@
from realms import assets
from __future__ import absolute_import
from ... import assets
assets.register('editor.js',
'vendor/store-js/store.js',

View file

@ -1,4 +1,7 @@
from __future__ import absolute_import
from flask import g, current_app
from .models import Wiki

View file

@ -1,13 +1,17 @@
from __future__ import absolute_import
import os
import posixpath
import re
import ghdiff
import yaml
from dulwich.object_store import tree_lookup_path
from dulwich.repo import Repo, NotGitRepository
from realms.lib.util import cname_to_filename, filename_to_cname
from realms import cache
from realms.lib.hook import HookMixin
from ...lib.util import cname_to_filename, filename_to_cname
from ... import cache
from ...lib.hook import HookMixin
class PageNotFound(Exception):

View file

@ -1,8 +1,12 @@
from __future__ import absolute_import
import json
from nose.tools import *
from flask import url_for
from realms.lib.util import cname_to_filename, filename_to_cname
from realms.lib.test import BaseTest
from ...lib.util import cname_to_filename, filename_to_cname
from ...lib.test import BaseTest
class WikiBaseTest(BaseTest):

View file

@ -1,11 +1,16 @@
from __future__ import absolute_import
import itertools
import sys
from datetime import datetime
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask_login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__, template_folder='templates',
static_folder='static', static_url_path='/static/wiki')

View file

@ -1 +1,3 @@
from __future__ import absolute_import
__version__ = '0.8.1'