-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
78 lines (69 loc) · 2.5 KB
/
setup.py
File metadata and controls
78 lines (69 loc) · 2.5 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
from setuptools import setup, find_packages
from setuptools.command.install import install
from setuptools import Command
import subprocess
import shutil
import sys
import os
from path_generator import generate_app_routes
class PostInstallCommand(install):
"""Custom install command to build frontend using Bun."""
def run(self):
install.run(self)
# Ensure Bun availability
if not shutil.which("bun"):
print("Bun is not installed. Installing via npm..")
try:
subprocess.check_call(["npm", "install", "-g", "bun"])
except subprocess.CalledProcessError as e:
print(f"Failed to install Bun: {e}")
sys.exit(1)
# Ensure app route exists
if not os.path.exists("src/app/index.tsx"):
print("Missing src/app/index.tsx // Skipping bun build.")
return
# Run build command
try:
print("Running: bun build src/app/index.tsx --outfit=dist/bundle.js")
subprocess.check_call([
"bun", "build", "src/app/index.tsx", "--outfile=dist/bundle.js"
])
except subprocess.CalledProcessError as e:
print(f"Bun build failed: {e}")
sys.exit(1)
class GenerateRoutesCommand(Command):
"""Custom command: python setup.py generate_routes"""
description = 'Generate route folders and page.tsx files.'
user_options = [
('paths=', None, 'Comma-separated list of route paths'),
('overwrite', None, 'Overwrite existing files')
]
def initialize_options(self):
self.paths = None
self.overwrite = False
def finalize_options(self):
if isinstance(self.overwrite, str):
self.overwrite = self.overwrite.lower() in ['true', '1', 'yes']
def run(self):
if self.paths:
paths_list = [p.strip() for p in self.paths.split(',') if p.strip()]
else:
paths_list = None
print(f"🛠 Requesting route generation (overwrite={self.overwrite})...")
generate_app_routes(paths=paths_list, overwrite=self.overwrite)
setup(
name="thou",
version="0.1.0",
description="Packages you need",
packages=find_packages(),
include_package_data=True,
cmdclass={
'install': PostInstallCommand,
'generate_routes': GenerateRoutesCommand,
},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
python_requires=">=3.8",
)