Skip to content
Snippets Groups Projects
Commit c140c766 authored by Travis Seymour's avatar Travis Seymour
Browse files

new system

parent 8c5061a7
No related branches found
No related tags found
No related merge requests found
# uv-meta: {"requires": ["rich"]}
import sys
import subprocess
import platform
from pathlib import Path
from rich.console import Console
from rich import print
console = Console()
def run_command(command):
"""Run a command and return the output, or None if it fails."""
try:
result = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)
return result.stdout
except subprocess.CalledProcessError as e:
console.print(f"[red]Error running command: {' '.join(command)}[/red]")
console.print(e.stderr)
return None
def ensure_git_installed():
"""Check if git is installed; if not, alert the user and quit."""
if not shutil.which("git"):
console.print("[red]Git is not installed![/red]")
console.print(
"Please install git from [blue]https://git-scm.com/downloads[/blue] before trying again."
)
sys.exit(1)
def get_python_3_10_path():
"""Get the path to Python 3.10 by checking the current Python interpreter."""
python_path = Path(sys.executable)
if python_path.exists() and python_path.name.startswith("python3.10"):
return str(python_path)
console.print(
"[red]EPICPy requires Python 3.10 on Linux and MacOS, but that version of Python could not be located on this system. You can install Python 3.10 by running this command: uv python install 3.10[/red]"
)
sys.exit(1)
def get_python_3_9_path():
"""Get the path to Python 3.9 by checking for it explicitly."""
result = run_command(
["where" if platform.system() == "Windows" else "which", "python3.9"]
)
if result:
python_path = Path(result.strip())
if python_path.exists():
return str(python_path)
console.print(
"[red]EPICPy requires Python 3. on Windows, but that version of Python could not be located on this system. You can install Python 3.9 by running this command: uv python install 3.9[/red]"
)
sys.exit(1)
def main():
ensure_git_installed()
# Determine the appropriate Python version
if platform.system().lower() == "windows":
python_path = get_python_3_9_path()
else:
python_path = get_python_3_10_path()
# Step 1: Check if EPICpy is installed and uninstall it if necessary
uv_tool_list = run_command(["uv", "tool", "list"])
if uv_tool_list and "EPICpy" in uv_tool_list:
console.print("[yellow]EPICpy is already installed. Uninstalling...[/yellow]")
run_command(["uv", "tool", "uninstall", "EPICpy"])
# Step 2: Install EPICpy using the determined Python path
console.print(f"[cyan]Installing EPICpy with Python at {python_path}...[/cyan]")
install_output = run_command(
[
"uv",
"tool",
"install",
"git+https://www.github.com/travisseymour/EPICpy.git",
"--python",
python_path,
]
)
if install_output and "Installed 1 executable: EPICpy" in install_output:
console.print(
"[green]EPICpy installed successfully! You can run it from the terminal like this: EPICpy[/green]"
)
else:
console.print(
"[red]Failed to install EPICpy. Please check the error above and try again.[/red]"
)
sys.exit(1)
# Step 3: Check if epiccoder is installed and uninstall it if necessary
uv_tool_list = run_command(["uv", "tool", "list"])
if uv_tool_list and "epiccoder" in uv_tool_list:
console.print(
"[yellow]epiccoder is already installed. Uninstalling...[/yellow]"
)
run_command(["uv", "tool", "uninstall", "epiccoder"])
# Step 4: Install epiccoder
console.print("[cyan]Installing epiccoder...[/cyan]")
epiccoder_output = run_command(
[
"uv",
"tool",
"install",
"git+https://www.github.com/travisseymour/epiccoder.git",
]
)
if epiccoder_output and "Installed 1 executable: epiccoder" in epiccoder_output:
console.print(
"[green]epiccoder installed successfully! You can run it from the terminal like this: epiccoder[/green]"
)
else:
console.print(
"[red]Failed to install epiccoder. Please check the error above and try again.[/red]"
)
sys.exit(1)
if __name__ == "__main__":
main()
# uv-meta: {}
import sys
import subprocess
import platform
from pathlib import Path
import shutil
"""
To run this script:
1. If you don't have git installed, install it from here: https://git-scm.com/downloads
2. If you don't have uv installed, install it from here: https://docs.astral.sh/uv/getting-started/installation/
3. Run this command:
uv run tool_install.py
"""
def run_command(command):
"""Run a command and return the output, or None if it fails."""
try:
result = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Error running command: {' '.join(command)}", file=sys.stderr)
print(e.stderr, file=sys.stderr)
return None
def ensure_git_installed():
"""Check if git is installed; if not, alert the user and quit."""
if not shutil.which("git"):
print("Git is not installed!", file=sys.stderr)
print(
"Please install git from https://git-scm.com/downloads before trying again.",
file=sys.stderr,
)
sys.exit(1)
def get_python_3_10_path():
"""Get the path to Python 3.10 by checking the current Python interpreter."""
python_path = Path(sys.executable)
if python_path.exists() and python_path.name.startswith("python3.10"):
return str(python_path)
print(
"EPICPy requires Python 3.10 on Linux and MacOS, but that version of Python could not be located on this system. "
"You can install Python 3.10 by running this command: uv python install 3.10",
file=sys.stderr,
)
sys.exit(1)
def get_python_3_9_path():
"""Get the path to Python 3.9 by checking for it explicitly."""
result = run_command(
["where" if platform.system() == "Windows" else "which", "python3.9"]
)
if result:
python_path = Path(result.strip())
if python_path.exists():
return str(python_path)
print(
"EPICPy requires Python 3.9 on Windows, but that version of Python could not be located on this system. "
"You can install Python 3.9 by running this command: uv python install 3.9",
file=sys.stderr,
)
sys.exit(1)
def is_tool_installed(tool_name):
"""Check if a tool is listed in the output of 'uv tool list'."""
uv_tool_list = run_command(["uv", "tool", "list"])
if uv_tool_list and tool_name in uv_tool_list:
return True
return False
def main():
ensure_git_installed()
# Determine the appropriate Python version
if platform.system().lower() == "windows":
python_path = get_python_3_9_path()
else:
python_path = get_python_3_10_path()
# Step 1: Uninstall EPICpy if it is already installed
if is_tool_installed("EPICpy"):
print("EPICpy is already installed. Uninstalling...")
run_command(["uv", "tool", "uninstall", "EPICpy"])
# Step 2: Install EPICpy using the determined Python path
print(f"Installing EPICpy with Python at {python_path}...")
run_command(
[
"uv",
"tool",
"install",
"git+https://www.github.com/travisseymour/EPICpy.git",
"--python",
python_path,
]
)
# Verify EPICpy installation
if is_tool_installed("EPICpy"):
print("EPICpy installed successfully! You can run it from the terminal like this: EPICpy")
else:
print("Failed to install EPICpy. Please check the error above and try again.", file=sys.stderr)
sys.exit(1)
# Step 3: Uninstall epiccoder if it is already installed
if is_tool_installed("epiccoder"):
print("epiccoder is already installed. Uninstalling...")
run_command(["uv", "tool", "uninstall", "epiccoder"])
# Step 4: Install epiccoder
print("Installing epiccoder...")
run_command(
[
"uv",
"tool",
"install",
"git+https://www.github.com/travisseymour/epiccoder.git",
]
)
# Verify epiccoder installation
if is_tool_installed("epiccoder"):
print("epiccoder installed successfully! You can run it from the terminal like this: epiccoder")
else:
print("Failed to install epiccoder. Please check the error above and try again.", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
# on Windows, you have to use Python 3.9
uv tool install git+https://github.com/travisseymour/EPICpy
uv tool install git+https://github.com/travisseymour/epiccoder
# on MacOS and Linux, you have to use Python 3.10
uv tool install git+https://github.com/travisseymour/EPICpy
uv tool install git+https://github.com/travisseymour/epiccoder
uv tool upgrade EPICpy epiccoder
uv tool upgrade EPICpy epiccoder
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment