mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Make Cython Support Optional.
Allow the user to choose not to have the cython module searching and loading enabled. This helps with packages installed in "develop" mode where the ".pyx"'s are still present and will be tried to be compiled and loaded even though that package is fully working.
This commit is contained in:
parent
5b10ae52e1
commit
e8cac6a61f
4 changed files with 49 additions and 22 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
##### Minion module management #####
|
||||
##########################################
|
||||
# Disable specific modules, this will allow the admin to limit the level os
|
||||
# Disable specific modules, this will allow the admin to limit the level os
|
||||
# access the master has to the minion
|
||||
#disable_modules: [cmd,test]
|
||||
#disable_returners: []
|
||||
|
@ -35,6 +35,8 @@
|
|||
#returner_dirs: []
|
||||
#states_dirs: []
|
||||
#render_dirs: []
|
||||
# Enable Cython modules searching and loading. (Default: True)
|
||||
#cython_enable: true
|
||||
|
||||
##### State Management Settings #####
|
||||
###########################################
|
||||
|
|
|
@ -35,6 +35,7 @@ def minion_config(path):
|
|||
'log_level': 'WARNING',
|
||||
'out_level': 'ERROR',
|
||||
'test': False,
|
||||
'cython_enable': True,
|
||||
}
|
||||
|
||||
if os.path.isfile(path):
|
||||
|
@ -45,7 +46,7 @@ def minion_config(path):
|
|||
|
||||
opts['master_uri'] = 'tcp://' + opts['master'] + ':'\
|
||||
+ str(opts['master_port'])
|
||||
|
||||
|
||||
# Enableing open mode requires that the value be set to True, and nothing
|
||||
# else!
|
||||
if opts['open_mode']:
|
||||
|
@ -93,7 +94,7 @@ def master_config(path):
|
|||
opts.update(yaml.load(open(path, 'r')))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
opts['aes'] = salt.crypt.Crypticle.generate_key_string()
|
||||
|
||||
# Enableing open mode requires that the value be set to True, and nothing
|
||||
|
|
|
@ -10,10 +10,6 @@ import sys
|
|||
import imp
|
||||
import distutils.sysconfig
|
||||
|
||||
# Import cython
|
||||
import pyximport
|
||||
pyximport.install()
|
||||
|
||||
def minion_mods(opts):
|
||||
'''
|
||||
Returns the minion modules
|
||||
|
@ -126,14 +122,26 @@ class Loader(object):
|
|||
fn_, path, desc = imp.find_module(name, self.module_dirs)
|
||||
mod = imp.load_module(name, fn_, path, desc)
|
||||
except ImportError:
|
||||
# The module was not found, try to find a cython module
|
||||
for mod_dir in self.module_dirs:
|
||||
for fn_ in os.listdir(mod_dir):
|
||||
if name == fn_[:fn_.rindex('.')]:
|
||||
# Found it, load the mod and break the loop
|
||||
mod = pyximport.load_module(name, os.path.join(mod_dir, fn_))
|
||||
return getattr(mod, fun[fun.rindex('.') + 1:])(*arg)
|
||||
if self.opts['cython_enable'] is True:
|
||||
# The module was not found, try to find a cython module
|
||||
try:
|
||||
import pyximport
|
||||
pyximport.install()
|
||||
|
||||
for mod_dir in self.module_dirs:
|
||||
for fn_ in os.listdir(mod_dir):
|
||||
if name == fn_[:fn_.rindex('.')]:
|
||||
# Found it, load the mod and break the loop
|
||||
mod = pyximport.load_module(
|
||||
name, os.path.join(mod_dir, fn_)
|
||||
)
|
||||
return getattr(
|
||||
mod, fun[fun.rindex('.') + 1:])(*arg)
|
||||
except ImportError:
|
||||
self.opts['logger'].info(
|
||||
"Cython is enabled in options though it's not present "
|
||||
"in the system path. Skipping Cython modules."
|
||||
)
|
||||
return getattr(mod, fun[fun.rindex('.') + 1:])(*arg)
|
||||
|
||||
def gen_functions(self, pack=None):
|
||||
|
@ -143,6 +151,18 @@ class Loader(object):
|
|||
names = {}
|
||||
modules = []
|
||||
funcs = {}
|
||||
|
||||
cython_enabled = False
|
||||
if self.opts['cython_enable'] is True:
|
||||
try:
|
||||
import pyximport
|
||||
pyximport.install()
|
||||
cython_enabled = True
|
||||
except ImportError:
|
||||
self.opts['logger'].info(
|
||||
"Cython is enabled in options though it's not present in "
|
||||
"the system path. Skipping Cython modules."
|
||||
)
|
||||
for mod_dir in self.module_dirs:
|
||||
if not mod_dir.startswith('/'):
|
||||
continue
|
||||
|
@ -155,11 +175,13 @@ class Loader(object):
|
|||
or fn_.endswith('.pyc')\
|
||||
or fn_.endswith('.pyo')\
|
||||
or fn_.endswith('.so')\
|
||||
or fn_.endswith('.pyx'):
|
||||
or (cython_enabled and fn_.endswith('.pyx')):
|
||||
names[fn_[:fn_.rindex('.')]] = os.path.join(mod_dir, fn_)
|
||||
for name in names:
|
||||
try:
|
||||
if names[name].endswith('.pyx'):
|
||||
# If there's a name which ends in .pyx it means the above
|
||||
# cython_enabled is True. Continue...
|
||||
mod = pyximport.load_module(name, names[name], '/tmp')
|
||||
else:
|
||||
fn_, path, desc = imp.find_module(name, self.module_dirs)
|
||||
|
|
|
@ -23,13 +23,6 @@ import salt.modules
|
|||
import salt.returners
|
||||
import salt.loader
|
||||
|
||||
cython_enable = False
|
||||
try:
|
||||
import pyximport; pyximport.install()
|
||||
cython_enable = True
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# To set up a minion:
|
||||
# 1, Read in the configuration
|
||||
|
@ -49,6 +42,15 @@ class Minion(object):
|
|||
Pass in the options dict
|
||||
'''
|
||||
self.opts = opts
|
||||
if opts['cython_enable'] is True:
|
||||
try:
|
||||
import pyximport
|
||||
pyximport.install()
|
||||
except ImportError:
|
||||
self.opts['logger'].info(
|
||||
"Cython is enabled in options though it's not present in "
|
||||
"the system path. Skipping Cython modules."
|
||||
)
|
||||
self.mod_opts = self.__prep_mod_opts()
|
||||
self.functions, self.returners = self.__load_modules()
|
||||
self.authenticate()
|
||||
|
|
Loading…
Add table
Reference in a new issue