Fix situation where a module name is identical to the package name

Bug #80403 reported by Jan Wijbrand Kolman
4
Affects Status Importance Assigned to Milestone
grok
Fix Released
Low
Jan Wijbrand Kolman

Bug Description

There're some issues when there is a module with a name identical to the package name using grok. People using grokproject will finf themselves in this situation by default.

This easily gets confusing with:

* registering templates.

* relative imports.

Revision history for this message
Jan Wijbrand Kolman (janwijbrand) wrote :

This issue is being discussed on the grok-dev list.

description: updated
Revision history for this message
Philipp von Weitershausen (philikon) wrote :

Apart from the fact that we need to come up with a solution for the templates in case we have foo/foo.py, we should not encourage this situation for beginners in grokproject. I wonder what a good name for a start-out module would be (foo/foomodel.py? foo/model.py? foo/demo.py? ...)

Revision history for this message
Philipp von Weitershausen (philikon) wrote :

Preliminary fix was commited in r72234. grokproject now asks you for the name of the module it creates.

Changed in grok:
status: Unconfirmed → In Progress
Revision history for this message
Martijn Faassen (faassen) wrote :

The issue in grokproject was solved (as remarked). The issue in grok itself maybe hasn't been solved yet so I'm leaving this open.

Changed in grok:
importance: Undecided → Low
Revision history for this message
Jan Wijbrand Kolman (janwijbrand) wrote :

This issue has a partial fix in that grokproject will ask for a "main" module name. I think this is the best we can do in practical terms, as it really is a Python "thing" that having identical module names and package names can lead to import-confusion.

Can someone either follow-up on this issue, or close it? (IMHO it can really be closed)

Revision history for this message
Philipp von Weitershausen (philikon) wrote : Re: [Bug 80403] Re: Fix situation where a module name is identical to the package name

On 5 Nov 2007, at 10:27 , Jan Wijbrand Kolman wrote:
> This issue has a partial fix in that grokproject will ask for a "main"
> module name.

This isn't a fix, this is actually the cause for this problem. Let's
say somebody adds a HelloWorld sandbox and calls the "main" module
helloworld.py too:

   grokproject HelloWorld
   ... [app.py] helloworld.py

Then grokproject will create src/helloworld/helloworld.py along with
src/helloworld/helloworld_templates. Such a setup is currently
unsupported by grok. I think the view/templates grokker in particular
has its problems with it.

Apart from the fact that this bug persists in grok, I also think we
should get rid of asking the user for an alternative name of 'app.py'.
It should simply be app.py and basta. I've seen so many newbies just
entering anything here, even when I've told them over and over and
that they should simply hit enter.

Revision history for this message
Christian Theune (ctheune) wrote : Re: [Bug 80403] Re: Fix situation where a module name is identical to the package name

Am Montag, den 05.11.2007, 09:42 +0000 schrieb Philipp von
Weitershausen:
> Apart from the fact that this bug persists in grok, I also think we
> should get rid of asking the user for an alternative name of 'app.py'.
> It should simply be app.py and basta. I've seen so many newbies just
> entering anything here, even when I've told them over and over and
> that they should simply hit enter.

+1

--
gocept gmbh & co. kg - forsterstrasse 29 - 06112 halle (saale) - germany
www.gocept.com - <email address hidden> - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development

Revision history for this message
Martijn Faassen (faassen) wrote : Re: [Bug 80403] Re: Fix situation where a module name is identical to the package name

On 11/5/07, Christian Theune <email address hidden> wrote:
>
> Am Montag, den 05.11.2007, 09:42 +0000 schrieb Philipp von
> Weitershausen:
> > Apart from the fact that this bug persists in grok, I also think we
> > should get rid of asking the user for an alternative name of 'app.py'.
> > It should simply be app.py and basta. I've seen so many newbies just
> > entering anything here, even when I've told them over and over and
> > that they should simply hit enter.
>
> +1

+1. You can always add a commandline option to name it something else,
but not really necessary in my mind.

Revision history for this message
Uli Fouquet (uli-gnufix) wrote :

This issue still persists as Joachims complaint on grok-dev shows:

  http://permalink.gmane.org/gmane.comp.web.zope.grok.devel/4252

Even if the 'Enter module name' option vanishes from grokproject (I know it does), we still have the problem, that Grok incorrectly emits warnings (or even errors in current releases) on 'unassociated templates'.

So the problem reappears, when somebody creates a subpackage with a module named like the subpackage and views and templates in it. In fact it seems to me that we got an ambiguity problem here:

When a pkg 'foo' contains view classes (defined in __init__.py) and a module 'foo' and a template dir 'foo_templates', to which entitiy should the templates in foo_templates be associated? To the package or the same named module? Well, the answer for almost every case would be: to the module.

For templates this could be simply clarified in the template registry by not searching for templates of modules, that are packages. I've 'implemented' this (two lines of code plus tests) in the attached patch on the current grok trunk. The ambiguity would vanish at least for templates.

The 'drawback' would be, that one cannot register package-bound templates, which would be defined in __init__.py. This, however, would be bad style IMHO and I wouldn't care too much for this usecase. In fact I never tried to define views in __init__.py.

Revision history for this message
Uli Fouquet (uli-gnufix) wrote :

This is an improved version of the patch: less code, less typos.

If there are no objections, I will apply this patch on the trunk this weekend.

Revision history for this message
Philipp von Weitershausen (philikon) wrote :

On 5 Apr 2008, at 12:03 , Uli Fouquet wrote:
> This is an improved version of the patch: less code, less typos.
>
> If there are no objections, I will apply this patch on the trunk this
> weekend.

The patch looks good overall. I would just drop the comments about
"prior versions of Grok" and just make statements about the status-
quo. Just a minor nitpick, though. Thanks!

Revision history for this message
Uli Fouquet (uli-gnufix) wrote :

The problem is fixed now in trunk at least for identical module/package names and templates. Not sure about relative imports.

Changed in grok:
status: In Progress → Fix Committed
todd (todd-infrae)
Changed in grok:
assignee: nobody → janwijbrand
milestone: none → 1.0
Changed in grok:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.