text
stringlengths
0
828
# push the path for the particular module if found in the env
if env_path:
self.pushPath(env_path)"
2010,"def refactor(module, name, repl):
""""""
Replaces the name in the module dictionary with the inputted replace \
value.
:param module | <str> || <module>
name | <str>
repl | <variant>
:return <bool>
""""""
name = nstr(name)
# import a module when refactoring based on a string
if isinstance(module, basestring):
try:
module = __import__(module)
except ImportError:
logger.exception('Could not import module: %s' % module)
return False
try:
glbls = module.__dict__
except AttributeError:
err = '%s cannot support refactoring.' % module.__name__
logger.exception(err)
return False
if name in glbls:
# refactor the value
glbls[name] = repl
return True
else:
err = '%s is not a member of %s.' % (name, module.__name__)
logger.warning(err)
return False"
2011,"def current():
""""""
Returns the current environment manager for the projex system.
:return <EnvManager>
""""""
if not EnvManager._current:
path = os.environ.get('PROJEX_ENVMGR_PATH')
module = os.environ.get('PROJEX_ENVMGR_MODULE')
clsname = os.environ.get('PROJEX_ENVMGR_CLASS')
cls = EnvManager
if module and clsname:
# check if the user specified an import path
if path:
logger.info('Adding env manager path: %s' % path)
sys.path.insert(0, path)
logger.info('Loading env manager: %s.%s' % (module, clsname))
try:
__import__(module)
mod = sys.modules[module]
cls = getattr(mod, clsname)
except ImportError:
logger.error('Could not import env manager %s', module)
except KeyError:
logger.error('Could not import env manager %s', module)
except AttributeError:
msg = '%s is not a valid class of %s' % (clsname, module)
logger.error(msg)
EnvManager._current = cls()
return EnvManager._current"
2012,"def fileImport(filepath, ignore=None):
""""""
Imports the module located at the given filepath.
:param filepath | <str>
ignore | [<str>, ..] || None
:return <module> || None
""""""
basepath, package = EnvManager.packageSplit(filepath)
if not (basepath and package):
return None
# make sure this is not part of the ignored package list
if ignore and package in ignore:
return None
basepath = os.path.normcase(basepath)
if basepath not in sys.path:
sys.path.insert(0, basepath)
logger.debug('Importing: %s' % package)