~marienz/twisted-x11/trunk

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python

from glob import glob
import os.path as osp

from distutils import core, cmd, dep_util, log
from distutils.command import sdist, build


# XXX this assumes the toplevel source dir is $PWD

class BuildProto(cmd.Command):

    user_options = [
        ('force', 'f', 'forcibly build everything (ignore file timestamps)'),
        ]

    boolean_options = ['force']

    srcdir = 'xcb-proto'
    destdir = osp.join('tx11', 'proto')

    def initialize_options(self):
        self.force = None

    def finalize_options(self):
        self.set_undefined_options('build', ('force', 'force'))

    def run(self):
        sources = glob(osp.join(self.srcdir, '*.xml'))
        targets = [osp.join(self.destdir,
                            osp.splitext(osp.basename(fn))[0] + '.py')
                   for fn in sources]
        if not sources:
            log.info('skipping proto rebuild (no sources)')
            return
        if not self.force:
            stale_sources, stale_targets = dep_util.newer_pairwise(sources,
                                                                   targets)
            if not stale_sources:
                log.info('skipping proto rebuild (up-to-date)')
                return
            # Rebuild everything, not just changed files, because one xml
            # file can refer to struct definitions in another
            # (we would have to build a full dep graph).
            # The pairwise comparisons above are technically bogus but
            # should suffice in practice.

        # Do these here so all this works with prebuilt proto files and no
        # tpfkax/py_client from dist tarballs.
        import py_client
        from tpfkax import state

        cache = state.XMLCache()
        for source in sources:
            py_client.PyModule(source, self.destdir, cache).run()


class MySDist(sdist.sdist):

    """sdist extended to run build_proto first."""

    sub_commands = [('build_proto', None)]

    def run(self):
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

        sdist.sdist.run(self)


class MyBuild(build.build):

    """build extended to run build_proto first."""

    sub_commands = [('build_proto', None)] + build.build.sub_commands


core.setup(name='twisted-x11',
           version='0.1',
           description='Pure python implementation of the X11 protocol',
           author='Marien Zwart',
           author_email='tx11@emzet.cjb.net',
           packages=['tx11', 'tx11.proto', 'tx11.test'],
           url='http://mzz.mine.nu/twisted-x11',
           license='X11',
           # Copied from distutils/dist.py, with build_proto added.
           common_usage='''\
Common commands: (see '--help-commands' for more)

  setup.py build_proto   will (re)build the protocol files in place
  setup.py build         will build the package underneath 'build/'
  setup.py install       will install the package
''',
           cmdclass=dict(build_proto=BuildProto,
                         sdist=MySDist,
                         build=MyBuild),
           )