CINXE.COM

[Import-SIG] Namespace Packages resolution

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <TITLE> [Import-SIG] Namespace Packages resolution </TITLE> <LINK REL="Index" HREF="index.html" > <LINK REL="made" HREF="mailto:import-sig%40python.org?Subject=Re%3A%20%5BImport-SIG%5D%20Namespace%20Packages%20resolution&In-Reply-To=%3C4F5E6703.2080503%40v.loewis.de%3E"> <META NAME="robots" CONTENT="index,nofollow"> <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> <LINK REL="Previous" HREF="000420.html"> <LINK REL="Next" HREF="000422.html"> </HEAD> <BODY BGCOLOR="#ffffff"> <H1>[Import-SIG] Namespace Packages resolution</H1> <B>&quot;Martin v. L&#246;wis&quot;</B> <A HREF="mailto:import-sig%40python.org?Subject=Re%3A%20%5BImport-SIG%5D%20Namespace%20Packages%20resolution&In-Reply-To=%3C4F5E6703.2080503%40v.loewis.de%3E" TITLE="[Import-SIG] Namespace Packages resolution">martin at v.loewis.de </A><BR> <I>Mon Mar 12 22:13:39 CET 2012</I> <P><UL> <LI>Previous message: <A HREF="000420.html">[Import-SIG] Where to discuss PEP 382 vs. PEP 402 (namespace packages)? </A></li> <LI>Next message: <A HREF="000422.html">[Import-SIG] Namespace Packages resolution </A></li> <LI> <B>Messages sorted by:</B> <a href="date.html#421">[ date ]</a> <a href="thread.html#421">[ thread ]</a> <a href="subject.html#421">[ subject ]</a> <a href="author.html#421">[ author ]</a> </LI> </UL> <HR> <!--beginarticle--> <PRE>We were just discussing the namespaces PEPs here at PyCon. We agreed to accept many, but not all principles of PEP 402; PEP 382 was essentially rejected. As a consequence, Eric Smith volunteered to write a new PEP covering the consensus. Here are the basic principles: - there will be two kinds of packages, &quot;regular packages&quot; and &quot;namespace packages&quot; (exact terminology subject to bikeshedding) - &quot;regular&quot; packages have an __init__.py, and live in a single directory - namespace packages can span multiple directories, and cannot have code on their own - there will be no explicit marker for namespace packages; any directory on the path (sys.path or package __path__) can constitute a package. Package names equal directory names - Importing a module/package keeps iterating over the parent path as before, and keeps with the current precedence: * if foo/__init__.py is found, a regular package is imported * if not, but foo.{py,pyc,so,pyd} is found, a module is imported * if not, but foo is found as a directory, it is recorded When search completes without importing a module, but it did find directories, then a namespace package is created. That namespace package * has an __name__ of the first directory that was found * has an __path__ which is the full list of directories that were collected Of PEP 402, the following features where rejected: - there is no support for code in a namespace package (i.e. you cannot use both foo/ and foo.py, but one will take precedence - depending on which one occurs first on the path) - the PEP 402 terminology calling things &quot;virtual&quot; was rejected - in the consensus spec, &quot;import foo&quot; alone will already trigger the path search, i.e. it is not deferred until a sub-level import occurs A number of aspects are still undecided - the API to dynamically update the __path__ was not immediately considered necessary. It may or may not be part of the PEP - the specific API of PEP 302 finders and loaders for this feature was not specified; it will draw on the research done for PEP 382 and PEP 402. The implementation will likely be provided once the import mechanism in CPython is based on importlib. Regards, Martin </PRE> <!--endarticle--> <HR> <P><UL> <!--threads--> <LI>Previous message: <A HREF="000420.html">[Import-SIG] Where to discuss PEP 382 vs. PEP 402 (namespace packages)? </A></li> <LI>Next message: <A HREF="000422.html">[Import-SIG] Namespace Packages resolution </A></li> <LI> <B>Messages sorted by:</B> <a href="date.html#421">[ date ]</a> <a href="thread.html#421">[ thread ]</a> <a href="subject.html#421">[ subject ]</a> <a href="author.html#421">[ author ]</a> </LI> </UL> <hr> <a href="http://mail.python.org/mailman/listinfo/import-sig">More information about the Import-SIG mailing list</a><br> </body></html>

Pages: 1 2 3 4 5 6 7 8 9 10