sysconfig.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. """Provide access to Python's configuration information.
  2. """
  3. import sys
  4. import os
  5. from os.path import pardir, realpath
  6. _INSTALL_SCHEMES = {
  7. 'posix_prefix': {
  8. 'stdlib': '{base}/'+sys.lib+'/python{py_version_short}',
  9. 'platstdlib': '{platbase}/'+sys.lib+'/python{py_version_short}',
  10. 'purelib': '{base}/'+sys.lib+'/python{py_version_short}/site-packages',
  11. 'platlib': '{platbase}/'+sys.lib+'/python{py_version_short}/site-packages',
  12. 'include': '{base}/include/python{py_version_short}',
  13. 'platinclude': '{platbase}/include/python{py_version_short}',
  14. 'scripts': '{base}/bin',
  15. 'data': '{base}',
  16. },
  17. 'posix_home': {
  18. 'stdlib': '{base}/lib/python',
  19. 'platstdlib': '{base}/lib/python',
  20. 'purelib': '{base}/lib/python',
  21. 'platlib': '{base}/lib/python',
  22. 'include': '{base}/include/python',
  23. 'platinclude': '{base}/include/python',
  24. 'scripts': '{base}/bin',
  25. 'data' : '{base}',
  26. },
  27. 'nt': {
  28. 'stdlib': '{base}/Lib',
  29. 'platstdlib': '{base}/Lib',
  30. 'purelib': '{base}/Lib/site-packages',
  31. 'platlib': '{base}/Lib/site-packages',
  32. 'include': '{base}/Include',
  33. 'platinclude': '{base}/Include',
  34. 'scripts': '{base}/Scripts',
  35. 'data' : '{base}',
  36. },
  37. 'os2': {
  38. 'stdlib': '{base}/Lib',
  39. 'platstdlib': '{base}/Lib',
  40. 'purelib': '{base}/Lib/site-packages',
  41. 'platlib': '{base}/Lib/site-packages',
  42. 'include': '{base}/Include',
  43. 'platinclude': '{base}/Include',
  44. 'scripts': '{base}/Scripts',
  45. 'data' : '{base}',
  46. },
  47. 'os2_home': {
  48. 'stdlib': '{userbase}/lib/python{py_version_short}',
  49. 'platstdlib': '{userbase}/lib/python{py_version_short}',
  50. 'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
  51. 'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
  52. 'include': '{userbase}/include/python{py_version_short}',
  53. 'scripts': '{userbase}/bin',
  54. 'data' : '{userbase}',
  55. },
  56. 'nt_user': {
  57. 'stdlib': '{userbase}/Python{py_version_nodot}',
  58. 'platstdlib': '{userbase}/Python{py_version_nodot}',
  59. 'purelib': '{userbase}/Python{py_version_nodot}/site-packages',
  60. 'platlib': '{userbase}/Python{py_version_nodot}/site-packages',
  61. 'include': '{userbase}/Python{py_version_nodot}/Include',
  62. 'scripts': '{userbase}/Scripts',
  63. 'data' : '{userbase}',
  64. },
  65. 'posix_user': {
  66. 'stdlib': '{userbase}/'+sys.lib+'/python{py_version_short}',
  67. 'platstdlib': '{userbase}/'+sys.lib+'/python{py_version_short}',
  68. 'purelib': '{userbase}/'+sys.lib+'/python{py_version_short}/site-packages',
  69. 'platlib': '{userbase}/'+sys.lib+'/python{py_version_short}/site-packages',
  70. 'include': '{userbase}/include/python{py_version_short}',
  71. 'scripts': '{userbase}/bin',
  72. 'data' : '{userbase}',
  73. },
  74. 'osx_framework_user': {
  75. 'stdlib': '{userbase}/lib/python',
  76. 'platstdlib': '{userbase}/lib/python',
  77. 'purelib': '{userbase}/lib/python/site-packages',
  78. 'platlib': '{userbase}/lib/python/site-packages',
  79. 'include': '{userbase}/include',
  80. 'scripts': '{userbase}/bin',
  81. 'data' : '{userbase}',
  82. },
  83. }
  84. _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
  85. 'scripts', 'data')
  86. _PY_VERSION = sys.version.split()[0]
  87. _PY_VERSION_SHORT = sys.version[:3]
  88. _PY_VERSION_SHORT_NO_DOT = _PY_VERSION[0] + _PY_VERSION[2]
  89. _PREFIX = os.path.normpath(sys.prefix)
  90. _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  91. _CONFIG_VARS = None
  92. _USER_BASE = None
  93. def _safe_realpath(path):
  94. try:
  95. return realpath(path)
  96. except OSError:
  97. return path
  98. if sys.executable:
  99. _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
  100. else:
  101. # sys.executable can be empty if argv[0] has been changed and Python is
  102. # unable to retrieve the real program name
  103. _PROJECT_BASE = _safe_realpath(os.getcwd())
  104. if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
  105. _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir))
  106. # PC/VS7.1
  107. if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
  108. _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
  109. # PC/AMD64
  110. if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
  111. _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
  112. # set for cross builds
  113. if "_PYTHON_PROJECT_BASE" in os.environ:
  114. # the build directory for posix builds
  115. _PROJECT_BASE = os.path.normpath(os.path.abspath("."))
  116. def is_python_build():
  117. for fn in ("Setup.dist", "Setup.local"):
  118. if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
  119. return True
  120. return False
  121. _PYTHON_BUILD = is_python_build()
  122. if _PYTHON_BUILD:
  123. for scheme in ('posix_prefix', 'posix_home'):
  124. _INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/Include'
  125. _INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}'
  126. def _subst_vars(s, local_vars):
  127. try:
  128. return s.format(**local_vars)
  129. except KeyError:
  130. try:
  131. return s.format(**os.environ)
  132. except KeyError, var:
  133. raise AttributeError('{%s}' % var)
  134. def _extend_dict(target_dict, other_dict):
  135. target_keys = target_dict.keys()
  136. for key, value in other_dict.items():
  137. if key in target_keys:
  138. continue
  139. target_dict[key] = value
  140. def _expand_vars(scheme, vars):
  141. res = {}
  142. if vars is None:
  143. vars = {}
  144. _extend_dict(vars, get_config_vars())
  145. for key, value in _INSTALL_SCHEMES[scheme].items():
  146. if os.name in ('posix', 'nt'):
  147. value = os.path.expanduser(value)
  148. res[key] = os.path.normpath(_subst_vars(value, vars))
  149. return res
  150. def _get_default_scheme():
  151. if os.name == 'posix':
  152. # the default scheme for posix is posix_prefix
  153. return 'posix_prefix'
  154. return os.name
  155. def _getuserbase():
  156. env_base = os.environ.get("PYTHONUSERBASE", None)
  157. def joinuser(*args):
  158. return os.path.expanduser(os.path.join(*args))
  159. # what about 'os2emx', 'riscos' ?
  160. if os.name == "nt":
  161. base = os.environ.get("APPDATA") or "~"
  162. return env_base if env_base else joinuser(base, "Python")
  163. if sys.platform == "darwin":
  164. framework = get_config_var("PYTHONFRAMEWORK")
  165. if framework:
  166. return env_base if env_base else \
  167. joinuser("~", "Library", framework, "%d.%d"
  168. % (sys.version_info[:2]))
  169. return env_base if env_base else joinuser("~", ".local")
  170. def _parse_makefile(filename, vars=None):
  171. """Parse a Makefile-style file.
  172. A dictionary containing name/value pairs is returned. If an
  173. optional dictionary is passed in as the second argument, it is
  174. used instead of a new dictionary.
  175. """
  176. import re
  177. # Regexes needed for parsing Makefile (and similar syntaxes,
  178. # like old-style Setup files).
  179. _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
  180. _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
  181. _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
  182. if vars is None:
  183. vars = {}
  184. done = {}
  185. notdone = {}
  186. with open(filename) as f:
  187. lines = f.readlines()
  188. for line in lines:
  189. if line.startswith('#') or line.strip() == '':
  190. continue
  191. m = _variable_rx.match(line)
  192. if m:
  193. n, v = m.group(1, 2)
  194. v = v.strip()
  195. # `$$' is a literal `$' in make
  196. tmpv = v.replace('$$', '')
  197. if "$" in tmpv:
  198. notdone[n] = v
  199. else:
  200. try:
  201. v = int(v)
  202. except ValueError:
  203. # insert literal `$'
  204. done[n] = v.replace('$$', '$')
  205. else:
  206. done[n] = v
  207. # do variable interpolation here
  208. while notdone:
  209. for name in notdone.keys():
  210. value = notdone[name]
  211. m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
  212. if m:
  213. n = m.group(1)
  214. found = True
  215. if n in done:
  216. item = str(done[n])
  217. elif n in notdone:
  218. # get it on a subsequent round
  219. found = False
  220. elif n in os.environ:
  221. # do it like make: fall back to environment
  222. item = os.environ[n]
  223. else:
  224. done[n] = item = ""
  225. if found:
  226. after = value[m.end():]
  227. value = value[:m.start()] + item + after
  228. if "$" in after:
  229. notdone[name] = value
  230. else:
  231. try: value = int(value)
  232. except ValueError:
  233. done[name] = value.strip()
  234. else:
  235. done[name] = value
  236. del notdone[name]
  237. else:
  238. # bogus variable reference; just drop it since we can't deal
  239. del notdone[name]
  240. # strip spurious spaces
  241. for k, v in done.items():
  242. if isinstance(v, str):
  243. done[k] = v.strip()
  244. # save the results in the global dictionary
  245. vars.update(done)
  246. return vars
  247. def get_makefile_filename():
  248. """Return the path of the Makefile."""
  249. if _PYTHON_BUILD:
  250. return os.path.join(_PROJECT_BASE, "Makefile")
  251. return os.path.join(get_path('platstdlib'), "config", "Makefile")
  252. # Issue #22199: retain undocumented private name for compatibility
  253. _get_makefile_filename = get_makefile_filename
  254. def _generate_posix_vars():
  255. """Generate the Python module containing build-time variables."""
  256. import pprint
  257. vars = {}
  258. # load the installed Makefile:
  259. makefile = get_makefile_filename()
  260. try:
  261. _parse_makefile(makefile, vars)
  262. except IOError, e:
  263. msg = "invalid Python installation: unable to open %s" % makefile
  264. if hasattr(e, "strerror"):
  265. msg = msg + " (%s)" % e.strerror
  266. raise IOError(msg)
  267. # load the installed pyconfig.h:
  268. config_h = get_config_h_filename()
  269. try:
  270. with open(config_h) as f:
  271. parse_config_h(f, vars)
  272. except IOError, e:
  273. msg = "invalid Python installation: unable to open %s" % config_h
  274. if hasattr(e, "strerror"):
  275. msg = msg + " (%s)" % e.strerror
  276. raise IOError(msg)
  277. # On AIX, there are wrong paths to the linker scripts in the Makefile
  278. # -- these paths are relative to the Python source, but when installed
  279. # the scripts are in another directory.
  280. if _PYTHON_BUILD:
  281. vars['LDSHARED'] = vars['BLDSHARED']
  282. # There's a chicken-and-egg situation on OS X with regards to the
  283. # _sysconfigdata module after the changes introduced by #15298:
  284. # get_config_vars() is called by get_platform() as part of the
  285. # `make pybuilddir.txt` target -- which is a precursor to the
  286. # _sysconfigdata.py module being constructed. Unfortunately,
  287. # get_config_vars() eventually calls _init_posix(), which attempts
  288. # to import _sysconfigdata, which we won't have built yet. In order
  289. # for _init_posix() to work, if we're on Darwin, just mock up the
  290. # _sysconfigdata module manually and populate it with the build vars.
  291. # This is more than sufficient for ensuring the subsequent call to
  292. # get_platform() succeeds.
  293. name = '_sysconfigdata'
  294. if 'darwin' in sys.platform:
  295. import imp
  296. module = imp.new_module(name)
  297. module.build_time_vars = vars
  298. sys.modules[name] = module
  299. pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
  300. if hasattr(sys, "gettotalrefcount"):
  301. pybuilddir += '-pydebug'
  302. try:
  303. os.makedirs(pybuilddir)
  304. except OSError:
  305. pass
  306. destfile = os.path.join(pybuilddir, name + '.py')
  307. with open(destfile, 'wb') as f:
  308. f.write('# system configuration generated and used by'
  309. ' the sysconfig module\n')
  310. f.write('build_time_vars = ')
  311. pprint.pprint(vars, stream=f)
  312. # Create file used for sys.path fixup -- see Modules/getpath.c
  313. with open('pybuilddir.txt', 'w') as f:
  314. f.write(pybuilddir)
  315. def _init_posix(vars):
  316. """Initialize the module as appropriate for POSIX systems."""
  317. # _sysconfigdata is generated at build time, see _generate_posix_vars()
  318. from _sysconfigdata import build_time_vars
  319. vars.update(build_time_vars)
  320. def _init_non_posix(vars):
  321. """Initialize the module as appropriate for NT"""
  322. # set basic install directories
  323. vars['LIBDEST'] = get_path('stdlib')
  324. vars['BINLIBDEST'] = get_path('platstdlib')
  325. vars['INCLUDEPY'] = get_path('include')
  326. vars['SO'] = '.pyd'
  327. vars['EXE'] = '.exe'
  328. vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
  329. vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
  330. #
  331. # public APIs
  332. #
  333. def parse_config_h(fp, vars=None):
  334. """Parse a config.h-style file.
  335. A dictionary containing name/value pairs is returned. If an
  336. optional dictionary is passed in as the second argument, it is
  337. used instead of a new dictionary.
  338. """
  339. import re
  340. if vars is None:
  341. vars = {}
  342. define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
  343. undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
  344. while True:
  345. line = fp.readline()
  346. if not line:
  347. break
  348. m = define_rx.match(line)
  349. if m:
  350. n, v = m.group(1, 2)
  351. try: v = int(v)
  352. except ValueError: pass
  353. vars[n] = v
  354. else:
  355. m = undef_rx.match(line)
  356. if m:
  357. vars[m.group(1)] = 0
  358. return vars
  359. def get_config_h_filename():
  360. """Returns the path of pyconfig.h."""
  361. if _PYTHON_BUILD:
  362. if os.name == "nt":
  363. inc_dir = os.path.join(_PROJECT_BASE, "PC")
  364. else:
  365. inc_dir = _PROJECT_BASE
  366. else:
  367. inc_dir = get_path('platinclude')
  368. return os.path.join(inc_dir, 'pyconfig.h')
  369. def get_scheme_names():
  370. """Returns a tuple containing the schemes names."""
  371. schemes = _INSTALL_SCHEMES.keys()
  372. schemes.sort()
  373. return tuple(schemes)
  374. def get_path_names():
  375. """Returns a tuple containing the paths names."""
  376. return _SCHEME_KEYS
  377. def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
  378. """Returns a mapping containing an install scheme.
  379. ``scheme`` is the install scheme name. If not provided, it will
  380. return the default scheme for the current platform.
  381. """
  382. if expand:
  383. return _expand_vars(scheme, vars)
  384. else:
  385. return _INSTALL_SCHEMES[scheme]
  386. def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):
  387. """Returns a path corresponding to the scheme.
  388. ``scheme`` is the install scheme name.
  389. """
  390. return get_paths(scheme, vars, expand)[name]
  391. def get_config_vars(*args):
  392. """With no arguments, return a dictionary of all configuration
  393. variables relevant for the current platform.
  394. On Unix, this means every variable defined in Python's installed Makefile;
  395. On Windows and Mac OS it's a much smaller set.
  396. With arguments, return a list of values that result from looking up
  397. each argument in the configuration variable dictionary.
  398. """
  399. import re
  400. global _CONFIG_VARS
  401. if _CONFIG_VARS is None:
  402. _CONFIG_VARS = {}
  403. # Normalized versions of prefix and exec_prefix are handy to have;
  404. # in fact, these are the standard versions used most places in the
  405. # Distutils.
  406. _CONFIG_VARS['prefix'] = _PREFIX
  407. _CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
  408. _CONFIG_VARS['py_version'] = _PY_VERSION
  409. _CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
  410. _CONFIG_VARS['py_version_nodot'] = _PY_VERSION[0] + _PY_VERSION[2]
  411. _CONFIG_VARS['base'] = _PREFIX
  412. _CONFIG_VARS['platbase'] = _EXEC_PREFIX
  413. _CONFIG_VARS['projectbase'] = _PROJECT_BASE
  414. if os.name in ('nt', 'os2'):
  415. _init_non_posix(_CONFIG_VARS)
  416. if os.name == 'posix':
  417. _init_posix(_CONFIG_VARS)
  418. # Setting 'userbase' is done below the call to the
  419. # init function to enable using 'get_config_var' in
  420. # the init-function.
  421. _CONFIG_VARS['userbase'] = _getuserbase()
  422. if 'srcdir' not in _CONFIG_VARS:
  423. _CONFIG_VARS['srcdir'] = _PROJECT_BASE
  424. # Convert srcdir into an absolute path if it appears necessary.
  425. # Normally it is relative to the build directory. However, during
  426. # testing, for example, we might be running a non-installed python
  427. # from a different directory.
  428. if _PYTHON_BUILD and os.name == "posix":
  429. base = _PROJECT_BASE
  430. try:
  431. cwd = os.getcwd()
  432. except OSError:
  433. cwd = None
  434. if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
  435. base != cwd):
  436. # srcdir is relative and we are not in the same directory
  437. # as the executable. Assume executable is in the build
  438. # directory and make srcdir absolute.
  439. srcdir = os.path.join(base, _CONFIG_VARS['srcdir'])
  440. _CONFIG_VARS['srcdir'] = os.path.normpath(srcdir)
  441. # OS X platforms require special customization to handle
  442. # multi-architecture, multi-os-version installers
  443. if sys.platform == 'darwin':
  444. import _osx_support
  445. _osx_support.customize_config_vars(_CONFIG_VARS)
  446. if args:
  447. vals = []
  448. for name in args:
  449. vals.append(_CONFIG_VARS.get(name))
  450. return vals
  451. else:
  452. return _CONFIG_VARS
  453. def get_config_var(name):
  454. """Return the value of a single variable using the dictionary returned by
  455. 'get_config_vars()'.
  456. Equivalent to get_config_vars().get(name)
  457. """
  458. return get_config_vars().get(name)
  459. def get_platform():
  460. """Return a string that identifies the current platform.
  461. This is used mainly to distinguish platform-specific build directories and
  462. platform-specific built distributions. Typically includes the OS name
  463. and version and the architecture (as supplied by 'os.uname()'),
  464. although the exact information included depends on the OS; eg. for IRIX
  465. the architecture isn't particularly important (IRIX only runs on SGI
  466. hardware), but for Linux the kernel version isn't particularly
  467. important.
  468. Examples of returned values:
  469. linux-i586
  470. linux-alpha (?)
  471. solaris-2.6-sun4u
  472. irix-5.3
  473. irix64-6.2
  474. Windows will return one of:
  475. win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
  476. win-ia64 (64bit Windows on Itanium)
  477. win32 (all others - specifically, sys.platform is returned)
  478. For other non-POSIX platforms, currently just returns 'sys.platform'.
  479. """
  480. import re
  481. if os.name == 'nt':
  482. # sniff sys.version for architecture.
  483. prefix = " bit ("
  484. i = sys.version.find(prefix)
  485. if i == -1:
  486. return sys.platform
  487. j = sys.version.find(")", i)
  488. look = sys.version[i+len(prefix):j].lower()
  489. if look == 'amd64':
  490. return 'win-amd64'
  491. if look == 'itanium':
  492. return 'win-ia64'
  493. return sys.platform
  494. # Set for cross builds explicitly
  495. if "_PYTHON_HOST_PLATFORM" in os.environ:
  496. return os.environ["_PYTHON_HOST_PLATFORM"]
  497. if os.name != "posix" or not hasattr(os, 'uname'):
  498. # XXX what about the architecture? NT is Intel or Alpha,
  499. # Mac OS is M68k or PPC, etc.
  500. return sys.platform
  501. # Try to distinguish various flavours of Unix
  502. osname, host, release, version, machine = os.uname()
  503. # Convert the OS name to lowercase, remove '/' characters
  504. # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
  505. osname = osname.lower().replace('/', '')
  506. machine = machine.replace(' ', '_')
  507. machine = machine.replace('/', '-')
  508. if osname[:5] == "linux":
  509. # At least on Linux/Intel, 'machine' is the processor --
  510. # i386, etc.
  511. # XXX what about Alpha, SPARC, etc?
  512. return "%s-%s" % (osname, machine)
  513. elif osname[:5] == "sunos":
  514. if release[0] >= "5": # SunOS 5 == Solaris 2
  515. osname = "solaris"
  516. release = "%d.%s" % (int(release[0]) - 3, release[2:])
  517. # We can't use "platform.architecture()[0]" because a
  518. # bootstrap problem. We use a dict to get an error
  519. # if some suspicious happens.
  520. bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
  521. machine += ".%s" % bitness[sys.maxint]
  522. # fall through to standard osname-release-machine representation
  523. elif osname[:4] == "irix": # could be "irix64"!
  524. return "%s-%s" % (osname, release)
  525. elif osname[:3] == "aix":
  526. return "%s-%s.%s" % (osname, version, release)
  527. elif osname[:6] == "cygwin":
  528. osname = "cygwin"
  529. rel_re = re.compile (r'[\d.]+')
  530. m = rel_re.match(release)
  531. if m:
  532. release = m.group()
  533. elif osname[:6] == "darwin":
  534. import _osx_support
  535. osname, release, machine = _osx_support.get_platform_osx(
  536. get_config_vars(),
  537. osname, release, machine)
  538. return "%s-%s-%s" % (osname, release, machine)
  539. def get_python_version():
  540. return _PY_VERSION_SHORT
  541. def _print_dict(title, data):
  542. for index, (key, value) in enumerate(sorted(data.items())):
  543. if index == 0:
  544. print '%s: ' % (title)
  545. print '\t%s = "%s"' % (key, value)
  546. def _main():
  547. """Display all information sysconfig detains."""
  548. if '--generate-posix-vars' in sys.argv:
  549. _generate_posix_vars()
  550. return
  551. print 'Platform: "%s"' % get_platform()
  552. print 'Python version: "%s"' % get_python_version()
  553. print 'Current installation scheme: "%s"' % _get_default_scheme()
  554. print
  555. _print_dict('Paths', get_paths())
  556. print
  557. _print_dict('Variables', get_config_vars())
  558. if __name__ == '__main__':
  559. _main()