Skip to content

Commit

Permalink
more aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
dyldonahue committed Aug 31, 2024
1 parent 21065a0 commit 87ecc5b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 39 deletions.
26 changes: 0 additions & 26 deletions build.py

This file was deleted.

61 changes: 61 additions & 0 deletions miniterm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import subprocess
import platform
import sys

def list_usb_devices():
"""List available USB serial devices based on the operating system."""
os_name = platform.system()

if os_name == 'Windows':
# List COM ports on Windows
try:
result = subprocess.run(['wmic', 'path', 'Win32_SerialPort'], capture_output=True, text=True)
devices = []
for line in result.stdout.splitlines():
if 'DeviceID' in line:
devices.append(line.split()[-1])
return devices
except Exception as e:
print(f"Failed to list USB devices on Windows: {e}", file=sys.stderr)
sys.exit(1)

elif os_name == 'Linux' or os_name == 'Darwin': # Darwin is macOS
# List USB devices on Unix-like systems
try:
result = subprocess.run(['ls', '/dev/tty*'], capture_output=True, text=True)
devices = [device for device in result.stdout.splitlines() if 'ttyUSB' in device or 'ttyACM' in device]
return devices
except Exception as e:
print(f"Failed to list USB devices on {os_name}: {e}", file=sys.stderr)
sys.exit(1)

else:
print(f"Unsupported operating system: {os_name}", file=sys.stderr)
sys.exit(1)

def run_miniterm(device, baudrate=9600):
"""Run pyserial-miniterm with the specified device and baudrate."""
try:
subprocess.run(['pyserial-miniterm', device, '-b', str(baudrate)], check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to run pyserial-miniterm: {e}", file=sys.stderr)
sys.exit(1)

def main():
# Detect the operating system and find USB devices
devices = list_usb_devices()

if not devices:
print("No USB devices found.", file=sys.stderr)
sys.exit(1)

# Default to the first device if available
selected_device = devices[0]
print(f"Selected USB device: {selected_device}")

# Run pyserial-miniterm with the selected device
run_miniterm(selected_device)

if __name__ == '__main__':
main()
23 changes: 11 additions & 12 deletions ner_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ def create_venv(venv_path):
print(f"ERROR: Failed to create virtual environment: {e}", file=sys.stderr)
sys.exit(1)

def install_requirements(venv_python):
print("Installing requirements.txt...")
def run_setup(venv_python):
print("Running setup.py...")
try:
run_command([venv_python, '-m', 'pip', 'install', '-r', 'requirements.txt'])
except Exception as e:
print(f"Failed to install requirements: {e}", file=sys.stderr)
# Run the pip install -e . command
run_command([venv_python, '-m', 'pip', 'install', '-e', '.'])
except subprocess.CalledProcessError as e:
print(f"Failed to run pip install -e .: {e}", file=sys.stderr)
sys.exit(1)


def install_precommit(venv_python):
print("Installing pre-commit hook...")
try:
Expand Down Expand Up @@ -157,16 +159,13 @@ def main():
# Use the venv's Python
venv_python = os.path.join(venv_path, 'Scripts', 'python') if os_type == "Windows" else os.path.join(venv_path, 'bin', 'python')

# Step 4: Install all Python packages from requirements.txt

#install_cython_and_wheel(venv_python)
#install_pyyaml_no_build_isolation(venv_python)
install_requirements(venv_python)
# Step 4: run setup.py (installs requirements and entry points)
run_setup(venv_python)

# Step 5: Run pre-commit install
# Step 5: Run pre-commit install
install_precommit(venv_python)

answer = input("Would you like to install probe-rs? (do this manually if on a weird linux ditro!) (yes/no)")
answer = input("Would you like to install probe-rs? (do this manually if on a weird linux distro!) (yes/no)")
if 'y' in answer:
# Step 5: Install probe-rs
install_probe_rs()
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def parse_requirements(filename):
'console_scripts': [
'ner_setup=ner_setup:main', # Command 'ner_setup' runs 'main' function in ner_setup.py
'clang_restage=clang_restage:main',
'another_command=another_module:another_function', # Another command, different function
'mini_term=miniterm:main',

],
},

Expand Down

0 comments on commit 87ecc5b

Please sign in to comment.