Skip to content

Commit

Permalink
Merge pull request #215 from pfmoore/config_fix
Browse files Browse the repository at this point in the history
Fix configuration handling for Windows and Python 3
  • Loading branch information
bitprophet committed Mar 10, 2015
2 parents 1bd901d + 5910c78 commit e85d397
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions invoke/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
import imp
import json
import os
import sys
from os.path import join, splitext, expanduser

from .vendor import six
Expand All @@ -10,9 +10,23 @@
else:
from .vendor import yaml2 as yaml

if sys.version_info[:2] >= (3, 3):
from importlib.machinery import SourceFileLoader
def load_source(name, path):
if not os.path.exists(path):
return {}
return vars(SourceFileLoader('mod', path).load_module())
else:
import imp
def load_source(name, path):
if not os.path.exists(path):
return {}
return vars(imp.load_source('mod', path))

from .env import Environment
from .exceptions import UnknownFileType
from .util import debug
from .platform import WINDOWS


class DataProxy(object):
Expand Down Expand Up @@ -241,8 +255,11 @@ def __init__(self, defaults=None, overrides=None, system_prefix=None,
self.collection = {}

#: Path prefix searched for the system config file.
self.system_prefix = ('/etc/invoke' if system_prefix is None
else system_prefix)
#: There is no default system prefix on Windows
if system_prefix is None:
self.system_prefix = (None if WINDOWS else '/etc/invoke')
else:
self.system_prefix = system_prefix
#: Path to loaded system config file, if any.
self.system_path = None
#: Whether the system config file has been loaded or not (or ``None``
Expand Down Expand Up @@ -505,7 +522,7 @@ def _load_json(self, path):

def _load_py(self, path):
data = {}
for key, value in six.iteritems(vars(imp.load_source('mod', path))):
for key, value in six.iteritems(load_source('mod', path)):
if key.startswith('__'):
continue
data[key] = value
Expand Down

0 comments on commit e85d397

Please sign in to comment.