File: my_build_ext.py

package info (click to toggle)
pyfribidi 0.12.0%2Brepack-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 184 kB
  • sloc: python: 395; ansic: 108; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# this code has been taken from gevent's setup.py file. it provides a
# build_ext command that puts .so/.pyd files in-place (like "setup.py
# build_ext -i"). it uses symlinks if possible and will rebuild when
# changing the python version (unlike "setup.py build_ext -i")

import sys, os, shutil

from distutils.command.build_ext import build_ext as _build_ext


def symlink_or_copy(src, dst):
    if hasattr(os, 'symlink'):
        try:
            os.symlink(src, dst)
            return
        except OSError:  # symbolic link privilege not held??
            pass
        except NotImplementedError:  # running on XP/'CreateSymbolicLinkW not found'
            pass

    shutil.copyfile(src, dst)


class build_ext(_build_ext):
    def build_extension(self, ext):
        self.inplace = 0
        _build_ext.build_extension(self, ext)
        filename = self.get_ext_filename(ext.name)
        build_path = os.path.abspath(os.path.join(self.build_lib, filename))
        src_path = os.path.abspath(filename)
        if build_path != src_path:
            try:
                os.unlink(src_path)
            except OSError:
                pass

            if self.verbose:
                sys.stderr.write('Linking %s to %s\n' % (build_path, src_path))

            symlink_or_copy(build_path, src_path)