-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathsetup.py
185 lines (166 loc) · 5.4 KB
/
setup.py
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import shutil
import subprocess
import sys
from pathlib import Path
from setuptools import Command, find_packages, setup
class BuildFrontendCommand(Command):
description = "build frontend assets"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
self._build_frontend()
except Exception as e:
print(f"Error building frontend: {str(e)}", file=sys.stderr)
raise
def _build_frontend(self):
frontend_dir = Path(__file__).parent / "frontend"
if not frontend_dir.exists():
print(f"Frontend directory not found at {frontend_dir}", file=sys.stderr)
return
print("Building frontend assets...")
try:
# Obtain npm path
npm_path = shutil.which("npm")
if not npm_path:
raise Exception("npm is not installed or not found in PATH")
# Run npm install with error handling
result = subprocess.run(
[npm_path, "install"],
cwd=frontend_dir,
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
print(f"npm install failed: {result.stderr}", file=sys.stderr)
raise Exception("npm install failed")
# Run npm build with error handling
result = subprocess.run(
[npm_path, "run", "build"],
cwd=frontend_dir,
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
print(f"npm build failed: {result.stderr}", file=sys.stderr)
raise Exception("npm build failed")
# Copy the built assets
self._copy_assets(frontend_dir)
except subprocess.CalledProcessError as e:
print(f"Failed to build frontend: {str(e)}", file=sys.stderr)
raise
except Exception as e:
print(f"Unexpected error building frontend: {str(e)}", file=sys.stderr)
raise
def _copy_assets(self, frontend_dir):
dist_dir = frontend_dir / "dist"
if not dist_dir.exists():
raise Exception(f"Build directory not found at {dist_dir}")
package_static_dir = Path(__file__).parent / "preswald" / "static"
package_static_dir.mkdir(parents=True, exist_ok=True)
# Copy dist contents
print(f"Copying built assets to {package_static_dir}")
for item in dist_dir.iterdir():
dest = package_static_dir / item.name
if dest.exists():
if dest.is_dir():
shutil.rmtree(dest)
else:
dest.unlink()
if item.is_dir():
shutil.copytree(item, dest)
else:
shutil.copy2(item, dest)
# Copy public assets
public_dir = frontend_dir / "public"
if public_dir.exists():
print("Copying public assets...")
for item in public_dir.iterdir():
dest = package_static_dir / item.name
if not dest.exists():
if item.is_dir():
shutil.copytree(item, dest)
else:
shutil.copy2(item, dest)
# Define core dependencies needed for the package to run
CORE_DEPENDENCIES = [
"fastapi>=0.68.0,<1.0.0",
"uvicorn>=0.15.0,<1.0.0",
"websockets>=10.0,<11.0",
"python-multipart>=0.0.5,<0.1.0",
"httpx>=0.23.0,<1.0.0",
"Markdown>=3.4.0",
"pandas>=1.5",
"toml==0.10.2",
"SQLAlchemy==2.0.36",
"plotly==5.24.1",
"Jinja2==3.1.4",
"click==8.1.7",
"networkx>=3.0",
"Requests==2.32.3",
"setuptools==75.1.0",
"psycopg2-binary>=2.9.10",
"openai==1.59.7",
"duckdb>=1.1.3",
"tomli==2.0.1",
]
# Define additional dependencies for development
DEV_DEPENDENCIES = [
"pytest>=8.3",
"build",
"twine",
"ruff>=0.1.11",
"pre-commit>=3.5.0",
]
setup(
# Basic package metadata
name="preswald",
version="0.1.38",
author="Structured",
author_email="founders@structuredlabs.com",
description="A lightweight data workflow SDK.",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
url="https://github.com/StructuredLabs/preswald",
license="Apache License 2.0",
# Package configuration
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
# Package data and dependencies
include_package_data=True,
package_data={
"preswald": [
"static/*",
"static/assets/*",
"templates/*",
"tutorial/*",
"tutorial/data/*",
"tutorial/images/*"
],
},
python_requires=">=3.7",
# Dependencies
install_requires=CORE_DEPENDENCIES,
extras_require={
"dev": DEV_DEPENDENCIES,
},
# Command line interface registration
entry_points={
"console_scripts": [
"preswald=preswald.cli:cli",
],
},
# Custom commands
cmdclass={
"build_frontend": BuildFrontendCommand,
},
)