From patchwork Fri Aug 15 14:21:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 7] cleanup: make sure we always access members of imported modules From: Mads Kiilerich X-Patchwork-Id: 5423 Message-Id: <53b0e3a724f24a085883.1408112477@mk-desktop> To: mercurial-devel@selenic.com Date: Fri, 15 Aug 2014 16:21:17 +0200 # HG changeset patch # User Mads Kiilerich # Date 1408070265 -7200 # Fri Aug 15 04:37:45 2014 +0200 # Node ID 53b0e3a724f24a0858837e1b4cb1742615a36836 # Parent 2965804483e31210b495f5b3cd498a4e3d3272b0 cleanup: make sure we always access members of imported modules This will make sure we get import errors, even if demandimport is enabled. This will also mute some pyflakes 'imported but unused' warnings. diff --git a/contrib/win32/hgwebdir_wsgi.py b/contrib/win32/hgwebdir_wsgi.py --- a/contrib/win32/hgwebdir_wsgi.py +++ b/contrib/win32/hgwebdir_wsgi.py @@ -52,6 +52,7 @@ import sys # Enable tracing. Run 'python -m win32traceutil' to debug if getattr(sys, 'isapidllhandle', None) is not None: import win32traceutil + win32traceutil.SetupForPrint # To serve pages in local charset instead of UTF-8, remove the two lines below import os @@ -90,6 +91,6 @@ def __ExtensionFactory__(): return isapi_wsgi.ISAPISimpleHandler(handler) if __name__=='__main__': - from isapi.install import * + from isapi.install import ISAPIParameters, HandleCommandLine params = ISAPIParameters() HandleCommandLine(params) diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -33,12 +33,14 @@ try: except ImportError: try: import sha + sha.sha except ImportError: raise SystemExit( "Couldn't import standard hashlib (incomplete Python install).") try: import zlib + zlib.compressobj except ImportError: raise SystemExit( "Couldn't import standard zlib (incomplete Python install).") @@ -56,6 +58,7 @@ if isironpython: else: try: import bz2 + bz2.BZ2Compressor except ImportError: raise SystemExit( "Couldn't import standard bz2 (incomplete Python install).") @@ -129,6 +132,7 @@ def hasfunction(cc, funcname): # py2exe needs to be installed to work try: import py2exe + py2exe.Distribution py2exeloaded = True # import py2exe's patched Distribution class from distutils.core import Distribution diff --git a/tests/hghave.py b/tests/hghave.py --- a/tests/hghave.py +++ b/tests/hghave.py @@ -148,6 +148,7 @@ def has_cacheable_fs(): def has_lsprof(): try: import _lsprof + _lsprof.Profiler return True except ImportError: return False @@ -163,7 +164,8 @@ def has_git(): @check("docutils", "Docutils text processing library") def has_docutils(): try: - from docutils.core import publish_cmdline + import docutils.core + docutils.core.publish_cmdline return True except ImportError: return False @@ -270,6 +272,7 @@ def has_pyflakes(): def has_pygments(): try: import pygments + pygments.highlight return True except ImportError: return False @@ -288,6 +291,7 @@ def has_outer_repo(): def has_ssl(): try: import ssl + ssl.wrap_socket import OpenSSL OpenSSL.SSL.Context return True diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t --- a/tests/test-check-pyflakes.t +++ b/tests/test-check-pyflakes.t @@ -7,16 +7,6 @@ run pyflakes on all tracked files ending $ hg locate 'set:**.py or grep("^!#.*python")' 2>/dev/null \ > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" - contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob) - setup.py:*: 'sha' imported but unused (glob) - setup.py:*: 'zlib' imported but unused (glob) - setup.py:*: 'bz2' imported but unused (glob) - setup.py:*: 'py2exe' imported but unused (glob) - tests/hghave.py:*: '_lsprof' imported but unused (glob) - tests/hghave.py:*: 'publish_cmdline' imported but unused (glob) - tests/hghave.py:*: 'pygments' imported but unused (glob) - tests/hghave.py:*: 'ssl' imported but unused (glob) - contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob) tests/filterpyflakes.py:58: undefined name 'undefinedname'