Merge lp:~mars/launchpad/silence-pycrypto-warnings into lp:launchpad

Proposed by Māris Fogels
Status: Merged
Approved by: Māris Fogels
Approved revision: no longer in the source branch.
Merged at revision: 10990
Proposed branch: lp:~mars/launchpad/silence-pycrypto-warnings
Merge into: lp:launchpad
Diff against target: 40 lines (+15/-1)
1 file modified
lib/lp_sitecustomize.py (+15/-1)
To merge this branch: bzr merge lp:~mars/launchpad/silence-pycrypto-warnings
Reviewer Review Type Date Requested Status
Michael Nelson (community) code Approve
Review via email: mp+27203@code.launchpad.net

Commit message

Silence a pair of DeprecationWarnings from pycrypto when running under Python2.6.

Description of the change

Hi,

This branch silences a pair of annoying warnings in pycrypto 2.0.1 under Python2.6.

I added a new site-wide warnings hook to lp_sitecustomize.py to do this.

I will run this through ec2 test before landing the change, as it touches the site-wide configuration.

Test: bin/ec2
Pre-implementation call with: gary_poster
Lint: None

Maris

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

Hi Maris,

did you or Gary talk about the option following the deprecation warning and using hashlib instead of sha throughout lp? There's an example of a conditional import in:

lib/mailman/Mailman/Utils.py

Or temporarily suppressing the warning where it is currently used, so we don't introduce more?
http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings

Also, I'm not sure how the module regex is meant to work there... at least, it doesn't work in a console:
{{{
In [1]: import warnings

In [2]: warnings.filterwarnings("ignore", category=DeprecationWarning, module="crypto")

In [3]: import sha
/usr/bin/ipython:1: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  #!/usr/bin/python

In [4]:
}}}

but this does:

{{{
In [1]: import warnings

In [2]: warnings.filterwarnings("ignore", category=DeprecationWarning, message="the sha module is deprecated")

In [3]: import sha

In [4]:
}}}

Thanks!

review: Needs Information (code)
Revision history for this message
Michael Nelson (michael.nelson) wrote :

> Also, I'm not sure how the module regex is meant to work there... at least, it
> doesn't work in a console:
> {{{
> In [1]: import warnings
>
> In [2]: warnings.filterwarnings("ignore", category=DeprecationWarning,
> module="crypto")

That should have been Crypto, and right, after sending one of my own branches off with bin/ec2 just now, I understand the module regex :) Never mind me.

...
>
> Thanks!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp_sitecustomize.py'
2--- lib/lp_sitecustomize.py 2010-04-22 23:02:07 +0000
3+++ lib/lp_sitecustomize.py 2010-06-09 21:06:30 +0000
4@@ -5,15 +5,28 @@
5 # buildout.cfg (see the "initialization" key in the "[scripts]" section).
6
7 import os
8+import warnings
9+
10+from bzrlib.branch import Branch
11 from lp.services.mime import customizeMimetypes
12 from zope.security import checker
13-from bzrlib.branch import Branch
14+
15
16 def dont_wrap_class_and_subclasses(cls):
17 checker.BasicTypes.update({cls: checker.NoProxy})
18 for subcls in cls.__subclasses__():
19 dont_wrap_class_and_subclasses(subcls)
20
21+def silence_warnings():
22+ """Silence warnings across the entire Launchpad project."""
23+ # pycrypto-2.0.1 on Python2.6:
24+ # DeprecationWarning: the sha module is deprecated; use the hashlib
25+ # module instead
26+ warnings.filterwarnings(
27+ "ignore",
28+ category=DeprecationWarning,
29+ module="Crypto")
30+
31 def main():
32 # Note that we configure the LPCONFIG environmental variable in the
33 # custom buildout-generated sitecustomize.py in
34@@ -26,5 +39,6 @@
35 os.environ['STORM_CEXTENSIONS'] = '1'
36 customizeMimetypes()
37 dont_wrap_class_and_subclasses(Branch)
38+ silence_warnings()
39
40 main()