1313"""
1414# Build helper
1515from __future__ import print_function
16- from builtins import str , bytes , open
17-
1816import os
1917from os .path import join as pjoin
2018import sys
21- from configparser import ConfigParser
22-
2319from glob import glob
2420from functools import partial
21+ from io import open
2522
2623# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
2724# update it when the contents of directories change.
4643
4744PY3 = sys .version_info [0 ] >= 3
4845
46+ if PY3 :
47+ string_types = (str , bytes )
48+ else :
49+ string_types = (basestring , str , unicode )
50+
4951def get_comrec_build (pkg_dir , build_cmd = build_py ):
5052 """ Return extended build command class for recording commit
5153
@@ -84,15 +86,21 @@ def get_comrec_build(pkg_dir, build_cmd=build_py):
8486 class MyBuildPy (build_cmd ):
8587 ''' Subclass to write commit data into installation tree '''
8688 def run (self ):
87- build_cmd .run (self )
8889 import subprocess
90+ try :
91+ from configparser import ConfigParser
92+ except ImportError :
93+ from ConfigParser import ConfigParser
94+
95+ build_cmd .run (self )
96+
8997 proc = subprocess .Popen ('git rev-parse --short HEAD' ,
9098 stdout = subprocess .PIPE ,
9199 stderr = subprocess .PIPE ,
92100 shell = True )
93101 repo_commit , _ = proc .communicate ()
94102 # Fix for python 3
95- repo_commit = str (repo_commit )
103+ repo_commit = '{}' . format (repo_commit )
96104 # We write the installation commit even if it's empty
97105 cfg_parser = ConfigParser ()
98106 cfg_parser .read (pjoin (pkg_dir , 'COMMIT_INFO.txt' ))
@@ -112,7 +120,7 @@ def _add_append_key(in_dict, key, value):
112120 # Append value to in_dict[key] list
113121 if key not in in_dict :
114122 in_dict [key ] = []
115- elif isinstance (in_dict [key ], ( str , bytes ) ):
123+ elif isinstance (in_dict [key ], string_types ):
116124 in_dict [key ] = [in_dict [key ]]
117125 in_dict [key ].append (value )
118126
@@ -209,7 +217,7 @@ def version_getter(pkg_name):
209217 msgs ['opt suffix' ])
210218 return
211219 # setuptools mode
212- if optional_tf and not isinstance (optional , ( str , bytes ) ):
220+ if optional_tf and not isinstance (optional , string_types ):
213221 raise RuntimeError ('Not-False optional arg should be string' )
214222 dependency = pkg_name
215223 if version :
0 commit comments