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
=== modified file 'lib/lp_sitecustomize.py'
--- lib/lp_sitecustomize.py 2010-04-22 23:02:07 +0000
+++ lib/lp_sitecustomize.py 2010-06-09 21:06:30 +0000
@@ -5,15 +5,28 @@
5# buildout.cfg (see the "initialization" key in the "[scripts]" section).5# buildout.cfg (see the "initialization" key in the "[scripts]" section).
66
7import os7import os
8import warnings
9
10from bzrlib.branch import Branch
8from lp.services.mime import customizeMimetypes11from lp.services.mime import customizeMimetypes
9from zope.security import checker12from zope.security import checker
10from bzrlib.branch import Branch13
1114
12def dont_wrap_class_and_subclasses(cls):15def dont_wrap_class_and_subclasses(cls):
13 checker.BasicTypes.update({cls: checker.NoProxy})16 checker.BasicTypes.update({cls: checker.NoProxy})
14 for subcls in cls.__subclasses__():17 for subcls in cls.__subclasses__():
15 dont_wrap_class_and_subclasses(subcls)18 dont_wrap_class_and_subclasses(subcls)
1619
20def silence_warnings():
21 """Silence warnings across the entire Launchpad project."""
22 # pycrypto-2.0.1 on Python2.6:
23 # DeprecationWarning: the sha module is deprecated; use the hashlib
24 # module instead
25 warnings.filterwarnings(
26 "ignore",
27 category=DeprecationWarning,
28 module="Crypto")
29
17def main():30def main():
18 # Note that we configure the LPCONFIG environmental variable in the31 # Note that we configure the LPCONFIG environmental variable in the
19 # custom buildout-generated sitecustomize.py in32 # custom buildout-generated sitecustomize.py in
@@ -26,5 +39,6 @@
26 os.environ['STORM_CEXTENSIONS'] = '1'39 os.environ['STORM_CEXTENSIONS'] = '1'
27 customizeMimetypes()40 customizeMimetypes()
28 dont_wrap_class_and_subclasses(Branch)41 dont_wrap_class_and_subclasses(Branch)
42 silence_warnings()
2943
30main()44main()