| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
"""check_py24 command for setup.py. |
| 22 |
It checks syntax of Python modules by compiling them with Python 2.4. |
| 23 |
""" |
| 24 |
|
| 25 |
from distutils.core import Command |
| 26 |
from distutils.errors import DistutilsPlatformError |
| 27 |
from distutils import log |
| 28 |
import os |
| 29 |
import sys |
| 30 |
import traceback |
| 31 |
|
| 32 |
|
| 33 |
class check_py24(Command): |
| 34 |
|
| 35 |
description = ("check syntax of python modules " |
| 36 |
"by compiling them with Python 2.4") |
| 37 |
user_options = [] |
| 38 |
|
| 39 |
def initialize_options(self): |
| 40 |
pass |
| 41 |
|
| 42 |
def finalize_options(self): |
| 43 |
if sys.version_info[:2] != (2, 4): |
| 44 |
raise DistutilsPlatformError( |
| 45 |
'check_py24 command require Python 2.4') |
| 46 |
|
| 47 |
def run(self): |
| 48 |
for root, dirs, files in os.walk('.'): |
| 49 |
for fname in sorted(files): |
| 50 |
if fname.endswith('.py'): |
| 51 |
fullname = os.path.join(root, fname)[2:] |
| 52 |
|
| 53 |
if self.verbose: |
| 54 |
log.info('checking ' + fullname) |
| 55 |
if not self.dry_run: |
| 56 |
f = open(fullname, 'rU') |
| 57 |
content = f.read() |
| 58 |
f.close() |
| 59 |
try: |
| 60 |
compile(content, fullname, 'exec') |
| 61 |
except SyntaxError as e: |
| 62 |
log.error(str(e)) |
| 63 |
if self.verbose: |
| 64 |
traceback.print_exc(0) |
| 65 |
|
| 66 |
for dname in dirs[:]: |
| 67 |
fullname = os.path.join(root, dname).replace('\\','/') |
| 68 |
if fullname in ('./_lib', './build', './dist', './installer'): |
| 69 |
dirs.remove(dname) |