13
13
"""
14
14
# Build helper
15
15
from __future__ import print_function
16
- from builtins import str , bytes , open
17
-
18
16
import os
19
17
from os .path import join as pjoin
20
18
import sys
21
- from configparser import ConfigParser
22
-
23
19
from glob import glob
24
20
from functools import partial
21
+ from io import open
25
22
26
23
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
27
24
# update it when the contents of directories change.
46
43
47
44
PY3 = sys .version_info [0 ] >= 3
48
45
46
+ if PY3 :
47
+ string_types = (str , bytes )
48
+ else :
49
+ string_types = (basestring , str , unicode )
50
+
49
51
def get_comrec_build (pkg_dir , build_cmd = build_py ):
50
52
""" Return extended build command class for recording commit
51
53
@@ -84,15 +86,21 @@ def get_comrec_build(pkg_dir, build_cmd=build_py):
84
86
class MyBuildPy (build_cmd ):
85
87
''' Subclass to write commit data into installation tree '''
86
88
def run (self ):
87
- build_cmd .run (self )
88
89
import subprocess
90
+ try :
91
+ from configparser import ConfigParser
92
+ except ImportError :
93
+ from ConfigParser import ConfigParser
94
+
95
+ build_cmd .run (self )
96
+
89
97
proc = subprocess .Popen ('git rev-parse --short HEAD' ,
90
98
stdout = subprocess .PIPE ,
91
99
stderr = subprocess .PIPE ,
92
100
shell = True )
93
101
repo_commit , _ = proc .communicate ()
94
102
# Fix for python 3
95
- repo_commit = str (repo_commit )
103
+ repo_commit = '{}' . format (repo_commit )
96
104
# We write the installation commit even if it's empty
97
105
cfg_parser = ConfigParser ()
98
106
cfg_parser .read (pjoin (pkg_dir , 'COMMIT_INFO.txt' ))
@@ -112,7 +120,7 @@ def _add_append_key(in_dict, key, value):
112
120
# Append value to in_dict[key] list
113
121
if key not in in_dict :
114
122
in_dict [key ] = []
115
- elif isinstance (in_dict [key ], ( str , bytes ) ):
123
+ elif isinstance (in_dict [key ], string_types ):
116
124
in_dict [key ] = [in_dict [key ]]
117
125
in_dict [key ].append (value )
118
126
@@ -209,7 +217,7 @@ def version_getter(pkg_name):
209
217
msgs ['opt suffix' ])
210
218
return
211
219
# setuptools mode
212
- if optional_tf and not isinstance (optional , ( str , bytes ) ):
220
+ if optional_tf and not isinstance (optional , string_types ):
213
221
raise RuntimeError ('Not-False optional arg should be string' )
214
222
dependency = pkg_name
215
223
if version :
0 commit comments