Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get Python code generation working again.

This patch refactors py_client into an importable library, that is called to
construct generated Python files from setup.py.

Also add exceptions to .gitignore for build products.
  • Loading branch information...
commit 5d368ad50d99e3caaf3772abd07007982cb39d63 1 parent ddfdd79
@cortesi cortesi authored
View
27 .gitignore
@@ -28,3 +28,30 @@ stamp-h1
*.pc
*.tar.bz2
*.tar.gz
+*.so
+*.swp
+*.pyc
+build
+xcb/bigreq.py
+xcb/composite.py
+xcb/damage.py
+xcb/dpms.py
+xcb/glx.py
+xcb/randr.py
+xcb/record.py
+xcb/render.py
+xcb/res.py
+xcb/screensaver.py
+xcb/shape.py
+xcb/shm.py
+xcb/sync.py
+xcb/xc_misc.py
+xcb/xevie.py
+xcb/xf86dri.py
+xcb/xfixes.py
+xcb/xinerama.py
+xcb/xprint.py
+xcb/xproto.py
+xcb/xtest.py
+xcb/xv.py
+xcb/xvmc.py
View
49 setup.py
@@ -0,0 +1,49 @@
+import shutil, os
+from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext as _build_ext
+from tools import py_client
+
+CFLAGS=["-Wall"]
+# We'll write code to detect this properly later
+XCB_PATH="/usr/local/share/xcb"
+
+xmlfiles = [
+ "bigreq", "composite", "damage", "dpms", "glx",
+ "randr", "record", "render", "res", "screensaver",
+ "shape", "shm", "sync", "xc_misc", "xevie",
+ "xf86dri", "xfixes", "xinerama", "xprint", "xproto",
+ "xtest", "xvmc", "xv"
+]
+extensions = [
+ "conn", "constant", "cookie", "error", "event",
+ "except", "ext", "extkey", "iter", "list", "module",
+ "protobj", "reply", "request", "response", "struct",
+ "union", "void"
+]
+ext_modules = []
+for i in extensions:
+ ext_modules.append(
+ Extension(
+ "xcb.%s"%i,
+ sources = ["xcb/%s.c"%i],
+ libraries = ["xcb"],
+ extra_compile_args=CFLAGS
+ )
+ )
+
+
+class build_ext(_build_ext):
+ def run(self):
+ for i in xmlfiles:
+ py_client.build(os.path.join(XCB_PATH, "%s.xml"%i))
+ return _build_ext.run(self)
+
+
+setup(
+ name = 'xpyb',
+ ext_modules = ext_modules,
+ packages = ["xcb"],
+ cmdclass = {
+ "build_ext": build_ext
+ }
+)
View
0  tools/__init__.py
No changes.
View
69 tools/py_client.py 100755 → 100644
@@ -4,6 +4,7 @@
import getopt
import sys
import re
+import __main__
# Jump to the bottom of this file for the main routine
@@ -25,13 +26,6 @@
'void': 'B',
'float': 'f',
'double' : 'd'}
-_pylines = []
-_pylevel = 0
-_ns = None
-
-_py_fmt_fmt = ''
-_py_fmt_size = 0
-_py_fmt_list = []
def _py(fmt, *args):
'''
@@ -102,7 +96,6 @@ def _py_flush_format():
def py_open(self):
'''
Exported function that handles module open.
- Opens the files and writes out the auto-generated comment, header file includes, etc.
'''
global _ns
_ns = self.namespace
@@ -156,7 +149,8 @@ def py_close(self):
Exported function that handles module close.
Writes out all the stored content lines, then closes the file.
'''
- pyfile = open('%s.py' % _ns.header, 'w')
+ print 'xcb/%s.py' % _ns.header
+ pyfile = open('xcb/%s.py' % _ns.header, 'w')
for list in _pylines:
for line in list:
pyfile.write(line)
@@ -571,30 +565,18 @@ def py_error(self, name):
# Main routine starts here
# Must create an "output" dictionary before any xcbgen imports.
-output = {'open' : py_open,
- 'close' : py_close,
- 'simple' : py_simple,
- 'enum' : py_enum,
- 'struct' : py_struct,
- 'union' : py_union,
- 'request' : py_request,
- 'event' : py_event,
- 'error' : py_error
- }
-
-# Boilerplate below this point
-
-# Check for the argument that specifies path to the xcbgen python package.
-try:
- opts, args = getopt.getopt(sys.argv[1:], 'p:')
-except getopt.GetoptError, err:
- print str(err)
- print 'Usage: py_client.py [-p path] file.xml'
- sys.exit(1)
+__main__.output = {
+ 'open' : py_open,
+ 'close' : py_close,
+ 'simple' : py_simple,
+ 'enum' : py_enum,
+ 'struct' : py_struct,
+ 'union' : py_union,
+ 'request' : py_request,
+ 'event' : py_event,
+ 'error' : py_error
+}
-for (opt, arg) in opts:
- if opt == '-p':
- sys.path.append(arg)
# Import the module class
try:
@@ -609,12 +591,21 @@ def py_error(self, name):
print ''
raise
-# Parse the xml header
-module = Module(args[0], output)
-# Build type-registry and resolve type dependencies
-module.register()
-module.resolve()
+def build(fname):
+ global _pylines, _pylevel, _ns, _py_fmt_fmt, _py_fmt_size, _py_fmt_list
+ _pylines = []
+ _pylevel = 0
+ _ns = None
+
+ _py_fmt_fmt = ''
+ _py_fmt_size = 0
+ _py_fmt_list = []
-# Output the code
-module.generate()
+ # Parse the xml header
+ module = Module(fname, __main__.output)
+ # Build type-registry and resolve type dependencies
+ module.register()
+ module.resolve()
+ # Output the code
+ module.generate()
Please sign in to comment.
Something went wrong with that request. Please try again.