winmd2py 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
winmd2py/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """winmd2py: generate portacom ctypes bindings from a .winmd file, in pure Python.
2
+
3
+ winmd2py.generate("Windows.Win32.winmd", "bindings", ["Windows.Win32.Graphics.Direct3D.Dxc"])
4
+ writes the bindings of that namespace, and of what it uses, as the package "bindings".
5
+ """
6
+
7
+ __version__ = "0.1.0"
8
+
9
+ from .emit import Generator, generate # noqa: E402 (emit reads __version__)
10
+
11
+ __all__ = ["generate", "Generator", "__version__"]
winmd2py/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
winmd2py/cli.py ADDED
@@ -0,0 +1,58 @@
1
+ """winmd2py FILE.winmd [-n NAMESPACE ...] [--ref OTHER.winmd ...] -o OUTDIR"""
2
+
3
+ import argparse
4
+ import sys
5
+ import time
6
+
7
+ from . import __version__
8
+ from .emit import Generator
9
+ from .model import WinMD
10
+
11
+
12
+ def main(argv=None):
13
+ parser = argparse.ArgumentParser(
14
+ prog="winmd2py",
15
+ description="Generate portacom ctypes bindings for classic COM interfaces from a .winmd file. "
16
+ "The bindings follow the Windows ABI the metadata describes; for a library built differently, "
17
+ "call portacom.use_abi() before importing them.",
18
+ )
19
+ parser.add_argument("winmd", help="the .winmd file (Win32 metadata format)")
20
+ parser.add_argument(
21
+ "-n",
22
+ "--namespace",
23
+ action="append",
24
+ dest="namespaces",
25
+ help="namespace to generate (repeatable; default: all namespaces in the file)",
26
+ )
27
+ parser.add_argument(
28
+ "--ref",
29
+ action="append",
30
+ default=[],
31
+ metavar="OTHER.winmd",
32
+ help="a .winmd whose types the file uses, such as Windows.Win32.winmd for "
33
+ "Microsoft.Direct3D.D3D12.winmd (repeatable); what is used from it is generated too",
34
+ )
35
+ parser.add_argument("-o", "--outdir", help="output package directory")
36
+ parser.add_argument("--list", action="store_true", help="list the namespaces in the file and exit")
37
+ parser.add_argument("-q", "--quiet", action="store_true", help="do not print what was left out or simplified")
38
+ parser.add_argument("--version", action="version", version=f"winmd2py {__version__}")
39
+ args = parser.parse_args(argv)
40
+ if not args.list and not args.outdir:
41
+ parser.error("-o/--outdir is required")
42
+
43
+ start = time.time()
44
+ try:
45
+ if args.list:
46
+ for ns in WinMD(args.winmd).namespaces():
47
+ print(ns)
48
+ return 0
49
+ generator = Generator(args.winmd, args.namespaces, refs=args.ref)
50
+ written = generator.generate(args.outdir)
51
+ except (OSError, ValueError) as error:
52
+ print(f"winmd2py: error: {error}", file=sys.stderr)
53
+ return 1
54
+ if not args.quiet:
55
+ for note in generator.notes:
56
+ print(f"winmd2py: {note}", file=sys.stderr)
57
+ print(f"winmd2py: wrote {len(written)} modules to {args.outdir} in {time.time() - start:.1f}s")
58
+ return 0