Just had a little surprise -- feels like a bug to me but let's hear
from the experts.

Having read in the web2py book that models are executed in name-sort
order, I changed the names of my model files to have more explicit
ordering -- from db.py and appconfig.py to 100-db.py and 000-
appconfig.py.  Next run of my app had many errors.  Changed the names
back, all is well.  Tried 000appconfig.py and 100db.py, also fine.
The hyphen was the proximate cause of the problem.

Took a look at gluon source -- the root cause seems to be this:

   models = listdir(path, '^\w+\.py$',0,sort=False)


This re spec (using \w) only matches file names using a-z, A-Z, 0-9
plus _   ... no match on hyphen

Generalizing a bit.  It seems like compileapp.py uses inconsistent
specs with listdir().  compile_models and compile_controllers use '.+
\.py$', which will match any file name up to the '.py' part.
compile_views does something more complicated (I don't really
understand the re spec) but it includes \w .   run_models uses '^w+\.py
$', which is more restrictive than what compile_models uses.

The same could be true in other gluon modules -- I didn't look
further.  I'm using version 1.99.2

In summary, it seems like web2py doesn't have a consistent rule for
what file names are allowed in the compile & run subfolders (models,
controllers, views).  If true -- this could lead to subtle bugs and
hard-to-diagnose problems.  If true -- would it make sense to adopt
one consistent allowable-name convention for all web2py files, or be
explicit about the current rules and issue log warnings when a file in
a standard directory is being skipped over due to file name not
matching the convention?

Personally I kind of like the option to rename a file and have it not
execute -- kind of like commenting out a file rather than having to
move in & out of the standard folders.  If the current approach should
persist, then my personal practice will be to add a leading hyphen to
file names to "comment out".

Thanks all

Reply via email to