config.include issues with a namespace package

15 views
Skip to first unread message

Laurent DAVERIO

unread,
Jan 23, 2017, 3:56:47 PM1/23/17
to pylons-discuss
Hello list,

after upgrading to Pyramid 1.8 and removing all my __pycache__/
directories (running Python 3.5.2 on macOS), I came across a problem I
had never encountered before, and I don't know how to fix.

NB: this is not a bug of Pyramid 1.8, as downgrading to 1.7 doesn't
eliminate the problem.

I have two packages, called ldc and ldc.shop. Both are Pyramid projects,
the latter being a namespace package which extends the former.


/ldc
/ldc
__init__.py (1)


/ldc.shop
/ldc
__ init__.py (2)
/shop
__init__.py (3)


File (3) contains a "config.include('ldc')" statement, which should
refer to file (1). But instead, it now refers to file (2), which of
course contains no includeme() function.

I've used that layout for several years without any problem (other than
having to symlink directory "shop/" under ldc/ldc), so I have no idea of
what is happening now.

Any help appreciated, thanks in advance!

Laurent.

Michael Merickel

unread,
Jan 23, 2017, 4:13:24 PM1/23/17
to Pylons
If the package has code in its `__init__.py` then it is no longer a real namespace package and I think you've been getting "lucky" for this long probably due to the order in which the packages were installed. A namespace package is a grouping of submodules/subpackages, but the top-level module in the package should always be empty and / or identical to the module in every separately-distributed copy of that file. Normally this means the file would just include a namespace declaration required to make setuptools work, although in py3 you can apparently get rid of the file entirely (meaning you shouldn't assume you can put code in there).


Laurent.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/17192211-04e2-442d-e707-3988a052a986%40cri.ensmp.fr.
For more options, visit https://groups.google.com/d/optout.

Laurent DAVERIO

unread,
Jan 25, 2017, 7:23:16 AM1/25/17
to pylons-...@googlegroups.com
Thank you Michael,

the fact is, I started with Python 2.7 some 4-5 years ago, and migrated
to 3.x around mid-2015. The incriminated __init__.py contains only the
following lines, as per instructions I had found somewhere (can't
remember where):

> # this is a namespace package
> from pkgutil import extend_path
> __path__ = extend_path(__path__, __name__)

I'll try to get rid of it entirely, as I don't wish to maintain Python
2.x compatibility. I like to burn my bridges sometimes ;)

Thanks again,

Laurent.

Laurent DAVERIO

unread,
Jan 25, 2017, 7:32:30 AM1/25/17
to pylons-...@googlegroups.com
> I'll try to get rid of it entirely, as I don't wish to maintain Python
> 2.x compatibility. I like to burn my bridges sometimes ;)

OK, it works, provided I reinstate the symlink:

ldc/ldc/shop --> ldc.shop/ldc/shop

Python namespace packages are really kludgy, it's a disappointment.
Python is usually smarter...

Laurent.

Michael Merickel

unread,
Jan 25, 2017, 10:39:00 AM1/25/17
to Pylons
On Wed, Jan 25, 2017 at 6:32 AM, Laurent DAVERIO <ldav...@gmail.com> wrote:
OK, it works, provided I reinstate the symlink:

ldc/ldc/shop --> ldc.shop/ldc/shop

Python namespace packages are really kludgy, it's a disappointment.
Python is usually smarter...

I won't deny that namespace packages are kludgy but it does sound like you're not quite doing it right.

The namespace declaration should be in each `__init__.py` from each separately distributed package. It sounds like 1) you are not defining the package as a namespace in *every* copy of the package's `__init__.py` and 2) you are not distributing them separately and are instead just symlinking them together into a single package - thus not really utilizing namespace packages as far as Python is concerned.
Reply all
Reply to author
Forward
0 new messages