1
#!/usr/bin/env python2.7
2
# Copyright 2012 Canonical Ltd. This software is licensed under the
3
# GNU Affero General Public License version 3 (see the file LICENSE).
5
"""Ensure that __future__ import lines are populated correctly."""
7
from __future__ import (
19
re_futures = re.compile(
20
r"^(from __future__ import) [(](.*?)[)]", re.DOTALL | re.MULTILINE)
23
mandatory_future_imports = frozenset(
24
("absolute_import", "print_function", "unicode_literals"))
28
imports = set().union(
29
(name.strip() for name in match.group(2).split(",")),
30
mandatory_future_imports)
32
imports = "".join(" %s,\n" % name for name in sorted(imports))
33
return "%s (\n%s )" % (match.group(1), imports)
36
if __name__ == '__main__':
37
for filename in sys.argv[1:]:
38
with open(filename, "rb") as fd:
40
source = re_futures.sub(replace, source)
41
with open(filename, "wb") as fd: