[cheesecake-users] pylint curiousness

will guaraldi willg at bluesock.org
Tue Jul 11 09:43:13 PDT 2006

On Mon, 10 Jul 2006, Grig Gheorghiu wrote:
> Will,
> Thanks for reporting this issue. It does seem like the sane approach for 
> cheesecake should be to run pylint on the package as a whole, as opposed 
> to the current way of running it on individual files. We have a 
> pylint-related story coming up soon, so we'll add this task to the 
> story.

The problem of running it on the entire package at the same time is that 
you don't get the level of granularity you might want (I'm 
hypotheticalizing that's what you want).

I did some more poking around (i.e. I read the documentation which I 
should have done before) and what pylint does is add the current directory 
to the head of sys.path before checking the module.  So if the module is 
deep into a package, then you should run pylint from the top of the 
package.  For my specific example, running:

    pylint PyBlosxom/cache/entryshelve.py

works fine.  But running:

    pylint entryshelve.py

in the Pyblosxom/cache directory doesn't work at all.

I did an svn update, made some changes, and produced the attached diff 
which fixes the pylint problem I had without resorting to switching to 
pylinting the package all at once.

-------------- next part --------------
Index: cheesecake_index.py
--- cheesecake_index.py	(revision 83)
+++ cheesecake_index.py	(working copy)
@@ -842,8 +842,17 @@
         pylint_value = 0
         cnt = 0
+        # wbg: switching cwd so that pylint works correctly regarding
+        # running it on individual modules
+        original_cwd = os.getcwd()
+        os.chdir(package_dir)
         for pyfile in get_files_of_type(files_list, 'module'):
-            fullpath = os.path.join(package_dir, pyfile)
+            # wbg: because we change the working dir, we can use relative
+            # paths which pylint is happier about.
+            # fullpath = os.path.join(package_dir, pyfile)
+            fullpath = pyfile
             path, filename = os.path.split(fullpath)
             module, ext = os.path.splitext(filename)
@@ -855,6 +864,7 @@
             score_line = output.split("\n")[-3]
             s = re.search(r" (\d+\.\d+)/10", score_line)
             # We only take positive scores into account
             if s:
                 score = s.group(1)
@@ -866,6 +876,9 @@
                 pylint_value += float(score)
                 cnt += 1
+        # wbg: switching back to the original cwd in case that's important
+        os.chdir(original_cwd)
         avg_score = 0
         if cnt:
             avg_score = float(pylint_value)/float(cnt)

More information about the cheesecake-users mailing list