jayvdb added a comment.

On Python 3.3+, it appears to be possible for a separate package to install 
family files into `pywikibot.families` **if** `pywikibot/__init__.py` includes:

  from pkgutil import extend_path
  __path__ = extend_path(__path__, __name__)

That means the `pywikibot` namespace isnt using PEP420, but it can contain 
PEP420 namespaces.

This appears to not work in lower versions of Python, as 
`pywikibot/__init__.py` can not include other code.
https://www.python.org/dev/peps/pep-0420/#namespace-packages-today says the 
following regarding pkgutil:

  As a consequence, the package's __init__.py cannot practically define any 
names as it depends on the order of the package fragments on sys.path to 
determine which portion is imported first.

Anyway on Python 3.3, we can delete `pywikibot/families/__init__.py` so that 
the namespace `pywikibot.families` is using PEP420, even when the `pywikibot` 
namespace is not.  Works lovely under Python 3.3+ but completely fails in 
earlier versions.

Setuptools' `pkg_resources.declare_namespace` is a very large hack that I still 
dont completely understand, and the complexity involved worries me, and I read 
a lot of similar warnings that `__init__.py` can not include other code anyway. 
 Depending on setuptools will probably annoy folks stuck on older systems.

Also, `importlib2` says it is Python 2.7+, and hasnt been updated for six 
months, so might be unmaintained, and definitely doesnt work as-is on Python 
2.6:

  Traceback (most recent call last):
    File "<string>", line 20, in <module>
    File "/tmp/pip-build-jB5cAM/importlib2/setup.py", line 13, in <module>
      vers = _util.load_version()
    File "_util/__init__.py", line 19, in load_version
      import _version
    File "/tmp/pip-build-jB5cAM/importlib2/importlib2/_version/__init__.py", 
line 27, in <module>
      VERSION = '{}.{}'.format(PY_VERSION, RELEASE)
  ValueError: zero length field name in format

So, I built my own much simpler hack to load the real pywikibot `__init__.py` 
to be called from the `__init__` from a different distributed package 
`pywikibot` is loaded first.


TASK DETAIL
  https://phabricator.wikimedia.org/T104130

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: jayvdb
Cc: pywikibot-bugs-list, jayvdb, Gallaecio, Aklapper, XZise, Malyacko, P.Copp



_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to