Commit 3af152a2 authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Extract method for reading local file. Now return results directly instead of for/append loop.

parent fc59fe8e
...@@ -252,7 +252,6 @@ class ConfigHandler(object): ...@@ -252,7 +252,6 @@ class ConfigHandler(object):
:rtype: str :rtype: str
""" """
include_directive = 'file:' include_directive = 'file:'
file_contents = []
if not isinstance(value, string_types): if not isinstance(value, string_types):
return value return value
...@@ -262,22 +261,24 @@ class ConfigHandler(object): ...@@ -262,22 +261,24 @@ class ConfigHandler(object):
spec = value[len(include_directive):] spec = value[len(include_directive):]
filepaths = (os.path.abspath(path.strip()) for path in spec.split(',')) filepaths = (os.path.abspath(path.strip()) for path in spec.split(','))
return '\n'.join(
current_directory = os.getcwd() self._read_local_file(path)
for path in filepath
for filepath in filepaths: if os.path.isfile(path)
if not filepath.startswith(current_directory): )
@staticmethod
def _read_local_file(filepath):
"""
Read contents of filepath. Raise error if the file
isn't in the current directory.
"""
if not filepath.startswith(os.getcwd()):
raise DistutilsOptionError( raise DistutilsOptionError(
'`file:` directive can not access %s' % filepath) '`file:` directive can not access %s' % filepath)
if os.path.isfile(filepath):
with io.open(filepath, encoding='utf-8') as f: with io.open(filepath, encoding='utf-8') as f:
file_contents.append(f.read()) return f.read()
if file_contents:
value = '\n'.join(file_contents)
return value
@classmethod @classmethod
def _parse_attr(cls, value): def _parse_attr(cls, value):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment