[Python-modules-commits] [pylint-flask] 01/04: initial commit
Daniel Stender
danstender-guest at moszumanska.debian.org
Sat Jan 23 19:12:40 UTC 2016
This is an automated email from the git hooks/post-receive script.
danstender-guest pushed a commit to branch master
in repository pylint-flask.
commit 81859562f1bffad762c61daec38b51082e80e3bf
Author: Daniel Stender <debian at danielstender.com>
Date: Sat Jan 23 19:34:05 2016 +0100
initial commit
---
PKG-INFO | 19 ++++
pylint_flask.egg-info/PKG-INFO | 19 ++++
pylint_flask.egg-info/SOURCES.txt | 8 ++
pylint_flask.egg-info/dependency_links.txt | 1 +
pylint_flask.egg-info/requires.txt | 4 +
pylint_flask.egg-info/top_level.txt | 1 +
pylint_flask/__init__.py | 143 +++++++++++++++++++++++++++++
setup.cfg | 5 +
setup.py | 57 ++++++++++++
test/test_func.py | 43 +++++++++
10 files changed, 300 insertions(+)
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..2e6b097
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: pylint-flask
+Version: 0.1
+Summary: pylint-flask is a Pylint plugin to aid Pylint in recognising and understandingerrors caused when using Flask
+Home-page: https://github.com/jschaf/pylint-flask
+Author: Joe Schafer
+Author-email: joe at jschaf.com
+License: GPLv2
+Description: UNKNOWN
+Keywords: pylint flask plugin
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: Operating System :: Unix
+Classifier: Topic :: Software Development :: Quality Assurance
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/pylint_flask.egg-info/PKG-INFO b/pylint_flask.egg-info/PKG-INFO
new file mode 100644
index 0000000..2e6b097
--- /dev/null
+++ b/pylint_flask.egg-info/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: pylint-flask
+Version: 0.1
+Summary: pylint-flask is a Pylint plugin to aid Pylint in recognising and understandingerrors caused when using Flask
+Home-page: https://github.com/jschaf/pylint-flask
+Author: Joe Schafer
+Author-email: joe at jschaf.com
+License: GPLv2
+Description: UNKNOWN
+Keywords: pylint flask plugin
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: Operating System :: Unix
+Classifier: Topic :: Software Development :: Quality Assurance
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/pylint_flask.egg-info/SOURCES.txt b/pylint_flask.egg-info/SOURCES.txt
new file mode 100644
index 0000000..befce4d
--- /dev/null
+++ b/pylint_flask.egg-info/SOURCES.txt
@@ -0,0 +1,8 @@
+setup.py
+pylint_flask/__init__.py
+pylint_flask.egg-info/PKG-INFO
+pylint_flask.egg-info/SOURCES.txt
+pylint_flask.egg-info/dependency_links.txt
+pylint_flask.egg-info/requires.txt
+pylint_flask.egg-info/top_level.txt
+test/test_func.py
\ No newline at end of file
diff --git a/pylint_flask.egg-info/dependency_links.txt b/pylint_flask.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/pylint_flask.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/pylint_flask.egg-info/requires.txt b/pylint_flask.egg-info/requires.txt
new file mode 100644
index 0000000..a098a37
--- /dev/null
+++ b/pylint_flask.egg-info/requires.txt
@@ -0,0 +1,4 @@
+pylint-plugin-utils>=0.2.1
+pylint>=1.0
+astroid>=1.0
+logilab-common>=0.60.0
\ No newline at end of file
diff --git a/pylint_flask.egg-info/top_level.txt b/pylint_flask.egg-info/top_level.txt
new file mode 100644
index 0000000..48c216e
--- /dev/null
+++ b/pylint_flask.egg-info/top_level.txt
@@ -0,0 +1 @@
+pylint_flask
diff --git a/pylint_flask/__init__.py b/pylint_flask/__init__.py
new file mode 100644
index 0000000..a5800b2
--- /dev/null
+++ b/pylint_flask/__init__.py
@@ -0,0 +1,143 @@
+'''pylint_flask module'''
+
+from astroid import MANAGER
+from astroid import nodes
+import re
+
+
+def register(_):
+ '''register is expected by pylint for plugins, but we are creating a transform,
+ not registering a checker.
+
+ '''
+ pass
+
+
+def copy_node_info(src, dest):
+ """Copy information from src to dest
+
+ Every node in the AST has to have line number information. Get
+ the information from the old stmt."""
+ for attr in ['lineno', 'fromlineno', 'tolineno',
+ 'col_offset', 'parent']:
+ if hasattr(src, attr):
+ setattr(dest, attr, getattr(src, attr))
+
+
+def mark_transformed(node):
+ '''Mark a node as transformed so we don't process it multiple times.'''
+ node.pylint_flask_was_transformed = True
+
+
+def is_transformed(node):
+ '''Return True if `node` was already transformed.'''
+ return getattr(node, 'pylint_flask_was_transformed', False)
+
+
+def make_non_magical_flask_import(flask_ext_name):
+ '''Convert a flask.ext.admin into flask_admin.'''
+ match = re.match(r'flask\.ext\.(.*)', flask_ext_name)
+ if match is None:
+ raise LookupError("Module name `{}` doesn't match"
+ "`flask.ext` style import.")
+ from_name = match.group(1)
+ actual_module_name = 'flask_{}'.format(from_name)
+ return actual_module_name
+
+
+def transform_flask_from_import(node):
+ '''Translates a flask.ext from-style import into a non-magical import.
+
+ Translates:
+ from flask.ext import wtf, bcrypt as fcrypt
+ Into:
+ import flask_wtf as wtf, flask_bcrypt as fcrypt
+
+ '''
+ new_names = []
+ # node.names is a list of 2-tuples. Each tuple consists of (name, as_name).
+ # So, the import would be represented as:
+ #
+ # from flask.ext import wtf as ftw, admin
+ #
+ # node.names = [('wtf', 'ftw'), ('admin', None)]
+ for (name, as_name) in node.names:
+ actual_module_name = 'flask_{}'.format(name)
+ new_names.append((actual_module_name, as_name or name))
+
+ new_node = nodes.Import()
+ copy_node_info(node, new_node)
+ new_node.names = new_names
+ mark_transformed(new_node)
+ return new_node
+
+
+def is_flask_from_import(node):
+ '''Predicate for checking if we have the flask module.'''
+ # Check for transformation first so we don't double process
+ return not is_transformed(node) and node.modname == 'flask.ext'
+
+MANAGER.register_transform(nodes.From,
+ transform_flask_from_import,
+ is_flask_from_import)
+
+
+def transform_flask_from_long(node):
+ '''Translates a flask.ext.wtf from-style import into a non-magical import.
+
+ Translates:
+ from flask.ext.wtf import Form
+ from flask.ext.admin.model import InlineFormAdmin
+ Into:
+ from flask_wtf import Form
+ from flask_admin.model import InlineFormAdmin
+
+ '''
+ actual_module_name = make_non_magical_flask_import(node.modname)
+ new_node = nodes.From(actual_module_name, node.names, node.level)
+ copy_node_info(node, new_node)
+ mark_transformed(new_node)
+ return new_node
+
+
+def is_flask_from_import_long(node):
+ '''Check if an import is like `from flask.ext.wtf import Form`.'''
+ # Check for transformation first so we don't double process
+ return not is_transformed(node) and node.modname.startswith('flask.ext.')
+
+MANAGER.register_transform(nodes.From,
+ transform_flask_from_long,
+ is_flask_from_import_long)
+
+
+def transform_flask_bare_import(node):
+ '''Translates a flask.ext.wtf bare import into a non-magical import.
+
+ Translates:
+ import flask.ext.admin as admin
+ Into:
+ import flask_admin as admin
+ '''
+
+ new_names = []
+ for (name, as_name) in node.names:
+ match = re.match(r'flask\.ext\.(.*)', name)
+ from_name = match.group(1)
+ actual_module_name = 'flask_{}'.format(from_name)
+ new_names.append((actual_module_name, as_name))
+
+ new_node = nodes.Import()
+ copy_node_info(node, new_node)
+ new_node.names = new_names
+ mark_transformed(new_node)
+ return new_node
+
+
+def is_flask_bare_import(node):
+ '''Check if an import is like `import flask.ext.admin as admin`.'''
+ return (not is_transformed(node)
+ and any(['flask.ext' in pair[0] for pair in node.names]))
+
+MANAGER.register_transform(nodes.Import,
+ transform_flask_bare_import,
+ is_flask_bare_import)
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..00bb0ae
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_date = 0
+tag_svn_revision = 0
+tag_build =
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..b2ffec3
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+from distutils.core import setup
+from setuptools import find_packages
+import sys
+
+
+_version = '0.1'
+_packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
+
+_short_description = "pylint-flask is a Pylint plugin to aid Pylint in recognising and understanding" \
+ "errors caused when using Flask"
+
+
+_classifiers = (
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'Operating System :: Unix',
+ 'Topic :: Software Development :: Quality Assurance',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
+)
+
+
+_install_requires = [
+ 'pylint-plugin-utils>=0.2.1'
+]
+
+
+if sys.version_info < (2, 7):
+ # pylint 1.4 dropped support for Python 2.6
+ _install_requires += [
+ 'pylint>=1.0,<1.4',
+ 'astroid>=1.0,<1.3.0',
+ 'logilab-common>=0.60.0,<0.63',
+ ]
+else:
+ _install_requires += [
+ 'pylint>=1.0',
+ 'astroid>=1.0',
+ 'logilab-common>=0.60.0',
+ ]
+
+setup(
+ name='pylint-flask',
+ url='https://github.com/jschaf/pylint-flask',
+ author='Joe Schafer',
+ author_email='joe at jschaf.com',
+ description=_short_description,
+ version=_version,
+ packages=_packages,
+ install_requires=_install_requires,
+ license='GPLv2',
+ classifiers=_classifiers,
+ keywords='pylint flask plugin'
+)
diff --git a/test/test_func.py b/test/test_func.py
new file mode 100644
index 0000000..e72e095
--- /dev/null
+++ b/test/test_func.py
@@ -0,0 +1,43 @@
+import os
+import unittest
+from logilab.common import testlib
+from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter
+
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+
+linter.load_plugin_modules(['pylint_flask'])
+# remove required __revision__
+linter.global_set_option('required-attributes', ())
+
+
+def module_exists(module_name):
+ try:
+ __import__(module_name)
+ except ImportError:
+ return False
+ else:
+ return True
+
+
+def tests(input_dir, messages_dir):
+ callbacks = [cb_test_gen(LintTestUsingFile)]
+
+ input_dir = os.path.join(HERE, input_dir)
+ messages_dir = os.path.join(HERE, messages_dir)
+
+ return make_tests(input_dir, messages_dir, None, callbacks)
+
+
+def suite():
+ test_list = tests('input', 'messages')
+
+ if module_exists('rest_framework'):
+ test_list += tests('external_drf', '')
+
+ return testlib.TestSuite(
+ [unittest.makeSuite(test, suiteClass=testlib.TestSuite)
+ for test in test_list])
+
+if __name__ == '__main__':
+ testlib.unittest_main(defaultTest='suite')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pylint-flask.git
More information about the Python-modules-commits
mailing list