Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / command / install_lib.py @ 1a305335

History | View | Annotate | Download (2.43 KB)

1
from distutils.command.install_lib import install_lib as _install_lib
2
import os
3

    
4
class install_lib(_install_lib):
5
    """Don't add compiled flags to filenames of non-Python files"""
6

    
7
    def _bytecode_filenames (self, py_filenames):
8
        bytecode_files = []
9
        for py_file in py_filenames:
10
            if not py_file.endswith('.py'):
11
                continue
12
            if self.compile:
13
                bytecode_files.append(py_file + "c")
14
            if self.optimize > 0:
15
                bytecode_files.append(py_file + "o")
16

    
17
        return bytecode_files
18

    
19
    def run(self):
20
        self.build()
21
        outfiles = self.install()
22
        if outfiles is not None:
23
            # always compile, in case we have any extension stubs to deal with
24
            self.byte_compile(outfiles)
25

    
26
    def get_exclusions(self):
27
        exclude = {}
28
        nsp = self.distribution.namespace_packages
29

    
30
        if (nsp and self.get_finalized_command('install')
31
               .single_version_externally_managed
32
        ):
33
            for pkg in nsp:
34
                parts = pkg.split('.')
35
                while parts:
36
                    pkgdir = os.path.join(self.install_dir, *parts)
37
                    for f in '__init__.py', '__init__.pyc', '__init__.pyo':
38
                        exclude[os.path.join(pkgdir,f)] = 1
39
                    parts.pop()
40
        return exclude
41

    
42
    def copy_tree(
43
        self, infile, outfile,
44
        preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1
45
    ):
46
        assert preserve_mode and preserve_times and not preserve_symlinks
47
        exclude = self.get_exclusions()
48

    
49
        if not exclude:
50
            return _install_lib.copy_tree(self, infile, outfile)
51

    
52
        # Exclude namespace package __init__.py* files from the output
53

    
54
        from setuptools.archive_util import unpack_directory
55
        from distutils import log
56

    
57
        outfiles = []
58

    
59
        def pf(src, dst):
60
            if dst in exclude:
61
                log.warn("Skipping installation of %s (namespace package)",dst)
62
                return False
63

    
64
            log.info("copying %s -> %s", src, os.path.dirname(dst))
65
            outfiles.append(dst)
66
            return dst
67

    
68
        unpack_directory(infile, outfile, pf)
69
        return outfiles
70

    
71
    def get_outputs(self):
72
        outputs = _install_lib.get_outputs(self)
73
        exclude = self.get_exclusions()
74
        if exclude:
75
            return [f for f in outputs if f not in exclude]
76
        return outputs
77

    
78

    
79

    
80

    
81

    
82