Tuesday, January 13, 2015

Moved the content of /dev/mixins to the docstrings in lino.core.model and lino.mixins.

Fixed #7. When a new user had been created through the web interface, it was not possible to change their password.

ValueError: Attempted relative import in non-package

Then I converted the content of /dev/ml/users to the lino.modlib.users API.

Since this is a tested document, I changed two lines in /tests/__init__.py. Basically I replaced:




This change caused a ValueError: Attempted relative import in non-package at the line:

from .mixins import UserProfiles

I’ve had this problem before, and this time I explored the reason for it.

It comes from atelier.doctest_utf8 where some code which I did not write (I copied it from Python 2.7’s doctest module) does a special handling if a file ends with .py. And a comment for this treatment says:

# It is a module -- insert its dir into sys.path and try to
# import it. If it is part of a package, that possibly
# won't work because of package imports.

And this comment is still there in the doctest module of Python 3.

And of course I am not the first to stumble over this problem. See Doctest and relative imports where Jason Scheirer advises:

I would get rid of the relative imports, many Python style guides strongly discourage them, most forbid them.

But even when I do this, the import fails because Django is special: you cannot import a models.py module if your DJANGO_SETTINGS_MODULE is not set. So I moved these tests to a separate new document /dev/users. A topic which anyway has serious lacks of documentation.