[core] Simplification: as truthfully stated by Maik at Pycon.DE sprint «lets try not to turn python into javascript».
This commit is contained in:
@ -150,25 +150,6 @@ def _override_runner(runner):
|
|||||||
bonobo.run = _run
|
bonobo.run = _run
|
||||||
|
|
||||||
|
|
||||||
def get_default_services(filename, services=None):
|
|
||||||
dirname = os.path.dirname(filename)
|
|
||||||
services_filename = os.path.join(dirname, DEFAULT_SERVICES_FILENAME)
|
|
||||||
if os.path.exists(services_filename):
|
|
||||||
with open(services_filename) as file:
|
|
||||||
code = compile(file.read(), services_filename, 'exec')
|
|
||||||
context = {
|
|
||||||
'__name__': '__services__',
|
|
||||||
'__file__': services_filename,
|
|
||||||
}
|
|
||||||
exec(code, context)
|
|
||||||
|
|
||||||
return {
|
|
||||||
**context[DEFAULT_SERVICES_ATTR](),
|
|
||||||
**(services or {}),
|
|
||||||
}
|
|
||||||
return services or {}
|
|
||||||
|
|
||||||
|
|
||||||
def set_env_var(e, override=False):
|
def set_env_var(e, override=False):
|
||||||
__escape_decoder = codecs.getdecoder('unicode_escape')
|
__escape_decoder = codecs.getdecoder('unicode_escape')
|
||||||
ename, evalue = e.split('=', 1)
|
ename, evalue = e.split('=', 1)
|
||||||
|
|||||||
@ -15,7 +15,6 @@ from bonobo.util.inspect import (
|
|||||||
istype,
|
istype,
|
||||||
)
|
)
|
||||||
from bonobo.util.objects import (get_name, get_attribute_or_create, ValueHolder)
|
from bonobo.util.objects import (get_name, get_attribute_or_create, ValueHolder)
|
||||||
from bonobo.util.python import require
|
|
||||||
|
|
||||||
# Bonobo's util API
|
# Bonobo's util API
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -35,5 +34,4 @@ __all__ = [
|
|||||||
'ismethod',
|
'ismethod',
|
||||||
'isoption',
|
'isoption',
|
||||||
'istype',
|
'istype',
|
||||||
'require',
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
import inspect
|
|
||||||
import os
|
|
||||||
import runpy
|
|
||||||
|
|
||||||
|
|
||||||
class _RequiredModule:
|
|
||||||
def __init__(self, dct):
|
|
||||||
self.__dict__ = dct
|
|
||||||
|
|
||||||
|
|
||||||
class _RequiredModulesRegistry(dict):
|
|
||||||
@property
|
|
||||||
def pathname(self):
|
|
||||||
return os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.stack()[2][0])))
|
|
||||||
|
|
||||||
def require(self, name):
|
|
||||||
if name not in self:
|
|
||||||
bits = name.split('.')
|
|
||||||
filename = os.path.join(self.pathname, *bits[:-1], bits[-1] + '.py')
|
|
||||||
self[name] = _RequiredModule(runpy.run_path(filename, run_name=name))
|
|
||||||
return self[name]
|
|
||||||
|
|
||||||
|
|
||||||
class WorkingDirectoryModulesRegistry(_RequiredModulesRegistry):
|
|
||||||
@property
|
|
||||||
def pathname(self):
|
|
||||||
return os.getcwd()
|
|
||||||
|
|
||||||
|
|
||||||
registry = _RequiredModulesRegistry()
|
|
||||||
require = registry.require
|
|
||||||
Reference in New Issue
Block a user