I'd like to run pylint on our buildbot files in an automated presubmit check
but pylint hardcodes the file types it is willing to load and our
configuration files ends with .cfg. The following diff makes it work in my
case but that obviously doesn't fly.
diff -r c34ce2658999 modutils.py
--- a/modutils.py Thu Sep 30 11:46:45 2010 +0200
+++ b/modutils.py Wed Oct 06 15:41:47 2010 -0400
@@ -55,7 +55,7 @@
PY_COMPILED_EXTS = ('dll', 'pyd')
STD_LIB_DIR = get_python_lib(standard_lib=1)
else:
- PY_SOURCE_EXTS = ('py',)
+ PY_SOURCE_EXTS = ('py', 'cfg')
PY_COMPILED_EXTS = ('so',)
# extend lib dir with some arch-dependant paths
STD_LIB_DIR = join(get_config_var("LIBDIR"), "python%s" %
get_python_version())
So I came up with a different code path to read the first line to check if
'python' is present and consider it a python file in that case. Does this
looks good to be integrated in the main branch?
diff -r c34ce2658999 modutils.py
--- a/modutils.py Thu Sep 30 11:46:45 2010 +0200
+++ b/modutils.py Wed Oct 06 15:50:49 2010 -0400
@@ -43,6 +43,7 @@
ZIPFILE = object()
from logilab.common import STD_BLACKLIST, _handle_blacklist
+from logilab.common.fileutils import norm_open
# Notes about STD_LIB_DIR
# Consider arch-specific installation for STD_LIB_DIR definition
@@ -442,6 +443,8 @@
return source_path
if include_no_ext and not orig_ext and exists(base):
return base
+ if is_python_source(filename):
+ return filename
raise NoSourceFile(filename)
@@ -461,7 +464,12 @@
rtype: bool
return: True if the filename is a python source file
"""
- return splitext(filename)[1][1:] in PY_SOURCE_EXTS
+ if splitext(filename)[1][1:] in PY_SOURCE_EXTS:
+ return True
+ try:
+ return 'python' in norm_open(filename).readline()
+ except IOError:
+ return False
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects