-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
157 lines (134 loc) · 4.79 KB
/
setup.py
File metadata and controls
157 lines (134 loc) · 4.79 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
Setup script for MUXI Runtime.
This setup.py exists primarily to handle the post-install hook for downloading
spaCy models. All package metadata and dependencies are defined in pyproject.toml.
"""
from setuptools import setup, find_packages
from setuptools.command.install import install
from setuptools.command.develop import develop
from setuptools.command.egg_info import egg_info
import subprocess
import sys
import os
# For reading pyproject.toml
try:
import tomllib # Python 3.11+
except ImportError:
try:
import tomli as tomllib # Python 3.10 with tomli installed
except ImportError:
print("ERROR: tomli is required for Python < 3.11")
print("Install it with: pip install tomli")
sys.exit(1)
def download_spacy_model():
"""Download the spaCy English model."""
try:
print("Downloading spaCy English model (en_core_web_sm)...")
subprocess.check_call([sys.executable, "-m", "spacy", "download", "en_core_web_sm"])
print("✓ Successfully downloaded spaCy English model")
except subprocess.CalledProcessError as e:
print(f"⚠ Warning: Failed to download spaCy model: {e}")
print(" Please run manually: python -m spacy download en_core_web_sm")
except Exception as e:
print(f"⚠ Warning: Unexpected error downloading spaCy model: {e}")
print(" Please run manually: python -m spacy download en_core_web_sm")
class PostInstallCommand(install):
"""Post-installation for development install."""
def run(self):
install.run(self)
download_spacy_model()
class PostDevelopCommand(develop):
"""Post-installation for editable install."""
def run(self):
develop.run(self)
download_spacy_model()
# Skip CLI installation for development mode
class PostEggInfoCommand(egg_info):
"""Post-installation for egg info."""
def run(self):
egg_info.run(self)
# Don't download on egg_info as it's called frequently
# Read configuration from pyproject.toml - SINGLE SOURCE OF TRUTH
if not os.path.exists("pyproject.toml"):
print("ERROR: pyproject.toml not found")
print("This file is required for installation")
sys.exit(1)
try:
with open("pyproject.toml", "rb") as f:
pyproject = tomllib.load(f)
except Exception as e:
print(f"ERROR: Failed to parse pyproject.toml: {e}")
sys.exit(1)
# Extract configuration
project_config = pyproject.get("project", {})
if not project_config:
print("ERROR: No [project] section found in pyproject.toml")
sys.exit(1)
# Required fields
name = project_config.get("name")
if not name:
print("ERROR: 'name' is required in pyproject.toml")
sys.exit(1)
# Version from .version file (for CI/CD)
version_file = os.path.join("src", "muxi", "runtime", ".version")
try:
with open(version_file, "r") as f:
version = f.read().strip()
except FileNotFoundError:
print(f"ERROR: Version file not found: {version_file}")
sys.exit(1)
# Optional fields with defaults
description = project_config.get("description", "")
authors = project_config.get("authors", [])
author = authors[0]["name"] if authors else "MUXI Team"
author_email = authors[0]["email"] if authors else "dev@muxi.org"
install_requires = project_config.get("dependencies", [])
extras_require = project_config.get("optional-dependencies", {})
python_requires = project_config.get("requires-python", ">=3.10")
classifiers = project_config.get("classifiers", [])
urls = project_config.get("urls", {})
# Read long description from README
try:
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
except FileNotFoundError:
long_description = description
# Run setup with configuration from pyproject.toml
setup(
name=name,
version=version,
author=author,
author_email=author_email,
description=description,
long_description=long_description,
long_description_content_type="text/markdown",
url=urls.get("Homepage", "https://github.com/muxi-ai/runtime"),
project_urls=urls,
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={
"muxi.runtime": [
".version",
"**/*.md",
"**/*.yaml",
"**/*.yml",
"**/*.json",
"**/*.txt",
"extensions/loadable/**/*.so",
"extensions/loadable/**/*.dylib",
"extensions/loadable/**/*.dll",
]
},
include_package_data=True,
classifiers=classifiers,
python_requires=python_requires,
install_requires=install_requires,
extras_require=extras_require,
# CLI will be installed as Go binary in post-install
cmdclass={
"install": PostInstallCommand,
"develop": PostDevelopCommand,
"egg_info": PostEggInfoCommand,
},
zip_safe=False,
)