Skip to content

Commit

Permalink
pyflakes: consider 'unicode' a builtin even on py3 to support code
Browse files Browse the repository at this point in the history
compatible with both py2 and py3.
  • Loading branch information
schettino72 committed Mar 23, 2014
1 parent 1573e49 commit 91266d5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Changes
=======


0.1.1 (*2014-03-23*)
=======================

- pyflakes: consider 'unicode' a builtin even on py3 to support code
compatible with both py2 and py3.


0.1.0 (*2014-03-22*)
=======================

Expand Down
2 changes: 1 addition & 1 deletion doitpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = (0,1,0)
__version__ = (0,1,1)
7 changes: 6 additions & 1 deletion doitpy/pyflakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def task_pyflakes():
from __future__ import absolute_import

from pathlib import Path
from pyflakes.scripts.pyflakes import checkPath
from pyflakes.api import checkPath
from pyflakes.checker import Checker

from confclass import Config

Expand Down Expand Up @@ -61,6 +62,10 @@ def __call__(self, py_file):
:param str pyfile: path to file
:return: task metadata to run pyflakes on a single module
"""
# 'unicode' is a builtin in py2 but not on py3.
# Make sure pyflakes consider 'unicode' as a builtin so
# it does not fail on py3.
Checker.builtIns.add('unicode')
return {
'name': py_file,
'actions': [(check_path, [py_file])],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup (
name = 'doit-py',
version = '0.1.0',
version = '0.1.1',
author = 'Eduardo Naufel Schettino',
author_email = 'schettino72@gmail.com',
description = 'doit tasks for python stuff',
Expand Down
2 changes: 2 additions & 0 deletions tests/sample/flake_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# not valid python3 code but forgive it to support code that runs on py2 e py3
unicode('1234')
4 changes: 2 additions & 2 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestPythonPackage(object):
def test_init_tests_in_package(self):
pkg = PythonPackage(SAMPLE)
assert pkg.test_base == str(SAMPLE / 'tests')
assert len(pkg.src) == 2
assert len(pkg.src) == 3
assert str(SAMPLE / 'flake_ok.py') in pkg.src
assert str(SAMPLE / 'flake_fail.py') in pkg.src
assert len(pkg.test) == 1
Expand All @@ -25,7 +25,7 @@ def test_init_test_path(self):
def test_all_modules(self):
pkg = PythonPackage(SAMPLE)
all_modules = list(pkg.all_modules())
assert len(all_modules) == 3
assert len(all_modules) == 4
assert str(SAMPLE / 'flake_fail.py') in all_modules


Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyflakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def test_tasks(self):
obj = pyflakes.Pyflakes(base_dir=base_dir,
exclude_patterns=[exclude_pattern])
tasks = list(obj.tasks(check_pattern, exclude_paths=[exclude_path]))
assert len(tasks) == 1
assert len(tasks) == 2
assert tasks[0]['name'] == str(base_dir / 'flake_ok.py')

0 comments on commit 91266d5

Please sign in to comment.