-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
116 lines (101 loc) · 3.69 KB
/
setup.py
File metadata and controls
116 lines (101 loc) · 3.69 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
setup.py for docx_comment_parser Python extension.
Build & install:
pip install pybind11
pip install .
Or build in-place:
python setup.py build_ext --inplace
Supported toolchains:
Linux / macOS : GCC or Clang (uses -std=c++17, -lz)
Windows MSVC : Visual Studio 2019+ (uses /std:c++17)
Windows MinGW : MinGW-w64 via MSYS2 (uses -std=c++17, -lz)
"""
from setuptools import setup, Extension
import sys
import os
import subprocess
def _is_mingw() -> bool:
"""Return True when building with MinGW-w64 GCC under Windows."""
if sys.platform != "win32":
return False
try:
out = subprocess.check_output(
["gcc", "--version"], stderr=subprocess.DEVNULL
).decode()
return "mingw" in out.lower() or "MINGW" in out
except (FileNotFoundError, subprocess.CalledProcessError):
return False
# ─── Locate pybind11 headers ──────────────────────────────────────────────────
try:
import pybind11
pybind11_include = pybind11.get_include()
except ImportError:
raise RuntimeError("pybind11 not found. Install with: pip install pybind11")
# ─── Platform / toolchain flags ──────────────────────────────────────────────
IS_MINGW = _is_mingw()
IS_MSVC = sys.platform == "win32" and not IS_MINGW
if IS_MSVC:
# MSVC (cl.exe) — Visual Studio 2019 or later
extra_compile_args = [
"/std:c++17",
"/O2",
"/DNDEBUG",
"/EHsc", # enable C++ exception handling
"/DDOCX_BUILDING_DLL", # expand DOCX_API to __declspec(dllexport)
]
extra_link_args = [] # zlib linked via vcpkg / find_package
elif IS_MINGW:
# MinGW-w64 GCC on Windows (MSYS2 / standalone)
extra_compile_args = [
"-std=c++17",
"-O2",
"-DNDEBUG",
"-DDOCX_BUILDING_DLL", # expand DOCX_API to __declspec(dllexport)
"-Wall",
]
extra_link_args = [
"-lz", # zlib1.dll — ships with every MinGW installation
"-lws2_32", # Winsock — required by std::thread on MinGW
"-lmswsock",
]
else:
# Linux / macOS — GCC or Clang
extra_compile_args = [
"-std=c++17",
"-O3",
"-DNDEBUG",
"-fvisibility=hidden", # hide all symbols except those marked DOCX_API
]
extra_link_args = ["-lz"]
# ─── Source files ─────────────────────────────────────────────────────────────
sources = [
"python/python_bindings.cpp",
"src/docx_parser.cpp",
"src/batch_parser.cpp",
"src/zip_reader.cpp",
"src/xml_parser.cpp",
]
ext = Extension(
"docx_comment_parser",
sources=sources,
include_dirs=["include", "vendor", pybind11_include],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language="c++",
)
setup(
name="docx-comment-parser",
version="1.0.0",
author="nick-developer",
description="Fast C++ library for extracting comment metadata from .docx files",
long_description=open("README.md", encoding="utf-8").read() if os.path.exists("README.md") else "",
ext_modules=[ext],
python_requires=">=3.8",
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: C++",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
],
)