Importlib shim that enables mixed syntax in Python packages and executables.
Go to file
Elf M. Sternberg 39e93c354f Better, I think. 2016-09-03 13:22:44 -07:00
docs Better, I think. 2016-09-03 13:22:44 -07:00
polyloader Remove debugging tracer. 2016-07-09 18:21:01 -07:00
tests_py2 Python 3's testing suite is radically different from 2's. I'm trying 2016-07-09 13:54:59 -07:00
tests_py3 Compilers should be static when they're just functions; when they're callable objects, they control their own instance of 'self'. 2016-07-09 17:46:21 -07:00
.gitignore Polyloader for Python 2 (2.6 and 2.7) is GREEN. Woot! 2016-06-30 22:11:10 -07:00
AUTHORS.rst Initial check-in of Cookiecutter version. 2016-06-04 17:54:28 -07:00
CONTRIBUTING.rst Unit tests working, with pkgutil not broken, on Python 3.3!!! 2016-06-05 09:15:12 -07:00
HISTORY.rst Initial check-in of Cookiecutter version. 2016-06-04 17:54:28 -07:00
LICENSE Initial check-in of Cookiecutter version. 2016-06-04 17:54:28 -07:00
MANIFEST.in Fixed build issue. Skipped pypy bytecode-without-source tests. 2016-07-03 16:43:09 -07:00
Makefile Still working out the docs. 2016-09-01 10:55:16 -07:00
README.rst Better, I think. 2016-09-03 13:22:44 -07:00
requirements.txt Sorta an initial check-in. 2016-05-29 09:42:34 -07:00
requirements_dev.txt Initial check-in of Cookiecutter version. 2016-06-04 17:54:28 -07:00
run_tests.py Sorta an initial check-in. 2016-05-29 09:42:34 -07:00
setup.cfg Name change. Pain in the neck. 2016-06-04 18:01:27 -07:00
setup.py Fixed build issue. Skipped pypy bytecode-without-source tests. 2016-07-03 16:43:09 -07:00
tox.ini Initial support for Python 3 completed. 2016-07-09 14:53:45 -07:00

README.rst

Synopsis
--------

**Polyloader** is a python module that extends the Python `import`
statement to enable the discovery and loading of heterogenous source
code packages.

Say What? In English this time
-------------------------------

The ``import`` statement is how the Python interpreter finds a module
written in Python and loads it, turning it into variables, executable
functions, constructable classes, and other Python objects, and then
exposes those objects to the currently running program.

The ``import`` statement has long been extensible so that things other
than Python code could be imported, but this feature has always had two
limitations:

1. It's annoyingly hard to write an importer. (Believe me. Polyloader
   *is* one!)
2. For filesystem-based modules (which is 99% of them) Python's importer
   only understands one loader type per directory.  It's not possible to
   store code or data written in something other than Python in the same
   directory with Python module code and load both via ``import``.

The former requires a certain degree of abstraction and thought.  For
the latter, most people ignore the problem and load module configuration
files written in JSON or YAML or whatever directly.  This is fine,
except when you want to write in one of Python's extended languages like
Hy or Coconut in a framework like Django, Flask or Glitch.

**Polyloader** eliminates these limitations.

What's the real problem?
------------------------

The real problem is that Python's traditional extensions, ``.py``,
``.pyc/.pyo``, and ``.so/.dll`` files, are hard-coded in Python.  In
Python 2, they're in the ``_imp`` builtin; In Python 3, they're defined
in a private section of `importlib`.  Either way, they're not accessible
for modification and extension.

This problem is made harder by the ``pkglib`` module, which is part of
Python's standard library.  This module uses ``inspect.getmoduleinfo``,
which again only recognizes the usual extensions.  Which means you can't
list multilingual modules either; this hampers the development of Django
management commands in a syntax other than Python.

What the solution?
------------------

At its heart, the Python import system runs two different internal
mechanisms to figure out what the *import string* (the dotted terms
after the word "import") "means."  Each mechanism has one or more
*finders*, and the first finder to report "I have a *loader* that knows
what that import string means" wins.

The very last finder is for the filesystem.  The solution is to get in
front of that finder with one that can handle all the other syntax
loaders *and* knows how to fall back on the last one for those files the
last one handles.

That's what ``polyloader`` does.