| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import sys, os, shutil |
| 7 |
|
| 8 |
from distutils.command.build_ext import build_ext as _build_ext |
| 9 |
|
| 10 |
|
| 11 |
def symlink_or_copy(src, dst): |
| 12 |
if hasattr(os, 'symlink'): |
| 13 |
try: |
| 14 |
os.symlink(src, dst) |
| 15 |
return |
| 16 |
except OSError: |
| 17 |
pass |
| 18 |
except NotImplementedError: |
| 19 |
pass |
| 20 |
|
| 21 |
shutil.copyfile(src, dst) |
| 22 |
|
| 23 |
|
| 24 |
class build_ext(_build_ext): |
| 25 |
def build_extension(self, ext): |
| 26 |
self.inplace = 0 |
| 27 |
_build_ext.build_extension(self, ext) |
| 28 |
filename = self.get_ext_filename(ext.name) |
| 29 |
build_path = os.path.abspath(os.path.join(self.build_lib, filename)) |
| 30 |
src_path = os.path.abspath(filename) |
| 31 |
if build_path != src_path: |
| 32 |
try: |
| 33 |
os.unlink(src_path) |
| 34 |
except OSError: |
| 35 |
pass |
| 36 |
|
| 37 |
if self.verbose: |
| 38 |
sys.stderr.write('Linking %s to %s\n' % (build_path, src_path)) |
| 39 |
|
| 40 |
symlink_or_copy(build_path, src_path) |