Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[setup] hooks 3to2 into build command
- Loading branch information
1 parent
5232a88
commit 380d4e2
Showing
3 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
''' | ||
Add 'from __future__ import absolute_import' to any file | ||
that uses imports. | ||
''' | ||
from lib2to3 import fixer_base | ||
from lib2to3.pygram import python_symbols as syms | ||
from lib3to2.fixer_util import future_import | ||
|
||
class FixPymorFutures(fixer_base.BaseFix): | ||
order = 'post' | ||
run_order = 10 | ||
|
||
def __init__(self, options, log): | ||
super(FixPymorFutures, self).__init__(options, log) | ||
self.__pymor_added = None | ||
|
||
def start_tree(self, tree, filename): | ||
super(FixPymorFutures, self).start_tree(tree, filename) | ||
self.__pymor_added = False | ||
|
||
def match(self, node): | ||
return (node.type in (syms.import_name, syms.import_from) | ||
and not self.__pymor_added) | ||
|
||
def transform(self, node, results): | ||
try: | ||
future_import('absolute_import', node) | ||
future_import('division', node) | ||
future_import('print_function', node) | ||
except ValueError: | ||
pass | ||
else: | ||
self.__pymor_added = True | ||
|
||
def finish_tree(self, tree, filename): | ||
fixer_base.BaseFix.finish_tree(self, tree, filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters