Mercurial > public > mercurial-scm > hg
comparison contrib/import-checker.py @ 51368:cf1bee12ecdb
import-checker: make stdlib path detection work in virtual environments
The previous logic tried to find the directory containing BaseHTTPServer, which
didn?t work as indended because it was only present on Python 2. Instead, the
argparse module is used now.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 02 Feb 2024 04:03:15 +0100 |
parents | 2c34c9b61a4f |
children | 617af10994fb |
comparison
equal
deleted
inserted
replaced
51367:0d414fb8336f | 51368:cf1bee12ecdb |
---|---|
9 | 9 |
10 # Import a minimal set of stdlib modules needed for list_stdlib_modules() | 10 # Import a minimal set of stdlib modules needed for list_stdlib_modules() |
11 # to work when run from a virtualenv. The modules were chosen empirically | 11 # to work when run from a virtualenv. The modules were chosen empirically |
12 # so that the return value matches the return value without virtualenv. | 12 # so that the return value matches the return value without virtualenv. |
13 if True: # disable lexical sorting checks | 13 if True: # disable lexical sorting checks |
14 try: | 14 import argparse |
15 import BaseHTTPServer as basehttpserver | |
16 except ImportError: | |
17 basehttpserver = None | |
18 import zlib | 15 import zlib |
19 | 16 |
20 import testparseutil | 17 import testparseutil |
21 | 18 |
22 # Allow list of modules that symbols can be directly imported from. | 19 # Allow list of modules that symbols can be directly imported from. |
242 for m in ['cffi']: | 239 for m in ['cffi']: |
243 yield m | 240 yield m |
244 stdlib_prefixes = {sys.prefix, sys.exec_prefix} | 241 stdlib_prefixes = {sys.prefix, sys.exec_prefix} |
245 # We need to supplement the list of prefixes for the search to work | 242 # We need to supplement the list of prefixes for the search to work |
246 # when run from within a virtualenv. | 243 # when run from within a virtualenv. |
247 for mod in (basehttpserver, zlib): | 244 for mod in (argparse, zlib): |
248 if mod is None: | 245 if mod is None: |
249 continue | 246 continue |
250 try: | 247 try: |
251 # Not all module objects have a __file__ attribute. | 248 # Not all module objects have a __file__ attribute. |
252 filename = mod.__file__ | 249 filename = mod.__file__ |