Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to rye.... with CI #6

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on: [push, pull_request]

jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rye_version: "0.32.0"
rye_home: "/opt/rye"
use_uv: "true"

steps:
- uses: actions/checkout@v3

- name: Check cache for Rye
uses: actions/cache@v4
id: get-cache
with:
key: "${{ matrix.rye_version }}-${{ matrix.use_uv }}"
path: "${{ matrix.rye_home }}"

- name: Add Rye to PATH
run: echo "${{ matrix.rye_home }}/shims" >> $GITHUB_PATH && echo "${{ matrix.rye_home }}/tools" >> $GITHUB_PATH

- name: Install Rye
uses: phi-friday/[email protected]
if: steps.get-cache.outputs.cache-hit != 'true'
id: install-rye
with:
rye_version: "${{ matrix.rye_version }}"
rye_home: "${{ matrix.rye_home }}"
use_uv: "${{ matrix.use_uv }}"

- name: Cache virtual environment
uses: actions/cache@v4
id: venv-cache
with:
key: venv-${{ runner.os }}-${{ hashFiles('requirements.lock') }}
path: ".venv"

- name: Get dependencies
run: rye sync

- name: Enter virtual env
run: . .venv/bin/activate

- name: Run Ruff formatter/linter
run: ./.venv/bin/ruff check && ./.venv/bin/ruff format --check

- name: Check types with MyPy
uses: sasanquaneuf/mypy-github-action@releases/v1
with:
checkName: "ci"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
**/.vscode
**/__pycache__
**/.DS_Store
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "gps"]
path = gps
url = ../gps/
[submodule "YOLO"]
path = YOLO
url = https://github.com/Sooner-Rover-Team/YOLO
[submodule "src/autonomous/gps"]
path = src/autonomous/gps
url = https://github.com/Sooner-Rover-Team/gps
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]
File renamed without changes.
28 changes: 28 additions & 0 deletions Notes/codebase_tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Codebase Tips

This codebase is a multi-generational. Here are some small tips to get started.

## Python

Let's discuss some weird Python semantics/syntax you'll see around here.

### Modules

Each file in `src` is a **module**. These are imported by typing `import module_name` in a file.

However, modules can also contain other modules. For example, the `libs` folder is technically a module, containing submodules like `Drive`, `Location`, etc.

To import a submodule that's in a folder, you'd usually type `from folder_name import submodule_name`. But! Some of the modules, like `examples`, aren't inside `src`.

That means you have to use the import dot syntax to use them.

- `.` represents the current directory (submodule).
- `..` represents the previous directory (module).

So, to get `src/libs/Location.py` from `examples/ar.py`, you'll have to:

- escape from the `examples` module with `..`
- enter the `src/libs` submodule with `src.libs`
- import the `Location` module

From these steps, you'll end up with: `from ..src.libs import Location`. It looks a bit weird, but it's consistent and keeps example/test code from our actual libraries.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Autonomous Code

This folder contains all of the code needed for the autonomous program to run. We tied for 2nd in the 2022 autonomous course with this code when one of our wheels wasn't moving!
This folder contains all of the code needed for the Autonomous program to run. We tied for 2nd in the 2022 autonomous course with this code when one of our wheels wasn't moving!

## Dependencies

Expand Down
1 change: 1 addition & 0 deletions YOLO
Submodule YOLO added at 453f31
15 changes: 8 additions & 7 deletions examples/ar.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from time import sleep

import os
from libs import ARTracker
from ..src.libs import ARTracker

tracker = ARTracker.ARTracker(['/dev/video1'], write=False, useYOLO = False) #ARTracker requires a list of camera files
tracker = ARTracker.ARTracker(
["/dev/video1"], write=False, useYOLO=False
) # ARTracker requires a list of camera files

while True:
tracker.findMarker(1)#, id2 = 1)
print('Distance (in cm): ', tracker.distanceToMarker)
print('Angle: ', tracker.angleToMarker)
sleep(.5)
tracker.findMarker(1) # , id2 = 1)
print("Distance (in cm): ", tracker.distanceToMarker)
print("Angle: ", tracker.angleToMarker)
sleep(0.5)
22 changes: 11 additions & 11 deletions examples/location.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from time import sleep
from libs import Location
from ..src.libs import Location

#os.chdir(os.path.dirname(os.path.abspath(__file__)))
if __name__ == '__main__':
l = Location.Location('10.0.0.222','55556')
print('starting gps')
l.start_GPS()
l.start_GPS_thread()
print('reading data')
# os.chdir(os.path.dirname(os.path.abspath(__file__)))
if __name__ == "__main__":
loc = Location.Location("10.0.0.222", "55556")
print("starting gps")
loc.start_GPS()
loc.start_GPS_thread()
print("reading data")
while True:
print(l.latitude)
print(l.longitude)
print(l.bearing)
print(loc.latitude)
print(loc.longitude)
print(loc.bearing)
print()
sleep(1)
27 changes: 12 additions & 15 deletions examples/map.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from nis import maps
import os
from random import randint, random
import threading
import sys

from ..src.RoverMap.server import MapServer
from ..src.libs import Location

from scipy import rand
os.chdir(os.path.dirname(os.path.abspath(__file__)))

import threading

import sys
sys.path.append('../../Mission Control/RoverMap/')
sys.path.append("../../Mission Control/RoverMap/")

from server import MapServer
from libs import Location

if __name__ == '__main__':

loc = Location.Location('10.0.0.222', '55556')
print('Starting GPS')
if __name__ == "__main__":
loc = Location.Location("10.0.0.222", "55556")
print("Starting GPS")
loc.start_GPS()
loc.start_GPS_thread()

Expand All @@ -28,14 +25,14 @@ def set_interval(func, sec):
def func_wrapper():
set_interval(func, sec)
func()

t = threading.Timer(sec, func_wrapper)
t.start()
return t

def update():
print("sending update...")
#mapServer.update_rover_coords([38.4375 + randint(0, 100) / 10000 , -110.8125])
# mapServer.update_rover_coords([38.4375 + randint(0, 100) / 10000 , -110.8125])
mapServer.update_rover_coords([loc.latitude, loc.longitude])

set_interval(update, 0.500)

set_interval(update, 0.500)
16 changes: 8 additions & 8 deletions examples/wheels.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#If someone knows a better way to write the next 5 lines, lmk
# If someone knows a better way to write the next 5 lines, lmk
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

import sys
sys.path.append('../')
from ..src.libs import UDPOut

os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.append("../")

from libs import UDPOut

HOST = '127.0.0.1'
HOST = "127.0.0.1"
# 127.0.0.1 is the 'loopback' address, or the address
# of your own computer

PORT = 2000
PORT = 2000
# this number is arbitrary as long as it is above 1024

UDPOut.sendWheelSpeeds(HOST, PORT, 255, 255, 255, 255, 255, 255)
# the six arguments represent each wheels speed (on a scale between 0 and 255, since it will be stored in a byte).
# the order of the wheels in the arguments is Front Left, Middle Left, Rear Left, Front Right, Middle Right, and Rear Right.
# the order of the wheels in the arguments is Front Left, Middle Left, Rear Left, Front Right, Middle Right, and Rear Right.
# sendWheelSpeeds(HOST, PORT, fl, ml, rl, rt, mr, rr)
65 changes: 0 additions & 65 deletions findFocalLength.py

This file was deleted.

1 change: 0 additions & 1 deletion gps
Submodule gps deleted from f505c0
Loading