[Import-SIG] PEP 402: specification questions
"Martin v. Löwis"
martin at v.loewis.de
Thu Nov 10 06:32:59 CET 2011
> Indeed, I don't see PEP 382 reducing the number of "Why doesn't my
> 'foo' package work?" questions from beginners either
Do beginners really have that question (i.e. can you kindly point
me to archived examples of that question)? I'd expect beginners to
do whatever tutorials and examples tell them to do. If these refer
to P.pyp folders, beginners will just take that as given, and copy
it.
> since it just replaces "add an __init__.py" with "change your
directory name to
> 'foo.pyp'".
Why should users have to *change* the directory name? When they
create a package, they would create the .pyp directory to begin
with, so no need to change it.
> PEP 402, by contrast, should *just work* in the most
> natural way possible. Similarly, "fixing" packaging conflicts just
> becomes a matter of making sure that *none* of the distro packages
> involved install an __init__.py file. By contrast, PEP 382 requires
> that *all* of the distro packages be updated to install to "foo.pyp"
> directories instead of "foo" directories.
See my message to Barry: setuptools/distribute could do that, with
no change to the source tree.
When people are ready to give up pre-3.3 support, they would likely
have to modify *all* distro packages either way: with PEP 402, they
would need to drop the __init__.py from the sources, and with PEP 382,
they would additionally need to rename the directory.
However, with PEP 382, they don't *have* to do that: some portions
of a namespace package may keep the __init__.py, others may drop it,
and it would still form a single namespace. OTOH, with PEP 402,
*all* portions of the namespace would have simultaneously to agree
to use the PEP 402 mechanism, since that mechanism will be ineffective
if there is an __init__.py.
> While there's no reference implementation for PEP 402 that updates the
> standard import machinery as yet, it's worth taking a look at Greg
> Slodkowic's importlib-based implementation that came out of GSoC this
> year: https://bitbucket.org/jergosh/pep-402
Not sure whether that's the right way to use it, but I tried
setting builtins.__import__ = importlib.__import__. Then,
with "foo/bar.py" on disk, "import foo.bar" works fine. Interestingly,
"import foo" fails afterwards, even though "foo" is in sys.path.
Consequently, "from foo import bar" also fails, just as Phillip
predicted. I presume that will have to be fixed in the PEP and
the implementation.
Regards,
Martin
More information about the Import-SIG
mailing list