-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathsetup.py
More file actions
49 lines (38 loc) · 1.81 KB
/
Copy pathsetup.py
File metadata and controls
49 lines (38 loc) · 1.81 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
"""Conditional mypyc compilation for invoice2data.
Most project metadata lives in ``pyproject.toml``; this file exists only to
optionally compile the hot-path modules into C extensions with mypyc. When the
``INVOICE2DATA_COMPILE_MYPYC`` environment variable is ``"1"`` (set by the
cibuildwheel release job) the listed modules are compiled, producing accelerated
wheels. Otherwise a pure-Python package is built — so the default ``uv build``
and ``pip install`` from sdist stay pure Python.
"""
import os
from setuptools import setup
# ``mypycify`` is only available where mypy is installed, so import it lazily.
if os.environ.get("INVOICE2DATA_COMPILE_MYPYC") == "1":
from mypyc.build import mypycify
def get_ext_modules() -> list:
"""Return the mypyc extension modules to compile, or an empty list.
Returns:
list: ``mypycify(...)`` extensions when compilation is requested,
otherwise an empty list (pure-Python build).
"""
if os.environ.get("INVOICE2DATA_COMPILE_MYPYC") != "1":
print("Skipping mypyc compilation. Building pure Python package...")
return []
print("Compiling invoice2data hot paths with mypyc...")
# Leaf hot-path modules only. Intentionally NOT compiled:
# - __main__.py: Click sets attributes on the decorated function object,
# which fails on a compiled function.
# - invoice_template.py: its OrderedDict subclass + dynamic attributes
# don't compile cleanly under mypyc.
return mypycify(
[
"src/invoice2data/extract/utils.py",
"src/invoice2data/extract/_regex.py",
"src/invoice2data/extract/parsers/regex.py",
"src/invoice2data/extract/parsers/lines.py",
"src/invoice2data/extract/plugins/tables.py",
]
)
setup(ext_modules=get_ext_modules())