-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathsetup.py
More file actions
48 lines (38 loc) · 1.59 KB
/
setup.py
File metadata and controls
48 lines (38 loc) · 1.59 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
"""This file handles the mypyc compilation settings.
It is configured to conditionally compile the project's Python modules into C
extensions using mypyc, based on the presence of an environment variable.
This allows for producing both pure Python and compiled wheels.
"""
import os
from setuptools import setup
# The 'mypycify' function is not available in a stock 'setuptools' environment,
# so we only import it when we're actually going to use it. This allows the
# project to be installed in environments where 'mypy' is not present.
if os.environ.get("ARIEL_COMPILE_MYPYC") == "1":
from mypyc.build import mypycify
def get_ext_modules():
"""Conditionally builds mypyc C extensions.
If the `ARIEL_COMPILE_MYPYC` environment variable is set to "1",
this function will return a list of modules to be compiled by mypyc.
Otherwise, it returns an empty list, resulting in a pure Python build.
"""
if os.environ.get("ARIEL_COMPILE_MYPYC") == "1":
print("Compiling with mypyc...")
# Add the paths to the Python modules you want to compile here.
# For example:
# return mypycify([
# "src/ariel/__main__.py",
# "src/ariel/some_other_module.py",
# ])
return mypycify(
[
"src/ariel/__main__.py",
]
)
print("Skipping mypyc compilation. Building pure Python package...")
return []
setup(
# Most of the project metadata is configured in `pyproject.toml`.
# This `setup.py` is primarily used for the conditional mypyc compilation.
ext_modules=get_ext_modules(),
)