Skip to content

Commit

Permalink
RF: import each component using importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremygray committed Dec 5, 2015
1 parent 468442b commit 60a1c2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions psychopy/app/builder/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# Copyright (C) 2015 Jonathan Peirce
# Distributed under the terms of the GNU General Public License (GPL).

from __future__ import absolute_import

import os, glob, copy
import wx
from PIL import Image
from os.path import join, dirname, abspath
from importlib import import_module # helps python 2.7 -> 3.x migration

excludeComponents = ['BaseComponent', 'BaseVisualComponent', #these are templates, not for use
'EyetrackerComponent', #this one isn't ready yet
Expand Down Expand Up @@ -65,8 +68,12 @@ def getComponents(folder=None, fetchIcons=True):
if os.path.isdir(folder):
for file in glob.glob(os.path.join(folder, '*.py')):#must start with a letter
file=os.path.split(file)[1]
# module = imp.load_source(file[:-3], fullPath)#can't use imp - breaks py2app
exec('import %s as module' %(file[:-3]))
if file in ['__init__.py', '_base.py']:
continue
#module = imp.load_source(file[:-3], fullPath)#can't use imp - breaks py2app
#exec('from psychopy.app.builder.components import %s as module' %(file[:-3]))
module_abs_path = 'psychopy.app.builder.components.' + file[:-3]
module = import_module(module_abs_path)
if not hasattr(module,'categories'):
module.categories=['Custom']
for attrib in dir(module):
Expand Down
2 changes: 2 additions & 0 deletions psychopy/app/builder/components/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (C) 2015 Jonathan Peirce
# Distributed under the terms of the GNU General Public License (GPL).

from __future__ import absolute_import

from ..experiment import Param
from ..components import getInitVals
from psychopy.constants import FOREVER
Expand Down

0 comments on commit 60a1c2e

Please sign in to comment.