Import themes from PYTHONPATH

1 view
Skip to first unread message

Andi Albrecht

unread,
Dec 22, 2007, 3:44:23 AM12/22/07
to Apydia
Hi,

I've want to use apydia with a custom theme for a project without a
setup.py. So, it would be great, if apydia could load themes from
PYTHONPATH if there's not entry point providing the theme.

Here's a little patch that modifies the Theme.load method: If loading
a theme from entry points fails, it finally tries to load a theme from
PYTHONPATH.

Regards,

Andi



Index: theme.py
===================================================================
--- theme.py (revision 30)
+++ theme.py (working copy)
@@ -161,6 +161,11 @@
except DistributionNotFound, msg:
warnings.warn("DistributionNotFound: %s" % msg)
if not module:
+ try:
+ module = __import__(name)
+ except ImportError:
+ pass
+ if not module:
raise ThemeNotFoundError, "No such theme \"%s\" can be
found." % name
else:
cls.themes[name] = Theme(name, module)

Daniel Haus

unread,
Dec 23, 2007, 6:11:50 AM12/23/07
to apy...@googlegroups.com
Thanks Andi, looks good. I applied your patch in r31.

--
Daniel Haus
http://ematia.de

Andi Albrecht

unread,
Dec 28, 2007, 3:27:43 AM12/28/07
to Apydia
Hi Daniel,

thanks for applying the patch, but it needs some correction (rev. 31):
If a theme module is loaded from PYTHONPATH (line 165) it will not be
initialized as a Theme instance, because the logic never reaches lines
171-172. Propably it's ok just to remove the "else" part in line 170 -
all exceptions should be caught at this point.

Andi

Daniel Haus

unread,
Dec 28, 2007, 3:37:55 AM12/28/07
to apy...@googlegroups.com
Ooops, now (hopefully) fixed in r33. Thank you, Andi.

--
Daniel Haus
http://ematia.de

Reply all
Reply to author
Forward
0 new messages