Skip to content

Commit

Permalink
Standardize Makefile (#2091)
Browse files Browse the repository at this point in the history
* Reorganize Makefile

* Add client Makefile

* Update CI make commands

* PR feedback: automate adding poetry binary path to PATH; use client make commands; small fixes/tweaks

* PR feedback: Replace command to add poetry to path with instructions for user to do it

* PR feedback: Use yarn instead of npm for client make commands

* Comment cleanup
  • Loading branch information
nikhilb4a authored Dec 9, 2024
1 parent 90ad5a8 commit 9c8ef4b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 42 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ commands:
- run:
name: create data model
command: |
make resetdb
make db-clean
# Generate the en_US.UTF-8 locale (which for some reason isn't set up in
# the Docker container we use). arlo uses this locale to parse numbers in CSVs.
- run:
Expand All @@ -54,16 +54,16 @@ jobs:
- run:
name: typecheck server
command: |
make typecheck-server
make typecheck
- run:
name: format server
command: |
make format-server
make format
git diff-index --quiet HEAD -- || (echo "Found unexpected changes!" && git diff && exit 1)
- run:
name: lint server
command: |
make lint-server
make lint
build-and-test-server:
executor: arlo
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
- run:
name: test client
command: |
make test-client
make -C client test
cypress:
executor: arlo
Expand Down
76 changes: 39 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,68 +1,70 @@
# Set path so we can find poetry after install
PATH := $(PATH):$(HOME)/.local/bin
## Prepare environment for development

deps:
prepare:
sudo apt update
sudo apt install -y python3.9 python3.9-venv libpython3.9-dev libpq-dev graphicsmagick gcc python-dev
# Install python with virtual env and dev extensions, graphicsmagick, and gcc
sudo apt install -y python3.9 python3.9-venv libpython3.9-dev python-dev libpq-dev graphicsmagick gcc postgresql
# Install node: https://github.com/nodesource/distributions/blob/master/README.md#deb
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install poetry: https://python-poetry.org/docs/#installing-with-the-official-installer
curl -sSL https://install.python-poetry.org | python3.9 -
# Install yarn
sudo npm install -g yarn
sudo apt install -y postgresql
sudo systemctl start postgresql
yarn install
yarn prepare # Sets up Git hooks
# Ensure poetry can be called from the command line and make commands
@echo "User action required: Make poetry available in your PATH. This will vary depending on your configuration"
@echo "If using bash, add 'export PATH=\"\$$PATH:\$$HOME/.local/bin\"' to your .bashrc and then run 'source ~/.bashrc'"

# this should only be used for development
initdevdb:
db-prepare:
sudo systemctl start postgresql
sudo -u postgres psql -c "create user arlo superuser password 'arlo';"
sudo -u postgres psql -c "create database arlo with owner arlo;"
make db-clean

install-development:
poetry install
yarn install
yarn --cwd client install

setup-git-hooks:
yarn prepare
## Local development

resettestdb:
FLASK_ENV=test make resetdb
dev-environment: prepare db-prepare install

resetdb:
FLASK_ENV=$${FLASK_ENV:-development} poetry run python -m scripts.resetdb
run: # Used for development, not during production deployment. Defaults to 3 ports - 8080, 3000, 3001
./run-dev.sh

migratedb:
FLASK_ENV=$${FLASK_ENV:-development} poetry run alembic upgrade head
## Following commands are mainly for server development, since client is encapsulated in a subdirectory

dev-environment: deps initdevdb install-development setup-git-hooks resetdb
install:
poetry install
yarn install
make -C client install

typecheck-server:
typecheck:
poetry run mypy server scripts fixtures

format-server:
format:
poetry run black .

lint-server:
lint:
poetry run pylint server scripts fixtures

test-client:
yarn --cwd client lint
yarn --cwd client test
test:
poetry run pytest -n auto --ignore=server/tests/arlo-extra-tests

test-server:
poetry run pytest -n auto --ignore=server/tests/arlo-extra-tests
test-clean:
FLASK_ENV=test make db-clean

test-server-coverage:
test-coverage:
poetry run pytest -n auto --cov=. --ignore=server/tests/arlo-extra-tests

# This runs all tests. If you have the extra files repo included, it runs those as well.
test-server-extra:
test-extra: # This runs the _extra files_ repo tests as well (must download first)
poetry run pytest -n auto

test-server-extra-coverage:
poetry run pytest -n auto --cov=.
test-extra-coverage:
poetry run pytest -n auto --cov=.

## Database

run-dev:
./run-dev.sh
db-clean:
FLASK_ENV=$${FLASK_ENV:-development} poetry run python -m scripts.resetdb

db-migrate:
FLASK_ENV=$${FLASK_ENV:-development} poetry run alembic upgrade head
15 changes: 15 additions & 0 deletions client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

install:
yarn install

run:
yarn start

lint:
yarn lint

test:
yarn test

build:
yarn build

0 comments on commit 9c8ef4b

Please sign in to comment.