-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
61 lines (52 loc) · 1.77 KB
/
setup.py
File metadata and controls
61 lines (52 loc) · 1.77 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
import os
import sys
import subprocess
import shutil
def run_command(command, sudo=False):
"""
Executes a shell command. Prepends sudo if required and available.
"""
if sudo and shutil.which("sudo"):
command = f"sudo {command}"
print(f"--> Executing: {command}")
return subprocess.run(command, shell=True)
def setup_environment():
"""
Sets up the Ruby environment, installs bundler, and gems.
"""
# Detect if we should use sudo (Unix-like systems only)
use_sudo = False
if os.name != 'nt':
try:
# Check if current user is root
use_sudo = os.getuid() != 0
except AttributeError:
pass
# 1. Install bundler
bundler_install = run_command("gem install bundler", sudo=use_sudo)
if bundler_install.returncode != 0:
print("Note: bundler installation command returned non-zero. Continuing...")
# 2. Configure local path and install gems
if subprocess.run("bundle config set --local path .vendor/bundle", shell=True).returncode == 0:
run_command("bundle install")
else:
print("Failed to set bundle config.")
sys.exit(1)
print("\nSetup successful!")
def start_jekyll_server():
"""
Start the Jekyll development server.
"""
try:
print("Starting Jekyll server (Ctrl+C to stop)...")
subprocess.run("bundle exec jekyll serve", shell=True, check=True)
except KeyboardInterrupt:
print("\nStopping Jekyll server...")
pass
except subprocess.CalledProcessError as e:
print(f"\nCommand failed: {e.cmd}\nExit code: {e.returncode}")
except Exception as e:
print(f"\nUnable to start the Jekyll server: {e}")
if __name__ == "__main__":
setup_environment()
start_jekyll_server()