Skip to content

Commit bbbdd0c

Browse files
committed
Improve setup script
1 parent c5ea7ab commit bbbdd0c

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

setup.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import io
44
import os
55
import platform
6+
import logging
67

78
import sys
89
from setuptools import setup, find_packages, Extension
910

11+
12+
logging.basicConfig(level=logging.INFO)
13+
1014
with io.open("README.md", mode="rt", encoding="utf-8") as readme_file:
1115
readme = readme_file.read()
1216

@@ -15,6 +19,8 @@
1519
USE_CYTHON = False
1620
PLATFORM = "windows_nt" if platform.system() == "Windows" else "posix"
1721
INCLUDE_LEXBOR = bool(os.environ.get("USE_LEXBOR", True))
22+
INCLUDE_MODEST = bool(os.environ.get("USE_MODEST", True))
23+
1824
ARCH = platform.architecture()[0]
1925

2026
try:
@@ -33,6 +39,10 @@
3339
INCLUDE_LEXBOR = True
3440
sys.argv.remove("--lexbor")
3541

42+
if "--disable-modest" in sys.argv:
43+
INCLUDE_MODEST = False
44+
sys.argv.remove("--disable-modest")
45+
3646
if "--cython" in sys.argv:
3747
if HAS_CYTHON:
3848
USE_CYTHON = True
@@ -78,30 +88,40 @@ def find_modest_files(modest_path="modest/source"):
7888

7989

8090
def make_extensions():
91+
logging.info(f"USE_CYTHON: {USE_CYTHON}")
92+
logging.info(f"INCLUDE_LEXBOR: {INCLUDE_LEXBOR}")
93+
logging.info(f"INCLUDE_MODEST: {INCLUDE_MODEST}")
94+
logging.info(f"USE_STATIC: {USE_STATIC}")
95+
8196
files_to_compile_lxb = []
97+
files_to_compile = []
8298
extra_objects_lxb, extra_objects = [], []
8399

84100
if USE_CYTHON:
85-
files_to_compile = [
86-
"selectolax/parser.pyx",
87-
]
101+
if INCLUDE_MODEST:
102+
files_to_compile = [
103+
"selectolax/parser.pyx",
104+
]
88105
if INCLUDE_LEXBOR:
89106
files_to_compile_lxb = [
90107
"selectolax/lexbor.pyx",
91108
]
92109
else:
93-
files_to_compile = ["selectolax/parser.c"]
110+
if INCLUDE_MODEST:
111+
files_to_compile = ["selectolax/parser.c"]
94112
if INCLUDE_LEXBOR:
95113
files_to_compile_lxb = [
96114
"selectolax/lexbor.c",
97115
]
98116

99117
if USE_STATIC:
100-
extra_objects = ["modest/lib/libmodest_static.a"]
118+
if INCLUDE_MODEST:
119+
extra_objects = ["modest/lib/libmodest_static.a"]
101120
if INCLUDE_LEXBOR:
102121
extra_objects_lxb = ["lexbor/liblexbor_static.a"]
103122
else:
104-
files_to_compile.extend(find_modest_files("modest/source"))
123+
if INCLUDE_MODEST:
124+
files_to_compile.extend(find_modest_files("modest/source"))
105125
if INCLUDE_LEXBOR:
106126
files_to_compile_lxb.extend(find_modest_files("lexbor/source"))
107127

@@ -135,18 +155,21 @@ def make_extensions():
135155
]
136156
)
137157

138-
extensions = [
139-
Extension(
140-
"selectolax.parser",
141-
files_to_compile,
142-
language="c",
143-
include_dirs=[
144-
"modest/include/",
145-
],
146-
extra_objects=extra_objects,
147-
extra_compile_args=compile_arguments,
148-
),
149-
]
158+
extensions = []
159+
if INCLUDE_MODEST:
160+
extensions.append(
161+
Extension(
162+
"selectolax.parser",
163+
files_to_compile,
164+
language="c",
165+
include_dirs=[
166+
"modest/include/",
167+
],
168+
extra_objects=extra_objects,
169+
extra_compile_args=compile_arguments,
170+
)
171+
)
172+
150173
if INCLUDE_LEXBOR:
151174
extensions.append(
152175
Extension(

0 commit comments

Comments
 (0)