Commit e870781d authored by Kirill Smelkov's avatar Kirill Smelkov

Top-level in-tree import redirector

For working copy checkout we would like to work on the source
right-away, without putting it under additional wendelin/ (and possibly
/core/) subdirectories.

Add in-tree modules redirector which tweaks plain-python and
pkg_resources-based imports so that e.g.

    import wendelin.bigarray

while in-tree resolves to

    bigarray/__init__.py

In installed state, there will be no such redirector, and code will be
installed with conventional structure.
parent 66c976ed
# Wendelin.core | Top-level in-tree python import redirector
# Copyright (C) 2014-2015 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
......@@ -14,3 +15,39 @@
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# tell python wendelin.* modules hierarchy starts at top-level
#
# This allows e.g. `import wendelin.bigarray`
# to resolve to importing `bigarray/__init__.py`
#
# and thus avoid putting everything in additional top-level wendelin/
# directory in source tree.
#
# see https://www.python.org/doc/essays/packages/ about __path__
# XXX avoid being imported twice, e.g. `import wendelin.wendelin` should not work.
from os.path import dirname, realpath
__path__ = [realpath(dirname(__file__))]
del dirname, realpath
# Also tell setuptools/pkg_resources 'wendelin' is a namespace package
# ( so that wendelin.core installed in development mode does not brake
# 'wendelin' namespacing wrt other wendelin software )
__import__('pkg_resources').declare_namespace(__name__)
# pkg_resources will append '.../wendelin' to __path__ which is not right for
# in-tree setup and thus is not needed here. Remove it.
del __path__[1:]
# in the end we have:
# __path__ has 1 item
# __path__[0] points to working tree
# __name__ registered as namespace package
#
# so the following should work:
# - importing from in-tree files
# - importing from other children of wendelin packages
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment