Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configuration handling for Windows and Python 3 #215

Merged
merged 1 commit into from
Mar 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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