Repository: google/pytype

Issue:
Include LICENSE in MANIFEST.in.
This PR needs to be imported and re-exported rather than merged directly.

Fixes #246.


Discussion:

Resolving patch:
diff --git a/pytype/tools/xref/indexer.py b/pytype/tools/xref/indexer.py
--- a/pytype/tools/xref/indexer.py
+++ b/pytype/tools/xref/indexer.py
@@ -6,8 +6,6 @@
 
 import collections
 import logging
-import os
-import re
 
 from pytype import abstract
 from pytype import analyze
@@ -17,6 +15,7 @@
 from pytype import module_utils
 from pytype import utils
 
+from pytype.tools.xref import utils as xref_utils
 from pytype.tools.xref import kythe
 
 from typed_ast import ast27t as ast27
@@ -117,21 +116,6 @@ def get_opcodes(traces, lineno, op_list):
   return [x for x in traces[lineno] if x[0] in op_list]
 
 
-def get_module_filepath(module):
-  """Recover the path to the py file from a module pyi path."""
-
-  def _clean(path):
-    """Change extension to .py."""
-    prefix, fname = os.path.split(path)
-    fname, _ = os.path.splitext(fname)
-    path = os.path.join(prefix, fname + ".py")
-    return path
-
-  return _clean(module.filename)
-
-
-
-
 # Internal datatypes
 
 
@@ -302,6 +286,7 @@ class Definition(collections.namedtuple(
     scope: The namespace id (e.g. module:class A:function f:x)
     target: The LHS of an attribute (e.g. for x.foo, target = typeof(x))
     doc: The docstring, if any, for function and class defs
+    id: The id
   """
 
   def __init__(self, name, typ, scope, target, doc):
@@ -370,7 +355,8 @@ class Reference(collections.namedtuple(
     scope: The namespace id (e.g. module.A.f)
     ref_scope: The namespace id of the referred symbol (if we can determine it)
     target: The LHS of an attribute (e.g. for x.foo, target = typeof(x))
-    location: The line and column of the symbol in the source code.
+    location: The line and column of the symbol in the source code
+    id: The id
   """
 
   def __init__(self, name, typ, data, scope, ref_scope, target, location):
@@ -1060,7 +1046,7 @@ def _make_defn_vname(self, defn):
     if isinstance(defn, Remote):
       remote = defn.module
       if remote in self.resolved_modules:
-        path = get_module_filepath(self.resolved_modules[remote])
+        path = xref_utils.get_module_filepath(self.resolved_modules[remote])
         sig = "module." + defn.name
         if path.startswith("pytd:"):
           return self.kythe.builtin_vname(sig, path)
diff --git a/pytype/tools/xref/utils.py b/pytype/tools/xref/utils.py
new file mode 100644
--- /dev/null
+++ b/pytype/tools/xref/utils.py
@@ -0,0 +1,16 @@
+"""Utilities for xref."""
+
+import os
+
+
+def get_module_filepath(module):
+  """Recover the path to the py file from a module pyi path."""
+
+  def _clean(path):
+    """Change extension to .py."""
+    prefix, fname = os.path.split(path)
+    fname, _ = os.path.splitext(fname)
+    path = os.path.join(prefix, fname + ".py")
+    return path
+
+  return _clean(module.filename)


Test patch:
diff --git a/pytype/tools/xref/TESTING.md b/pytype/tools/xref/TESTING.md
--- a/pytype/tools/xref/TESTING.md
+++ b/pytype/tools/xref/TESTING.md
@@ -6,4 +6,3 @@ release](https://github.com/google/kythe/releases) and unpack it to `$HOME/kythe
 ````
 xref testdata/testcase.py | ./kythe-verifier.sh testdata/testcase.py
 ````
-
diff --git a/pytype/tools/xref/indexer_test.py b/pytype/tools/xref/indexer_test.py
--- a/pytype/tools/xref/indexer_test.py
+++ b/pytype/tools/xref/indexer_test.py
@@ -3,7 +3,6 @@
 
 from pytype import config
 from pytype import file_utils
-from pytype import load_pytd
 
 from pytype.tests import test_base
 
@@ -12,8 +11,6 @@
 from pytype.tools.xref import output
 
 
-
-
 class IndexerTest(test_base.TargetIndependentTest):
   """Tests for the indexer."""