diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2017-08-28 09:05:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 09:05:42 -0400 |
commit | 3af152a26ee2ef889b8d7ab4428c975ba0c8e85b (patch) | |
tree | 5a82c4f80df197622ce1d10f418f2c4424ede7b3 /setuptools/config.py | |
parent | fc59fe8ea080f7d469c6c388fa878c4ede3e6557 (diff) | |
download | python-setuptools-git-3af152a26ee2ef889b8d7ab4428c975ba0c8e85b.tar.gz |
Extract method for reading local file. Now return results directly instead of for/append loop.
Diffstat (limited to 'setuptools/config.py')
-rw-r--r-- | setuptools/config.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/setuptools/config.py b/setuptools/config.py index 23fc25ea..2b156269 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -252,7 +252,6 @@ class ConfigHandler(object): :rtype: str """ include_directive = 'file:' - file_contents = [] if not isinstance(value, string_types): return value @@ -262,22 +261,24 @@ class ConfigHandler(object): spec = value[len(include_directive):] filepaths = (os.path.abspath(path.strip()) for path in spec.split(',')) + return '\n'.join( + self._read_local_file(path) + for path in filepath + if os.path.isfile(path) + ) + + @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( + '`file:` directive can not access %s' % filepath) - current_directory = os.getcwd() - - for filepath in filepaths: - if not filepath.startswith(current_directory): - raise DistutilsOptionError( - '`file:` directive can not access %s' % filepath) - - if os.path.isfile(filepath): - with io.open(filepath, encoding='utf-8') as f: - file_contents.append(f.read()) - - if file_contents: - value = '\n'.join(file_contents) - - return value + with io.open(filepath, encoding='utf-8') as f: + return f.read() @classmethod def _parse_attr(cls, value): |