Skip to content

Commit

Permalink
Update Makefile and Readme with new development experience (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction authored Jan 10, 2025
1 parent bf37905 commit 8feda29
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
59 changes: 41 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
.PHONY: all
all: download-libraries help
all: venv download-libraries pre-commit-install help

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

ACTIVATE_VENV := . venv/bin/activate;
BOARD_MOUNT_POINT ?= /Volumes/PYSQUARED

venv:
@echo "Creating virtual environment..."
@python3 -m venv venv
@$(ACTIVATE_VENV) pip install --upgrade pip --quiet
@$(ACTIVATE_VENV) pip install --requirement requirements.txt --quiet

.PHONY: download-libraries
download-libraries: venv ## Download the required libraries
@echo "Downloading libraries..."
@$(ACTIVATE_VENV) pip install --requirement lib/requirements.txt --target lib --no-deps --upgrade --quiet
@rm -rf lib/*.dist-info

.PHONY: pre-commit-install
pre-commit-install: venv
@echo "Installing pre-commit hooks..."
@$(ACTIVATE_VENV) pre-commit install > /dev/null

.PHONY: fmt
fmt: ## Lint and format files
pre-commit run --all-files
fmt: pre-commit-install ## Lint and format files
$(ACTIVATE_VENV) pre-commit run --all-files

.PHONY: test
test: ## Run tests
python3 -m pytest tests/unit
test: venv ## Run tests
$(ACTIVATE_VENV) python3 -m pytest tests/unit

.PHONY: install
install: build ## Install the project onto a connected PROVES Kit use `BOARD_MOUNT_POINT` to specify the mount point
rsync -avh artifacts/proves/ $(BOARD_MOUNT_POINT) --delete

.PHONY: clean
clean: ## Remove all gitignored files such as downloaded libraries and artifacts
git clean -dfX

##@ Build

.PHONY: build
build: download-libraries ## Build the project, store the result in the artifacts directory
rm -rf artifacts/proves/
mkdir -p artifacts/proves
cp config.json artifacts/proves/
cp ./*.py artifacts/proves/
find ./lib -type d -name '__pycache__' -prune -o -type f -print | cpio -pdm artifacts/proves/
zip -r artifacts/proves.zip artifacts/proves

##@ Library Management

download-libraries: ## Download the required libraries
@echo "Downloading libraries..."
@pip3 install --requirement lib/requirements.txt --target lib --no-deps --upgrade --quiet
@rm -rf lib/*.dist-info
@echo "Creating artifacts/proves"
@rm -rf artifacts/proves/
@mkdir -p artifacts/proves
@cp config.json artifacts/proves/
@cp ./*.py artifacts/proves/
@find ./lib -type d -name '__pycache__' -prune -o -type f -print | cpio -pdm artifacts/proves/
@echo "Creating artifacts/proves.zip"
@zip -r artifacts/proves.zip artifacts/proves > /dev/null
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,44 @@ from pysquared_eps import cubesat as c
# Development Getting Started
We welcome contributions so please feel free to join us. If you have any questions about contributing please open an issue or a discussion.

We have a few python tools to make development safer, easier, and more consistent. To get started you'll need to set up your python virtual environment (venv).
We have a few python tools to make development safer, easier, and more consistent. To get started you'll need to run
```sh
make
```

## Manually testing code on the board
We are working on improving our automated testing but right now the best way to test your code is to run it on the board. We have provided the following command to make it easy to install code on the board:
```sh
make install BOARD_MOUNT_POINT=/PATH_TO_YOUR_BOARD
```

1. Create your venv `python3 -m venv venv`
2. Activate your venv `source ./venv/bin/activate`
3. Install required packages `pip install -r requirements.txt`
4. Download necessary libraries `make download-libraries`
You can find the path to your board by looking for the volume named `PYSQUARED`

## Precommit hooks
Everytime you make a change in git, it's called a commit. We have a tool called a precommit hook that will run before you make each commit to ensure your code is safe and formatted correctly.
### Mac
```sh
ls -lah /Volumes
...
drwx------@ 1 nate staff 16K Jan 9 08:09 PYSQUARED/
```

To install the precommit hook:
### Linux or Windows via WSL
```sh
df -h
```

1. Install the precommit hook with `pre-commit install`
## Build failures

To run the precommit hook:
### Lint failure
Everytime you make a change in git, it's called a commit. We have a tool called a precommit hook that will run before you make each commit to ensure your code is safe and formatted correctly. If you experience a lint failure you can run the following to fix it for you or tell you what's wrong.
```sh
make fmt
```

1. Run the precommit hook against all files with `make fmt`
### Test failure
To ensure our code works we use automated testing. If you're seeing a testing failure in your build, you can see what's wrong by running those tests yourself with:
```
make test
```

## General Structure:
- **boot.py** This is the code that runs on boot and initializes the stack limit
Expand Down

0 comments on commit 8feda29

Please sign in to comment.