forked from LMCache/LMCache
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
62 lines (51 loc) · 1.94 KB
/
Copy pathsetup.py
File metadata and controls
62 lines (51 loc) · 1.94 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
# SPDX-License-Identifier: Apache-2.0
"""LMCache setup script — policy-driven extension build.
Uses the strategy pattern so that each platform lives in its own file
under ``setup_extensions/build_profiles/``. Adding a new platform requires
zero changes to this file.
"""
# Standard
from pathlib import Path
import sys
ROOT_DIR = Path(__file__).parent
# Ensure the project root is importable when ``setup.py`` runs inside a
# PEP 517 build subprocess (where CWD is not added to ``sys.path``).
if str(ROOT_DIR) not in sys.path:
sys.path.insert(0, str(ROOT_DIR))
# Third Party
from setuptools import find_packages, setup # noqa: E402
# First Party
from setup_extensions import BuildPolicy, BuildProfile # noqa: E402
def _read_requirements(path: Path) -> list[str]:
if not path.exists():
return []
reqs: list[str] = []
for raw in path.read_text().splitlines():
line = raw.strip()
if line and not line.startswith("#"):
reqs.append(line)
return reqs
if __name__ == "__main__":
policy = BuildPolicy()
profile = policy.resolve_profile()
ext_modules, cmdclass, req_file = policy.collect_extensions(profile)
install_requires = _read_requirements(ROOT_DIR / "requirements" / "common.txt")
extras_require: dict[str, list[str]] = {}
if (
not BuildProfile.is_gpu_ext_disabled()
and req_file is not None
and profile is not None
):
install_requires += _read_requirements(ROOT_DIR / "requirements" / req_file)
for extra_name, extra_req_file in profile.extras_requirements().items():
extras_require[extra_name] = _read_requirements(
ROOT_DIR / "requirements" / extra_req_file
)
setup(
packages=find_packages(exclude=("csrc",)),
ext_modules=ext_modules,
cmdclass=cmdclass,
include_package_data=True,
install_requires=install_requires,
extras_require=extras_require,
)