summaryrefslogtreecommitdiff
path: root/distutils2/command/build_scripts.py
diff options
context:
space:
mode:
Diffstat (limited to 'distutils2/command/build_scripts.py')
-rw-r--r--distutils2/command/build_scripts.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py
index 300f692..e752ff1 100644
--- a/distutils2/command/build_scripts.py
+++ b/distutils2/command/build_scripts.py
@@ -2,17 +2,18 @@
import os
import re
+from tokenize import detect_encoding
from distutils2.command.cmd import Command
from distutils2.util import convert_path, newer
from distutils2 import logger
from distutils2.compat import Mixin2to3
-from distutils2.compat import detect_encoding, fsencode
+from distutils2.compat import fsencode
from distutils2._backport import sysconfig
# check if Python is called on the first line with this expression
-first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
+first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')
class build_scripts(Command, Mixin2to3):
@@ -94,7 +95,7 @@ class build_scripts(Command, Mixin2to3):
match = first_line_re.match(first_line)
if match:
adjust = True
- post_interp = match.group(1) or ''
+ post_interp = match.group(1) or b''
if adjust:
logger.info("copying and adjusting %s -> %s", script,
@@ -108,7 +109,7 @@ class build_scripts(Command, Mixin2to3):
"python%s%s" % (sysconfig.get_config_var("VERSION"),
sysconfig.get_config_var("EXE")))
executable = fsencode(executable)
- shebang = "#!" + executable + post_interp + "\n"
+ shebang = b"#!" + executable + post_interp + b"\n"
# Python parser starts to read a script using UTF-8 until
# it gets a #coding:xxx cookie. The shebang has to be the
# first line of a file, the #coding:xxx cookie cannot be
@@ -130,12 +131,9 @@ class build_scripts(Command, Mixin2to3):
"The shebang (%r) is not decodable "
"from the script encoding (%s)" % (
shebang, encoding))
- outf = open(outfile, "wb")
- try:
+ with open(outfile, "wb") as outf:
outf.write(shebang)
outf.writelines(f.readlines())
- finally:
- outf.close()
if f:
f.close()
else:
@@ -148,8 +146,8 @@ class build_scripts(Command, Mixin2to3):
if self.dry_run:
logger.info("changing mode of %s", file)
else:
- oldmode = os.stat(file).st_mode & 07777
- newmode = (oldmode | 0555) & 07777
+ oldmode = os.stat(file).st_mode & 0o7777
+ newmode = (oldmode | 0o555) & 0o7777
if newmode != oldmode:
logger.info("changing mode of %s from %o to %o",
file, oldmode, newmode)