Attempt to better handle python(2|3) tempfile differences

main
Dan Buch 7 years ago
parent 1505b9f046
commit d83210ca77
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -68,6 +68,9 @@ import tempfile
import textwrap
_PY3 = sys.version_info.major == 3
class _FancyFormatter(argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter):
pass
@ -104,9 +107,7 @@ def main(sysargs=sys.argv[:]):
def _generate_flag_types(writefunc, output_go, input_json):
types = json.load(input_json)
tmp = tempfile.NamedTemporaryFile(
suffix='.go', mode='w', delete=False, encoding='utf-8'
)
tmp = _get_named_tmp_go()
writefunc(tmp, types)
tmp.close()
@ -119,6 +120,13 @@ def _generate_flag_types(writefunc, output_go, input_json):
os.remove(tmp.name)
def _get_named_tmp_go():
tmp_args = dict(suffix='.go', mode='w', delete=False)
if _PY3:
tmp_args['encoding'] = 'utf-8'
return tempfile.NamedTemporaryFile(**tmp_args)
def _set_typedef_defaults(typedef):
typedef.setdefault('doctail', '')
typedef.setdefault('context_type', typedef['type'])

@ -13,6 +13,7 @@ import tempfile
from subprocess import check_call, check_output
_PY3 = sys.version_info.major == 3
_WINDOWS = platform.system().lower() == 'windows'
_PACKAGE_NAME = os.environ.get(
'CLI_PACKAGE_NAME', 'github.com/urfave/cli'
@ -148,9 +149,11 @@ def _go_version():
def _combine_coverprofiles(coverprofiles):
combined = tempfile.NamedTemporaryFile(
suffix='.coverprofile', delete=False
)
tmp_args = dict(suffix='.coverprofile', delete=False)
if _PY3:
tmp_args['encoding'] = 'utf-8'
combined = tempfile.NamedTemporaryFile(**tmp_args)
combined.write(b'mode: set\n')
for coverprofile in coverprofiles:

Loading…
Cancel
Save