|
7 | 7 | from distutils.command.build_scripts import build_scripts
|
8 | 8 | from distutils.command.install_lib import install_lib
|
9 | 9 | from distutils.sysconfig import get_config_var
|
| 10 | +from distutils.util import convert_path |
| 11 | +from distutils.dep_util import newer |
| 12 | +from distutils import log |
10 | 13 | from platform import architecture
|
11 | 14 | from subprocess import Popen, CalledProcessError, PIPE, check_call
|
12 | 15 | from glob import glob
|
13 |
| -import shutil |
| 16 | +import stat |
14 | 17 | import sys
|
15 | 18 | import os
|
16 | 19 |
|
@@ -274,6 +277,60 @@ def finalize_options(self):
|
274 | 277 | scripts.append(script)
|
275 | 278 | self.scripts = scripts
|
276 | 279 |
|
| 280 | + def copy_scripts(self): |
| 281 | + # Look for the npython script as it can't be copied by the base class' |
| 282 | + # copy_scripts as it attempts to determine the file encoding as if it |
| 283 | + # were a text file. |
| 284 | + npython = None |
| 285 | + for script in self.scripts: |
| 286 | + if os.path.basename(script) == _npython_exe: |
| 287 | + npython = script |
| 288 | + |
| 289 | + if npython is None: |
| 290 | + return build_scripts.copy_scripts(self) |
| 291 | + |
| 292 | + # Call the base class copy_scripts with anything other than npython |
| 293 | + scripts = self.scripts |
| 294 | + self.scripts = [x for x in scripts if x != npython] |
| 295 | + try: |
| 296 | + base_result = build_scripts.copy_scripts(self) |
| 297 | + finally: |
| 298 | + self.scripts = scripts |
| 299 | + |
| 300 | + # Copy npython |
| 301 | + outfiles = [] |
| 302 | + updated_files = [] |
| 303 | + |
| 304 | + script = convert_path(npython) |
| 305 | + outfile = os.path.join(self.build_dir, os.path.basename(script)) |
| 306 | + outfiles.append(outfile) |
| 307 | + |
| 308 | + if not self.force and not newer(script, outfile): |
| 309 | + log.debug("not copying %s (up-to-date)", script) |
| 310 | + else: |
| 311 | + updated_files.append(outfile) |
| 312 | + self.copy_file(script, outfile) |
| 313 | + |
| 314 | + if os.name == 'posix': |
| 315 | + for file in outfiles: |
| 316 | + if self.dry_run: |
| 317 | + log.info("changing mode of %s", file) |
| 318 | + else: |
| 319 | + oldmode = os.stat(file)[stat.ST_MODE] & 0o7777 |
| 320 | + newmode = (oldmode | 0o555) & 0o7777 |
| 321 | + if newmode != oldmode: |
| 322 | + log.info("changing mode of %s from %o to %o", |
| 323 | + file, oldmode, newmode) |
| 324 | + os.chmod(file, newmode) |
| 325 | + |
| 326 | + # Some versions of build_command.copy_scripts return (outfiles, updated_files), |
| 327 | + # older versions return None. |
| 328 | + if base_result is not None: |
| 329 | + base_outfiles, base_updated_files = base_result |
| 330 | + outfiles.extend(base_outfiles) |
| 331 | + updated_files.extend(base_updated_files) |
| 332 | + return outfiles, updated_files |
| 333 | + |
277 | 334 |
|
278 | 335 | def _check_output(*popenargs, **kwargs):
|
279 | 336 | """subprocess.check_output from python 2.7.
|
@@ -309,9 +366,9 @@ def _check_output(*popenargs, **kwargs):
|
309 | 366 | scripts=[_npython_exe],
|
310 | 367 | zip_safe=False,
|
311 | 368 | cmdclass={
|
312 |
| - "build_ext" : PythonNET_BuildExt, |
313 |
| - "build_scripts" : PythonNET_BuildScripts, |
314 |
| - "install_lib" : PythonNET_InstallLib |
| 369 | + "build_ext": PythonNET_BuildExt, |
| 370 | + "build_scripts": PythonNET_BuildScripts, |
| 371 | + "install_lib": PythonNET_InstallLib, |
315 | 372 | }
|
316 | 373 | )
|
317 | 374 |
|
0 commit comments