Commit Graph

13 Commits

Author SHA1 Message Date
Augie Fackler
33d314f3e6 demandimportpy3: update to pass import checker 2017-08-22 14:14:34 -04:00
Jun Wu
3e05e789bc demandimport: disable if chg is being used
In chg's case, making modules lazily loaded could actually slow down things
since chg pre-imports them. Therefore disable demandimport if chg is being
used.

This is not done by setting `HGDEMANDIMPORT` chg client-side because that
has side-effects on child processes (hooks, etc).

Differential Revision: https://phab.mercurial-scm.org/D351
2017-08-16 10:44:06 -07:00
Jun Wu
e60bc9fd17 demandimport: move HGDEMANDIMPORT test to __init__.py
The logic is now shared between demandimport{2,3}.

Differential Revision: https://phab.mercurial-scm.org/D445
2017-08-18 11:08:17 -07:00
Yuya Nishihara
0d4ca251b9 demandimport: prefer loaded module over package attribute (issue5617)
In general, the attribute of the same name is overwritten by executing an
import statement.

  import a.b
  print(a.b.c)  # 'c' of a/b/__init__.py
  from a.b.c import d
  print(a.b.c)  # a/b/c.py

However, this appears not true for the scenario described in the test case,
and surprisingly, "from a.b.c import d" works even if "a.b.c" is not a module.

This patch works around the problem by taking the right module from sys.modules
if available.
2017-07-16 17:38:39 +09:00
Yuya Nishihara
7c2ef4a52e demandimport: drop Py3 workarounds from Py2 implementation 2017-07-16 17:19:22 +09:00
Yuya Nishihara
99466473c5 demandimport: drop hack for old Pythons which had no level argument
_import() was added by 1538e0df23b4, but it is identical to _origimport()
now.
2017-07-16 17:16:32 +09:00
Yuya Nishihara
07ba7d360b demandimport: stop overriding __getattribute__()
Proxy __dict__ and __doc__ explicitly instead.

I'm not sure which is less evil, but this seems slightly simpler than hooking
all attribute accesses.
2017-04-28 00:01:22 +09:00
Yuya Nishihara
7cd4cd9753 demandimport: look for 'mod' suffix as alternative name for module reference
It's widely used in our codebase.
2017-04-28 23:46:16 +09:00
Yuya Nishihara
3bbb35ccf6 demandimport: insert empty line per method
_demandmod class is getting bigger, and I don't want to put more things in
a dense form.
2017-05-01 14:26:56 +09:00
Yuya Nishihara
8bad75346f demandimport: strictly compare identity of proxy object
This looks better, and __eq__() may be overridden in an undesired way.
2017-05-01 13:43:31 +09:00
Siddharth Agarwal
71d917f14d demandimport: add python 3 implementation
This implementation uses the new importlib finder/loader functionality
available in Python 3.5 and up.

# no-check-commit
2017-05-21 12:23:04 -07:00
Siddharth Agarwal
8ffb99bcb0 demandimport: move ignore list to __init__.py
We're going to use the same ignore list for Python 3.
2017-05-21 12:10:53 -07:00
Siddharth Agarwal
a41c665cd6 demandimport: move to separate package
In Python 3, demand loading is per-package. Keeping demandimport in the
mercurial package would disable demand loading for any modules in
mercurial.
2017-05-21 12:10:53 -07:00