[Distutils] namespace_package

Zvezdan Petkovic zvezdanpetkovic at gmail.com
Sat Dec 5 01:02:27 EST 2015


Hi Lele,

I experimented with your GitHub demo project.

First, let’s state that the custom distclass I sent previously on this thread definitely helps Kevin (KP, the original poster) with the editable packages in a namespace.

Unfortunately, the fundamental problem and the reason why it doesn’t help you is as follows:

- The solution relies on the presence of a *.pth file for the namespace that extends the path to include the editable package which has only the *.egg-link file

- When you install a package, it gets the correct file structure in site-packages as bugex/foo/__init__.py and you have a *.pth file so everything works fine (no need for custom distclass)

- When python imports such a package it follows the file-structure in site-packages and succeeds.

- When you install it as an editable package, there’s no *.pth file, only *.egg-link that leads to your source
 
- However, the source code does not have a directory for bugex (the namespace) and it fails to import

In essence, the Python importer expects a directory for each part separated with dot. Thus, if there’s import bugex.foo it expects a directory for bugex which contains a foo directory.

I’m afraid your editable package must follow the file structure that gets installed into site-packages or you’ll have to write a custom importer for such packages.

In conclusion:

1. The solution I sent helps with regularly structured packages installed editable as a part of a namespace.
     (the pip issue #3)

2. I don’t see the way to use the flatten file structure as editable. (the issue #3160 that you opened)

Sorry for not being of too much help for your issue. Maybe someone else might help.

Honestly, I do not have a compelling motive for not keeping the packages and namespaces hierarchically structured even with Python 3. We usually do not nest our namespaces deeper than 2 anyway (e.g., zope.app.session).

In Java development it’s quite common to see file structure like this:

    src/java/main/com/somecompany/x/y/z/SomeClass.java
    src/java/test/com/somecompany/x/y/z/TestSomeClass.java
    src/scala/main/….

You get the idea. And all the directories until z would have no code in them.
At least we don’t need to do that much nesting.
:-)

All the best,

Zvezdan


> On Dec 4, 2015, at 12:19 PM, Lele Gaifax <lele at metapensiero.it> wrote:
> 
> Zvezdan Petkovic <zvezdanpetkovic at gmail.com> writes:
> 
>> Did you try that?
> 
> Yes, indeed that way it works, an all my packages do that. But, as explained
> by the https://github.com/pypa/pip/issues/3160 issue, I would like to use a
> shallower tree for some of them.
> 
> Thanks for taking a look!
> 
> ciao, lele.
> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> lele at metapensiero.it  |                 -- Fortunato Depero, 1929.
> 
> _______________________________________________
> Distutils-SIG maillist  -  Distutils-SIG at python.org
> https://mail.python.org/mailman/listinfo/distutils-sig



More information about the Distutils-SIG mailing list