Last active
April 17, 2025 08:14
-
-
Save nhamilakis/2725ba39735016d146f4443ea8a1c218 to your computer and use it in GitHub Desktop.
Python script made standalone slurm job using UV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S uv run --script | |
# /// script | |
# dependencies = ["rich", "ipython", "httpx", "polars-lts-cpu"] | |
# /// | |
# fmt: off | |
#SBATCH --partition=cpu | |
#SBATCH --cpus-per-task=1 | |
#SBATCH --mem=1G | |
#SBATCH --job-name=env-test | |
#SBATCH --time=00:10:00 | |
#SBATCH --export=ALL | |
#SBATCH --output uv-test-%J.log | |
# fmt: on | |
import sys | |
import platform | |
import httpx | |
import polars as pl | |
import IPython | |
from rich.console import Console | |
from rich.table import Table | |
print(f"Coucou from {platform.node()}, using {sys.executable}") | |
r = httpx.get('https://api.github.com/events') | |
df = pl.DataFrame(r.json()) | |
if sys.stdout.isatty(): | |
# You're running in a real terminal | |
# Interactivly explore the data | |
IPython.embed() | |
else: | |
# You're being piped or redirected, just print | |
console = Console() | |
table = Table(show_header=True, header_style="bold") | |
# Add columns | |
for col in df.columns: | |
table.add_column(col) | |
# Add rows | |
for row in df.rows(): | |
table.add_row(*[str(cell) for cell in row]) | |
# Print the table | |
console.print(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment