Merge lp://staging/~gary/launchpad/fix-warnings into lp://staging/~launchpad-committers/launchpad/ztk-2.5

Proposed by Gary Poster
Status: Merged
Approved by: Guilherme Salgado
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp://staging/~gary/launchpad/fix-warnings
Merge into: lp://staging/~launchpad-committers/launchpad/ztk-2.5
Diff against target: 24 lines
1 file modified
lib/site.py (+12/-2)
To merge this branch: bzr merge lp://staging/~gary/launchpad/fix-warnings
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) Approve
Review via email: mp+13713@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

We were encountering a lot of warnings about the fact that Python could not import site-package namespace packages. They were apparently caused by importing pkg_resources in our site.py hack. I have silenced them, using Python's usual warnings mechanism.

Thank you

Gary

Revision history for this message
Guilherme Salgado (salgado) wrote :

Looks good to me, although I don't quite understand how the hacked
site.py works.

 status approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/site.py'
2--- lib/site.py 2009-10-16 15:53:10 +0000
3+++ lib/site.py 2009-10-21 15:30:25 +0000
4@@ -6,8 +6,18 @@
5 # packages will mask all of the egg-based packages in the same namespace
6 # package. Normally, we handle that in bin/py or _pythonpath. but sometimes
7 # we do subprocess calls, relying on the PYTHONPATH to set the eggs
8-# correctly. It is for this situation that we have hacked site.py. Here
9-# is the important part:
10+# correctly. It is for this situation that we have hacked site.py.
11+
12+# Before we actually import pkg_resources, we need to filter warnings,
13+# because importing pkg_resources will otherwise trigger a type of
14+# warnings that we don't care about. These warnings occur when Python
15+# 2.5 and higher encounters directories that do not have an __init__.py.
16+# These can be data directories, or namespace directories in
17+# site-packages, such as "zope" or "lazr."
18+__import__('warnings').filterwarnings(
19+ 'ignore', "Not importing directory '.+': missing __init__.py")
20+
21+# Now here is the important part:
22 try:
23 __import__('pkg_resources') # Use __import__ to not pollute the namespace.
24 except ImportError:

Subscribers

People subscribed via source and target branches

to all changes: