]> granicus.if.org Git - python/commitdiff
Made sysconfig a script that displays useful information - #8770
authorTarek Ziadé <ziade.tarek@gmail.com>
Tue, 25 May 2010 09:44:36 +0000 (09:44 +0000)
committerTarek Ziadé <ziade.tarek@gmail.com>
Tue, 25 May 2010 09:44:36 +0000 (09:44 +0000)
Doc/library/sysconfig.rst
Lib/sysconfig.py
Lib/test/test_sysconfig.py
Misc/NEWS

index 24264364c3922de4cdebd2b133234ab315e3167d..0a7e3de17b25e4192c0cf48252000f93b0c7b2f8 100644 (file)
@@ -216,3 +216,35 @@ Other functions
 .. function:: get_config_h_filename()
 
    Return the path of :file:`pyconfig.h`.
+
+Using :mod:`sysconfig` as a script
+----------------------------------
+
+You can use :mod:`sysconfig` as a script with Python's *-m* option::
+
+    $ python -m sysconfig
+    Platform: "macosx-10.4-i386"
+    Python version: "3.2"
+    Current installation scheme: "posix_prefix"
+
+    Paths:
+            data = "/usr/local"
+            include = "/Users/tarek/Dev/svn.python.org/py3k/Include"
+            platinclude = "."
+            platlib = "/usr/local/lib/python3.2/site-packages"
+            platstdlib = "/usr/local/lib/python3.2"
+            purelib = "/usr/local/lib/python3.2/site-packages"
+            scripts = "/usr/local/bin"
+            stdlib = "/usr/local/lib/python3.2"
+
+    Variables:
+            AC_APPLE_UNIVERSAL_BUILD = "0"
+            AIX_GENUINE_CPLUSPLUS = "0"
+            AR = "ar"
+            ARFLAGS = "rc"
+            ASDLGEN = "./Parser/asdl_c.py"
+            ...
+
+This call will print in the standard output the information returned by
+:func:`get_platform`, :func:`get_python_version`, :func:`get_path` and
+:func:`get_config_vars`.
index a95ea8dccf86311e26cad795bcecddcd1b9ce29d..007d82b112971cd7c77a0216bd2b558feef157f0 100644 (file)
@@ -686,3 +686,22 @@ def get_platform():
 
 def get_python_version():
     return _PY_VERSION_SHORT
+
+def _print_dict(title, data):
+    for index, (key, value) in enumerate(sorted(data.items())):
+        if index == 0:
+            print('{0}: '.format(title))
+        print('\t{0} = "{1}"'.format(key, value))
+
+def _main():
+    """Displays all information sysconfig detains."""
+    print('Platform: "{0}"'.format(get_platform()))
+    print('Python version: "{0}"'.format(get_python_version()))
+    print('Current installation scheme: "{0}"'.format(_get_default_scheme()))
+    print('')
+    _print_dict('Paths', get_paths())
+    print('')
+    _print_dict('Variables', get_config_vars())
+
+if __name__ == '__main__':
+    _main()
index 968f3de51d9f55a1d6d4ce89f91bf00a731b5d87..f4a3c8ea1724126aff4307043f029b3ac8454b1d 100644 (file)
@@ -11,13 +11,14 @@ import subprocess
 import shutil
 from copy import copy, deepcopy
 
-from test.support import run_unittest, TESTFN, unlink, get_attribute
+from test.support import (run_unittest, TESTFN, unlink, get_attribute,
+                          captured_stdout)
 
 import sysconfig
 from sysconfig import (get_paths, get_platform, get_config_vars,
                        get_path, get_path_names, _INSTALL_SCHEMES,
                        _get_default_scheme, _expand_vars,
-                       get_scheme_names, get_config_var)
+                       get_scheme_names, get_config_var, _main)
 
 class TestSysConfig(unittest.TestCase):
 
@@ -264,6 +265,13 @@ class TestSysConfig(unittest.TestCase):
             user_path = get_path(name, 'posix_user')
             self.assertEquals(user_path, global_path.replace(base, user))
 
+    def test_main(self):
+        # just making sure _main() runs and returns things in the stdout
+        with captured_stdout() as output:
+            _main()
+        self.assertTrue(len(output.getvalue().split('\n')) > 0)
+
+
 def test_main():
     run_unittest(TestSysConfig)
 
index df363451ac443b2cafc0c6b9f2e7b69577273668..ecf5744ebc7cbe813f1592597742c0ae2d8751d7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -392,6 +392,9 @@ C-API
 Library
 -------
 
+- Issue #8770: now sysconfig displays information when it's called as
+  a script. Initial idea by Sridhar Ratnakumar.
+
 - Issue #6662: Fix parsing of malformatted charref (&#bad;), patch written by
   Fredrik Håård