From d04e4c8c1027310520576e1890061799a0f64f0b Mon Sep 17 00:00:00 2001 From: ?ric Araujo Date: Sat, 24 Sep 2011 01:06:28 +0200 Subject: Start a branch to provide Distutils2 for Python 3. This codebase is compatible with 3.1, 3.2 and 3.3. It was converted with 2to3 and a semi-automated diff/merge with packaging in 3.3 to fix some idioms. We?ve now come full circle from 2.x to 3.x to 2.x to 3.x again :) Starting from now, contributors can make patches for packaging (preferred, as the stdlib?s regrtest is very useful), distutils2 or distutils-python3, and we?ll make patches flow between versions. --- distutils2/command/config.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'distutils2/command/config.py') diff --git a/distutils2/command/config.py b/distutils2/command/config.py index e3af2e5..437cde9 100644 --- a/distutils2/command/config.py +++ b/distutils2/command/config.py @@ -67,17 +67,17 @@ class config(Command): def finalize_options(self): if self.include_dirs is None: self.include_dirs = self.distribution.include_dirs or [] - elif isinstance(self.include_dirs, basestring): + elif isinstance(self.include_dirs, str): self.include_dirs = self.include_dirs.split(os.pathsep) if self.libraries is None: self.libraries = [] - elif isinstance(self.libraries, basestring): + elif isinstance(self.libraries, str): self.libraries = [self.libraries] if self.library_dirs is None: self.library_dirs = [] - elif isinstance(self.library_dirs, basestring): + elif isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) def run(self): @@ -110,8 +110,7 @@ class config(Command): def _gen_temp_sourcefile(self, body, headers, lang): filename = "_configtest" + LANG_EXT[lang] - file = open(filename, "w") - try: + with open(filename, "w") as file: if headers: for header in headers: file.write("#include <%s>\n" % header) @@ -119,8 +118,6 @@ class config(Command): file.write(body) if body[-1] != "\n": file.write("\n") - finally: - file.close() return filename def _preprocess(self, body, headers, include_dirs, lang): @@ -206,11 +203,10 @@ class config(Command): self._check_compiler() src, out = self._preprocess(body, headers, include_dirs, lang) - if isinstance(pattern, basestring): + if isinstance(pattern, str): pattern = re.compile(pattern) - file = open(out) - try: + with open(out) as file: match = False while True: line = file.readline() @@ -219,8 +215,6 @@ class config(Command): if pattern.search(line): match = True break - finally: - file.close() self._clean() return match @@ -351,8 +345,5 @@ def dump_file(filename, head=None): logger.info(filename) else: logger.info(head) - file = open(filename) - try: + with open(filename) as file: logger.info(file.read()) - finally: - file.close() -- cgit v1.2.1