Commits

anatoly techtonik committed 471091f

First version of Python stdlib tools.

  • Participants

Comments (0)

Files changed (3)

+Tools for experiments with Python stdlib organization
+-----------------------------------------------------
+
+- stdlib.json  - manually maintained mapping of paths
+                 inside stdlib source to module names
+
+  [ ] TODO - scanner to build this file automatically
+  [ ] TODO - Sphinx dumper to compare stdlib contents
+
+- stdlib.py  - module for stdlib queries, currently
+               contains only one useful function
+
+    getmodname(path) - get module name for the path
+
+
+Roadmap
+-----------------------------------------------------
+
+- modstats.py  - get per module stats
+
+  [ ] open patches per module
+    [ ] get list of all open issues with patches
+    [ ] get patch files for each issue
+    [ ] extract paths from each patch
+    [ ] detect modules for the issue using paths
+    [ ] print list of modules and issues
+{
+  "distutils":[
+    "Doc/distutils",
+    "Lib/distutils",
+    "Lib/test/test_distutils.py"
+  ],
+  "json":[
+    "Doc/library/json.rst",
+    "Lib/json",
+    "Lib/test/json_tests",
+    "Lib/test/test_json.py"
+  ]
+}
+"""
+Task 001:
+
+  Given a relative path from the Python checkout, detect to
+which module it belongs.
+
+Task 002:
+
+  Generate module definition file directly from Python source
+or at least validate existing definition file against it to
+ensure no modules are missing.
+
+Task 003:
+
+  Find modified files in Python installation (to create
+patches be sent upstream).
+"""
+import os
+import json
+
+DIR = os.path.abspath(os.path.dirname(__file__))
+MODULES = json.load(open(DIR + '/stdlib.json'))
+
+"""
+{'distutils': ['Doc/distutils', 
+               'Lib/distutils', 
+               'Lib/test/test_distutils.py'],
+ 'json': ['Doc/library/json.rst',
+          'Lib/json',
+          'Lib/test/json_tests',
+          'Lib/test/test_json.py']}
+"""
+
+# --- helpers ---
+def pathsplit(pathstr, maxsplit=1):
+    """Split a path into list.
+
+       :param maxsplit:  left for compatibility with os.path.split
+    """
+    path = [pathstr]
+    while True:
+        oldpath = path[:]
+        path[:1] = list(os.path.split(path[0]))
+        if path[0] == '':
+            path = path[1:]
+        elif path[1] == '':
+            path = path[:1] + path[2:]
+        if path == oldpath:
+            return path
+        if maxsplit is not None and len(path) > maxsplit:
+            return path
+# --- /helpers ---
+
+
+def getmodname(path):
+  """
+  Return module name for the module from standard library given
+  its relative path from source checkout directory.
+  
+  [ ] unify source checkout and target installation layout for
+      standard library
+  """
+  global MODULES
+  
+  path = pathsplit(path, None)
+  for m in MODULES:
+    for p in MODULES[m]:
+      p = pathsplit(p, None)
+      if path[:len(p)] == p:
+        return m
+  else:
+    return ''
+
+
+if __name__ == '__main__':
+  for test in [
+      'Lib/json',
+      'Lib/json/',
+      'Lib/json/foobar',
+      'Doc/library/json.rst']:
+    if getmodname(test) != 'json':
+      print('Test failed.')