Skip to content

Instantly share code, notes, and snippets.

from typing import TYPE_CHECKING, Optional
def import_or_install(package: str, submodule: Optional[str] = None):
try:
if submodule:
module = __import__(f"{package}.{submodule}", fromlist=[submodule])
else:
module = __import__(package)
return module
@datavudeja
datavudeja / self-create-venv.py
Created February 9, 2025 22:28 — forked from pepoluan/self-create-venv.py
Self-creating a virtualenv with required modules
import subprocess
import sys
import tempfile
from pathlib import Path
try:
### PERFORM IMPORTS OF NEEDED MODULE IN THIS try: BLOCK
from rich.traceback import install as rtb_install
rtb_install(show_locals=True)
@datavudeja
datavudeja / script.py
Created February 9, 2025 22:28 — forked from stan-dot/script.py
Python script to read out many repos in a github org
import os
from pprint import pprint
import subprocess
import sys
def check_python_version():
v = sys.version_info
if v < (3, 10):
print("This script requires Python 3.10 or higher.")
@datavudeja
datavudeja / capture.py
Created February 9, 2025 22:28 — forked from ssbarnea/capture.py
Script that captures both stdout and stderr in a way that works for subprocesses, while still being able to use rich own console to use original streams.
from rich.console import Console
from subprocess import run
import tempfile
import sys
from contextlib import redirect_stdout, redirect_stderr
# If we do not pass file=sys.stdout explicitly, rich output will also be
# captured by the context manager.
console = Console(file=sys.stdout)
console_err = Console(file=sys.stderr, stderr=True)
@datavudeja
datavudeja / reduce_faces.py
Created February 9, 2025 22:29 — forked from awesomebytes/reduce_faces.py
Executing meshlab from commandline reduce faces of a mesh iteratively
#!/usr/bin/env python
import sys
import os
import subprocess
# Script taken from doing the needed operation
# (Filters > Remeshing, Simplification and Reconstruction >
# Quadric Edge Collapse Decimation, with parameters:
# 0.9 percentage reduction (10%), 0.3 Quality threshold (70%)
@datavudeja
datavudeja / runner.py
Created February 9, 2025 22:30 — forked from canislupaster/runner.py
test case runner
import argparse
import os
import time
import re
import asyncio
from tempfile import TemporaryDirectory
from asyncio import subprocess
from rich import print
@datavudeja
datavudeja / check_env.py
Created February 9, 2025 22:30 — forked from kyleboddy/check_env.py
CUDA / ML check environment script using rich
#!/usr/bin/env python3
import subprocess
import importlib
import platform
import sys
import locale
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
@datavudeja
datavudeja / validate.py
Created February 9, 2025 22:30 — forked from SamTheisens/validate.py
Run local "make" tasks in parallel
import concurrent.futures
import os
import shutil
import subprocess
import time
from concurrent.futures import Future
from dataclasses import dataclass
# Textualize rich dependencies https://github.com/Textualize/rich
from rich.console import RenderableType, Console
@datavudeja
datavudeja / git-repos-status
Created February 9, 2025 22:31 — forked from justsh/git-repos-status
Find git repositories recursively and output tables showing if their remotes and whether they have uncommitted changes
#!/bin/sh
# Execute an underlying
set -eu
prog="$(basename "$0")"
has_command() { command -v 1>/dev/null 2>&1; }
self="$0"
target="$(printf '%s' "$self" | tr '-' '_').py"
@datavudeja
datavudeja / run_stats.py
Created February 9, 2025 22:31 — forked from paulgessinger/run_stats.py
Python script to run a process a number of times and report status
#!/usr/bin/env python3
# /// script
# dependencies = [
# "rich",
# "typer",
# ]
# ///
import rich