Skip to content

Commit 3c63a37

Browse files
committed
initial commit
0 parents  commit 3c63a37

15 files changed

+593
-0
lines changed

.coveragerc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
source=pylint_werkzeug

.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### https://raw.github.com/github/gitignore/14b7566ce157ce95b07006466bacee160f242284/python.gitignore
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
env/
13+
build/
14+
develop-eggs/
15+
dist/
16+
eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.cache
41+
nosetests.xml
42+
coverage.xml
43+
44+
# Translations
45+
*.mo
46+
*.pot
47+
48+
# Django stuff:
49+
*.log
50+
51+
# Sphinx documentation
52+
docs/_build/
53+
54+
# PyBuilder
55+
target/
56+
57+

.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sudo: false
2+
language: python
3+
python:
4+
- "2.6"
5+
- "2.7"
6+
- "3.3"
7+
- "3.4"
8+
install:
9+
scripts/travis-install.sh
10+
script:
11+
scripts/travis-build.sh
12+
after_success:
13+
coveralls

LICENSE

+339
Large diffs are not rendered by default.

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pylint-flask
2+
===============
3+
4+
[![Build Status](https://travis-ci.org/jschaf/pylint-flask.svg?branch=master)](https://travis-ci.org/jschaf/pylint-flask) [![Coverage Status](https://coveralls.io/repos/jschaf/pylint-flask/badge.svg)](https://coveralls.io/r/jschaf/pylint-flask)
5+
6+
## About
7+
8+
`pylint-flask` is [Pylint](http://pylint.org) plugin for improving code
9+
analysis when editing code using [Flask](http://flask.pocoo.org/).
10+
Inspired by [pylint-django](https://github.com/landscapeio/pylint-django).
11+
12+
## Usage
13+
14+
Ensure `pylint-flask` is installed and on your path, and then run pylint.
15+
16+
```
17+
pip install pylint-flask
18+
pylint --load-plugins pylint_flask [..your module..]
19+
```
20+
21+
## License
22+
23+
pylint-flask is available under the GPLv2 license.

dev-requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
logilab-common==0.63.2
2+
pylint==1.4.3
3+
Flask==0.10.1
4+
Flask-WTF==0.11

pylint_flask/__init__.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''pylint_flask module'''
2+
3+
from astroid import MANAGER
4+
from astroid.builder import AstroidBuilder
5+
from astroid import nodes
6+
import textwrap
7+
8+
9+
def register(_):
10+
'''register is expected by pylint for plugins, but we are creating a transform,
11+
not registering a checker.
12+
13+
'''
14+
pass
15+
16+
17+
def flask_transform(_):
18+
'''Replace Flask module with the imports it lazily loads.'''
19+
pass
20+
# module = AstroidBuilder().string_build(code)
21+
# module.name = 'flask'
22+
# return module
23+
24+
25+
def is_flask_module(node):
26+
'''Predicate for checking if we have the flask module.'''
27+
return node.name == 'flask'
28+
29+
MANAGER.register_transform(nodes.Module,
30+
flask_transform,
31+
is_flask_module)

scripts/test.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
python test/test_func.py

scripts/travis-build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
coverage run test/test_func.py

scripts/travis-install.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
pip install --use-mirrors coverage coveralls
3+
pip install --use-mirrors flask
4+
pip install --use-mirrors git+https://github.com/landscapeio/pylint-plugin-utils.git@develop
5+
pip install --use-mirrors --editable .

setup.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
from distutils.core import setup
3+
from setuptools import find_packages
4+
import sys
5+
6+
7+
_version = '0.1'
8+
_packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
9+
10+
_short_description = "pylint-flask is a Pylint plugin to aid Pylint in recognising and understanding" \
11+
"errors caused when using Flask"
12+
13+
14+
_classifiers = (
15+
'Development Status :: 4 - Beta',
16+
'Environment :: Console',
17+
'Intended Audience :: Developers',
18+
'Operating System :: Unix',
19+
'Topic :: Software Development :: Quality Assurance',
20+
'Programming Language :: Python :: 2.7',
21+
'Programming Language :: Python :: 3.3',
22+
'Programming Language :: Python :: 3.4',
23+
)
24+
25+
26+
_install_requires = [
27+
'pylint-plugin-utils>=0.2.1'
28+
]
29+
30+
31+
if sys.version_info < (2, 7):
32+
# pylint 1.4 dropped support for Python 2.6
33+
_install_requires += [
34+
'pylint>=1.0,<1.4',
35+
'astroid>=1.0,<1.3.0',
36+
'logilab-common>=0.60.0,<0.63',
37+
]
38+
else:
39+
_install_requires += [
40+
'pylint>=1.0',
41+
'astroid>=1.0',
42+
'logilab-common>=0.60.0',
43+
]
44+
45+
setup(
46+
name='pylint-flask',
47+
url='https://github.com/jschaf/pylint-flask',
48+
author='Joe Schafer',
49+
author_email='[email protected]',
50+
description=_short_description,
51+
version=_version,
52+
packages=_packages,
53+
install_requires=_install_requires,
54+
license='GPLv2',
55+
classifiers=_classifiers,
56+
keywords='pylint flask plugin'
57+
)

test/input/__init__.py

Whitespace-only changes.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'''Ensure that pylint finds the exported methods from flask.ext.'''
2+
3+
from flask.ext import wtf
4+
5+
MYFORM = wtf.Form

test/test_func.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import unittest
3+
from logilab.common import testlib
4+
from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter
5+
6+
7+
HERE = os.path.dirname(os.path.abspath(__file__))
8+
9+
linter.load_plugin_modules(['pylint_flask'])
10+
# remove required __revision__
11+
linter.global_set_option('required-attributes', ())
12+
13+
14+
def module_exists(module_name):
15+
try:
16+
__import__(module_name)
17+
except ImportError:
18+
return False
19+
else:
20+
return True
21+
22+
23+
def tests(input_dir, messages_dir):
24+
callbacks = [cb_test_gen(LintTestUsingFile)]
25+
26+
input_dir = os.path.join(HERE, input_dir)
27+
messages_dir = os.path.join(HERE, messages_dir)
28+
29+
return make_tests(input_dir, messages_dir, None, callbacks)
30+
31+
32+
def suite():
33+
test_list = tests('input', 'messages')
34+
35+
if module_exists('rest_framework'):
36+
test_list += tests('external_drf', '')
37+
38+
return testlib.TestSuite(
39+
[unittest.makeSuite(test, suiteClass=testlib.TestSuite)
40+
for test in test_list])
41+
42+
if __name__ == '__main__':
43+
testlib.unittest_main(defaultTest='suite')

tox.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tox]
2+
envlist = py26,py27,py34
3+
4+
[testenv]
5+
deps=flask
6+
flask-wtf
7+
pylint
8+
astroid
9+
logilab-common
10+
commands=python test/test_func.py

0 commit comments

Comments
 (0)