~moriyoshi/twisted-x11/display-parsing-fix

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Marien Zwart
  • Date: 2009-04-23 23:34:37 UTC
  • Revision ID: marienz@localhost-20090423233437-a7m7276r6u5dt27s
Build protocol files from setup.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
3
 
from distutils import core
 
3
import os
 
4
import os.path as osp
 
5
 
 
6
from distutils import core, cmd, dep_util, log
 
7
from distutils.command import sdist, build
 
8
 
 
9
 
 
10
# XXX this assumes the toplevel source dir is $PWD
 
11
 
 
12
class BuildProto(cmd.Command):
 
13
 
 
14
    user_options = [
 
15
        ('force', 'f', 'forcibly build everything (ignore file timestamps)'),
 
16
        ]
 
17
 
 
18
    boolean_options = ['force']
 
19
 
 
20
    srcdir = 'xcb-proto'
 
21
    destdir = osp.join('tx11', 'proto')
 
22
 
 
23
    def initialize_options(self):
 
24
        self.force = None
 
25
 
 
26
    def finalize_options(self):
 
27
        self.set_undefined_options('build', ('force', 'force'))
 
28
 
 
29
    def run(self):
 
30
        names = [fn for fn in os.listdir(self.srcdir)
 
31
                 if osp.splitext(fn)[1] == '.xml']
 
32
        sources = [osp.join(self.srcdir, fn) for fn in names]
 
33
        targets = [osp.join(self.destdir, osp.splitext(fn)[0] + '.py')
 
34
                   for fn in names]
 
35
        if not sources:
 
36
            log.info('skipping proto rebuild (no sources)')
 
37
            return
 
38
        if not self.force:
 
39
            stale_sources, stale_targets = dep_util.newer_pairwise(sources,
 
40
                                                                   targets)
 
41
            if not stale_sources:
 
42
                log.info('skipping proto rebuild (up-to-date)')
 
43
                return
 
44
            # Rebuild everything, not just changed files, because one xml
 
45
            # file can refer to struct definitions in another
 
46
            # (we would have to build a full dep graph).
 
47
            # The pairwise comparisons above are technically bogus but
 
48
            # should suffice in practice.
 
49
 
 
50
        # Do these here so all this works with prebuilt proto files and no
 
51
        # tpfkax/py_client from dist tarballs.
 
52
        import py_client
 
53
        from tpfkax import state
 
54
 
 
55
        cache = state.XMLCache()
 
56
        for source in sources:
 
57
            module = py_client.PyModule(source, self.destdir, cache)
 
58
            module.register()
 
59
            module.resolve()
 
60
            module.generate()
 
61
 
 
62
 
 
63
class MySDist(sdist.sdist):
 
64
 
 
65
    """sdist extended to run build_proto first."""
 
66
 
 
67
    sub_commands = [('build_proto', None)]
 
68
 
 
69
    def run(self):
 
70
        for cmd_name in self.get_sub_commands():
 
71
            self.run_command(cmd_name)
 
72
 
 
73
        sdist.sdist.run(self)
 
74
 
 
75
 
 
76
class MyBuild(build.build):
 
77
 
 
78
    """build extended to run build_proto first."""
 
79
 
 
80
    sub_commands = [('build_proto', None)] + build.build.sub_commands
4
81
 
5
82
 
6
83
core.setup(name='Twisted-X11',
9
86
           author='Marien Zwart',
10
87
           author_email='tx11@emzet.cjb.net',
11
88
           packages=['tx11', 'tx11.proto', 'tx11.test'],
 
89
           # Copied from distutils/dist.py, with build_proto added.
 
90
           common_usage='''\
 
91
Common commands: (see '--help-commands' for more)
 
92
 
 
93
  setup.py build_proto   will (re)build the protocol files in place
 
94
  setup.py build         will build the package underneath 'build/'
 
95
  setup.py install       will install the package
 
96
''',
 
97
           cmdclass=dict(build_proto=BuildProto,
 
98
                         sdist=MySDist,
 
99
                         build=MyBuild),
12
100
           )