Bug 36599 - test-webkitpy: Should remove orphaned *.pyc files in webkitpy/ prior to importing from webkitpy/
Summary: test-webkitpy: Should remove orphaned *.pyc files in webkitpy/ prior to impor...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Chris Jerdonek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-25 07:23 PDT by Chris Jerdonek
Modified: 2010-03-30 09:20 PDT (History)
6 users (show)

See Also:


Attachments
Proposed patch (3.23 KB, patch)
2010-03-26 05:26 PDT, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 2 (3.20 KB, patch)
2010-03-26 05:32 PDT, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch (4.99 KB, patch)
2010-03-26 21:45 PDT, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 4 (5.37 KB, patch)
2010-03-26 21:56 PDT, Chris Jerdonek
eric: review+
commit-queue: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Jerdonek 2010-03-25 07:23:51 PDT
This should increase the robustness of test-webkitpy since it eliminates the possibility of test-webkitpy passing because of *.pyc files left-over from a batch of file moves.
Comment 1 Eric Seidel (no email) 2010-03-25 12:01:13 PDT
Huh?  To test-webkitpy would always cause a full python recompile?  That seems like a bad idea.
Comment 2 Chris Jerdonek 2010-03-25 12:29:23 PDT
(In reply to comment #1)
> Huh?  To test-webkitpy would always cause a full python recompile?  That seems
> like a bad idea.

I noticed no perceptible difference between running test-webkitpy with and without  deleting all *.pyc files before-hand.  It seems like recompiling might be an order of magnitude or two less than running the tests themselves.  (I tried to time the difference, but unittest.main() exits before you can execute a final line.)

Do you have a suggestion for an alternative?  We could always put this behind a --clean option, but I think it would be good for the bots to do whatever we come up with by default.

One alternative might be to delete any .pyc file that doesn't have a corresponding .py, but I don't think that covers all the cases we want to deal with.  Or maybe delete any *.pyc file that doesn't correspond to a source-controlled (tracked) *.py file, but I'm also not sure that covers all the scenarios.  Given that the compile is so fast, it might not be worth the trouble.
Comment 3 Eric Seidel (no email) 2010-03-25 12:39:17 PDT
We can certainly try it.  I wonder how it will interact with things like the commit-queue which are written in python and run test-webkitpy before committing. :)
Comment 4 Chris Jerdonek 2010-03-25 14:16:09 PDT
(In reply to comment #2)
> One alternative might be to delete any .pyc file that doesn't have a
> corresponding .py, but I don't think that covers all the cases we want to deal
> with.

After thinking about this, the above may be the correct alternative.  This should address the main case I had in mind which was moving .py files in source control and leaving behind orphaned .pyc files that were still being referenced by import statements.  (This has occasionally caused problems in practice.)   If there are untracked .py files still being referenced, though, I'm not sure how much we can really do about that (or in practice need to) since in problem scenarios those would get recompiled anyways.

> Or maybe delete any *.pyc file that doesn't correspond to a
> source-controlled (tracked) *.py file, but I'm also not sure that covers all
> the scenarios.


(In reply to comment #3)
> We can certainly try it.  I wonder how it will interact with things like the
> commit-queue which are written in python and run test-webkitpy before
> committing. :)

A related issue to consider is that we may want other scripts (e.g. update-webkit) to trigger a *.pyc "clean" action ("clean" in the sense of the first alternative above).  This way if there are orphaned *.pyc files in someone's webkitpy, the Python scripts will never pick up the wrong ones (e.g. if import finds multiple potential matches in sys.path).
Comment 5 Chris Jerdonek 2010-03-26 05:26:34 PDT
Created attachment 51730 [details]
Proposed patch

This would have come in handy during the re-org. :)
Comment 6 Chris Jerdonek 2010-03-26 05:32:58 PDT
Created attachment 51732 [details]
Proposed patch 2

Reduced the maximum indent level by one.
Comment 7 Eric Seidel (no email) 2010-03-26 09:44:37 PDT
Are we sure this is actually a bug?  Do we know how to reproduce it?  If so, we should file a bug with python before working around it here.
Comment 8 Chris Jerdonek 2010-03-26 10:08:27 PDT
(In reply to comment #7)
> Are we sure this is actually a bug?  Do we know how to reproduce it?

Yes, we can reproduce it.  Just "svn move" any python module (without touching any of the code), and then run test-webkitpy.  It still succeeds.  With this patch, it correctly fails with an error:

ImportError: No module named ...

> If so, we
> should file a bug with python before working around it here.

It's a Python feature, not a bug. :)

"It is possible to have a file called spam.pyc (or spam.pyo when -O is used) without a file spam.py for the same module. This can be used to distribute a library of Python code in a form that is moderately hard to reverse engineer."

(from http://docs.python.org/tutorial/modules.html#compiled-python-files )
Comment 9 Chris Jerdonek 2010-03-26 10:24:58 PDT
(In reply to comment #7)
> Are we sure this is actually a bug?  Do we know how to reproduce it?  If so, we
> should file a bug with python before working around it here.

The problem is also stated here, for instance:

http://bugs.python.org/issue1180193#msg24989
Comment 10 Eric Seidel (no email) 2010-03-26 10:44:13 PDT
Comment on attachment 51732 [details]
Proposed patch 2

OK.  I think it needs a unit test though.
Comment 11 Chris Jerdonek 2010-03-26 11:04:05 PDT
So (In reply to comment #10)
> (From update of attachment 51732 [details])
> OK.  I think it needs a unit test though.

This seems a bit excessive to me since we'd be unit testing unit-test code.  We don't normally do that, but I could do it.

In this case, since the method needs to be defined in test-webkitpy, the unit test would either need to go in test-webkitpy itself, or we would need a module somewhere in webkitpy (say webkitpy/test/main_unittest.py) that would need to import this method from test-webkitpy.  (In particular, the method would be getting unit-tested after it has already executed.)

Clarify for me by r-'ing the patch if this is required.  Thanks.
Comment 12 Chris Jerdonek 2010-03-26 13:10:57 PDT
(In reply to comment #11)
> In this case, since the method needs to be defined in test-webkitpy, the unit
> test would either need to go in test-webkitpy itself, or we would need a module
> somewhere in webkitpy (say webkitpy/test/main_unittest.py) that would need to
> import this method from test-webkitpy.

Maybe the simplest approach to test that this method is doing what it's supposed to do would be to insert a mock .pyc file somewhere in webkitpy before the method call and then raise an error afterwards if that particular file hasn't been deleted.  I.e. the call and the test would be one and the same.
Comment 13 Eric Seidel (no email) 2010-03-26 13:21:01 PDT
The problem is that this code is "complicated" and difficult to tell when it's broken.  Which is why I suggested testing.  I agree, it seems kinda silly to test the test code.   Your solution of dropping a some sort of testing .pyc file makes sense.
Comment 14 Chris Jerdonek 2010-03-26 21:45:52 PDT
Created attachment 51812 [details]
Proposed patch
Comment 15 Chris Jerdonek 2010-03-26 21:56:40 PDT
Created attachment 51814 [details]
Proposed patch 4

Added link to Python documentation.
Comment 16 Eric Seidel (no email) 2010-03-29 19:56:37 PDT
Comment on attachment 51814 [details]
Proposed patch 4

Looks sane.
Comment 17 WebKit Commit Bot 2010-03-29 20:08:23 PDT
Comment on attachment 51814 [details]
Proposed patch 4

Rejecting patch 51814 from commit-queue.

Failed to run "['/Users/eseidel/Projects/CommitQueue/WebKitTools/Scripts/svn-apply', '--reviewer', 'Eric Seidel', '--force']" exit_code: 1
patching file WebKitTools/ChangeLog
Hunk #1 succeeded at 1 with fuzz 3.
patching file WebKitTools/Scripts/test-webkitpy
Hunk #1 FAILED at 29.
Hunk #2 succeeded at 79 (offset 1 line).
1 out of 2 hunks FAILED -- saving rejects to file WebKitTools/Scripts/test-webkitpy.rej

Full output: http://webkit-commit-queue.appspot.com/results/1605082
Comment 18 Chris Jerdonek 2010-03-30 09:20:15 PDT
Manually committed after rebasing:

http://trac.webkit.org/changeset/56794