Patchwork D5046: hgdemandimport: adjust imports to reflect vendored module

login
register
mail settings
Submitter phabricator
Date Oct. 13, 2018, 7:28 a.m.
Message ID <differential-rev-PHID-DREV-q6te53l22my7h4wzoicx-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/35832/
State New
Headers show

Comments

phabricator - Oct. 13, 2018, 7:28 a.m.
indygreg created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The "token" module is renamed in our local copy. Import it appropriately.
  
  This angered test-check-module-imports due to attempting relative import of
  stdlib module and direct symbol imports. We suppress that check on this file
  since it is mostly 3rd party code.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5046

AFFECTED FILES
  hgdemandimport/py3token.py
  hgdemandimport/py3tokenize.py
  tests/test-check-module-imports.t

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mjpieters, mercurial-devel

Patch

diff --git a/tests/test-check-module-imports.t b/tests/test-check-module-imports.t
--- a/tests/test-check-module-imports.t
+++ b/tests/test-check-module-imports.t
@@ -25,6 +25,7 @@ 
   > -X contrib/win32/hgwebdir_wsgi.py \
   > -X doc/gendoc.py \
   > -X doc/hgmanpage.py \
+  > -X hgdemandimport/py3tokenize.py \
   > -X i18n/posplit \
   > -X mercurial/thirdparty \
   > -X tests/hypothesishelpers.py \
diff --git a/hgdemandimport/py3tokenize.py b/hgdemandimport/py3tokenize.py
--- a/hgdemandimport/py3tokenize.py
+++ b/hgdemandimport/py3tokenize.py
@@ -59,6 +59,10 @@ 
 # * Removed generate_tokens().
 # * Removed open().
 # * Removed module docstring.
+# * Adjusted for relative imports.
+# * absolute_import added.
+
+from __future__ import absolute_import
 
 __author__ = 'Ka-Ping Yee <ping@lfw.org>'
 __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
@@ -69,15 +73,15 @@ 
 from itertools import chain
 import itertools as _itertools
 import re
-from token import *
+from .py3token import *
 
 cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
 blank_re = re.compile(br'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII)
 
-import token
-__all__ = token.__all__ + ["tokenize", "detect_encoding",
-                           "untokenize", "TokenInfo"]
-del token
+from . import py3token
+__all__ = py3token.__all__ + ["tokenize", "detect_encoding",
+                              "untokenize", "TokenInfo"]
+del py3token
 
 EXACT_TOKEN_TYPES = {
     '(':   LPAR,
diff --git a/hgdemandimport/py3token.py b/hgdemandimport/py3token.py
--- a/hgdemandimport/py3token.py
+++ b/hgdemandimport/py3token.py
@@ -56,9 +56,12 @@ 
 # Changes from official Python source code:
 #
 # * _main() and related functionality removed.
+# * absolute_import added.
 
 """Token constants (from "token.h")."""
 
+from __future__ import absolute_import
+
 __all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
 
 #  This file is automatically generated; please don't muck it up!