Skip to content

Commit

Permalink
Hijack requests for pyro* in config files
Browse files Browse the repository at this point in the history
  • Loading branch information
kannibalox committed Jan 18, 2022
1 parent 72a6896 commit b5a58c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pyrosimple/util/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from __future__ import with_statement
from __future__ import absolute_import

import re
import glob
import errno
import importlib

import io
import sys
import configparser as ConfigParser

from pyrosimple import config, error
from pyrosimple.util import os, pymagic


def validate(key, val):
""" Validate a configuration value.
"""
Expand Down Expand Up @@ -205,6 +204,9 @@ def _load_py(self, namespace, config_file):
"""
if config_file and os.path.isfile(config_file):
self.LOG.debug("Loading %r..." % (config_file,))
p = importlib.import_module('pyrosimple')
sys.modules['pyrocore'] = p
sys.modules['pyrobase'] = p
exec(compile(open(config_file).read(), config_file, 'exec'), # pylint: disable=exec-used
vars(config), namespace)
else:
Expand Down
4 changes: 4 additions & 0 deletions src/pyrosimple/util/pymagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def import_name(module_spec, name=None):
@return: Requested object.
@rtype: object
"""
# Hijack requests for pyrocore
if 'pyrocore' in module_spec or 'pyrobase' in module_spec:
module_spec = module_spec.replace('pyrocore', 'pyrosimple')
module_spec = module_spec.replace('pyrobase', 'pyrosimple')
# Load module
module_name = module_spec
if name is None:
Expand Down

0 comments on commit b5a58c9

Please sign in to comment.