Made sysconfig a script that displays useful information - #8770
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index a95ea8d..007d82b 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -686,3 +686,22 @@
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()
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index 968f3de..f4a3c8e 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -11,13 +11,14 @@
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 @@
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)