When config.py is missing from hg clone demand import tries to use "random" package config.py
Created originally on Bitbucket by steve_barnes (Steve Barnes)
Running from source TortoiseHg Dialogues (version 2.10.1+182-d2d315e6fbf9), Mercurial (version 2.8.1). Depending on the content of PYHTONPATH and lib/site-packages when thg loads it attempts to import from tortoise.util.config - if this fails then demandimport will import any config module that it finds - in my case it is now importing config from wxPython 3.0.0 or from pyspread.
This seems to be because it effectively does from [.[.*]] import config.
I tried numerous PYTHONPATH values and it just changed which other package the wrong config.py was found in. Eventually I figured out that the tortoisehg hg repository doesn't contain config.py and does contain .hg/requies so that setup.py wasn't creating a config.py - once I 'manually' forced its creation the problem disappeared.
I do feel that, if from package import * is discouraged because of the
lack of clarity due to name space removal, and because of the hard to
diagnose problems that occur when you have name clashes, then code that
effectively does if not found path.to.package from
anwhere.recurse.package import ... is potentially even more perilous.
In my specific case if the exception output had been "can't load
tortoisehg.util.config" I would probably have resolved the issue in a
few minutes as it was I was getting "missing method mmmm in
random.package.config" - this took days to isolate.
Classing as minor as this only occurs when running from source repository in the absence of config.py in util directory.