Skip to content

Commit 8e1dd6e

Browse files
committed
Add makefile
1 parent 85c24aa commit 8e1dd6e

3 files changed

Lines changed: 110 additions & 4 deletions

File tree

‎.github/workflows/build.yaml‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ on:
99
types: [released]
1010
permissions: read-all
1111
jobs:
12+
lint:
13+
name: Lint code
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout the Git repository
17+
uses: actions/checkout@v4
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.13
22+
cache: "pip"
23+
- name: Lint code
24+
shell: bash
25+
run: make lint format
1226
test-image:
1327
name: Generate test ext4 image
1428
runs-on: ubuntu-latest
@@ -59,11 +73,11 @@ jobs:
5973
cache: "pip"
6074
- name: Run test
6175
shell: bash
62-
run: ./test.sh
76+
run: make test
6377
build:
6478
name: Build pip package
6579
runs-on: ubuntu-latest
66-
needs: [test]
80+
needs: [test, lint]
6781
steps:
6882
- name: Checkout the Git repository
6983
uses: actions/checkout@v4
@@ -75,7 +89,7 @@ jobs:
7589
- name: Install build tool
7690
run: pip install build
7791
- name: Building package
78-
run: python -m build
92+
run: make release
7993
- uses: actions/upload-artifact@v4
8094
with:
8195
name: pip

‎Makefile‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.DEFAULT_GOAL := all
2+
VERSION := $(shell grep -m 1 version pyproject.toml | tr -s ' ' | tr -d "'\":" | cut -d' ' -f3)
3+
PACKAGE := $(shell grep -m 1 name pyproject.toml | tr -s ' ' | tr -d "'\":" | cut -d' ' -f3)
4+
5+
OBJ := $(wildcard ${PACKAGE}/**)
6+
OBJ += requirements.txt
7+
OBJ += pyproject.toml
8+
OBJ += README.md
9+
OBJ += LICENSE
10+
11+
SHELL := /bin/bash
12+
ifeq ($(OS),Windows_NT)
13+
ifeq ($(VENV_BIN_ACTIVATE),)
14+
VENV_BIN_ACTIVATE := .venv/Scripts/activate
15+
endif
16+
else
17+
ifeq ($(VENV_BIN_ACTIVATE),)
18+
VENV_BIN_ACTIVATE := .venv/bin/activate
19+
endif
20+
endif
21+
22+
ifeq ($(PYTHON),)
23+
PYTHON := python
24+
endif
25+
26+
clean:
27+
if [ -d .venv/mnt ] && mountpoint -q .venv/mnt; then \
28+
umount -ql .venv/mnt; \
29+
fi
30+
git clean --force -dX
31+
32+
build: wheel
33+
34+
release: wheel sdist
35+
36+
sdist: dist/${PACKAGE}-${VERSION}.tar.gz
37+
38+
wheel: dist/${PACKAGE}-${VERSION}-py3-none-any.whl
39+
40+
dist:
41+
mkdir -p dist
42+
43+
dist/${PACKAGE}-${VERSION}.tar.gz: ${VENV_BIN_ACTIVATE} dist $(OBJ)
44+
. ${VENV_BIN_ACTIVATE}; \
45+
python -m build --sdist
46+
47+
dist/${PACKAGE}-${VERSION}-py3-none-any.whl: ${VENV_BIN_ACTIVATE} dist $(OBJ)
48+
. ${VENV_BIN_ACTIVATE}; \
49+
python -m build --wheel
50+
51+
${VENV_BIN_ACTIVATE}: requirements.txt
52+
@echo "Setting up development virtual env in .venv"
53+
python -m venv .venv
54+
. ${VENV_BIN_ACTIVATE}; \
55+
python -m pip install wheel build ruff; \
56+
python -m pip install \
57+
-r requirements.txt
58+
59+
test: ${VENV_BIN_ACTIVATE}
60+
bash test.sh
61+
62+
all: release
63+
64+
lint: $(VENV_BIN_ACTIVATE)
65+
. $(VENV_BIN_ACTIVATE); \
66+
python -m ruff check
67+
68+
lint-fix: $(VENV_BIN_ACTIVATE)
69+
. $(VENV_BIN_ACTIVATE); \
70+
python -m ruff check --fix
71+
72+
format: $(VENV_BIN_ACTIVATE)
73+
. $(VENV_BIN_ACTIVATE); \
74+
python -m ruff format --diff
75+
76+
format-fix: $(VENV_BIN_ACTIVATE)
77+
. $(VENV_BIN_ACTIVATE); \
78+
python -m ruff format
79+
80+
.PHONY: \
81+
all \
82+
build \
83+
clean \
84+
sdist \
85+
wheel \
86+
test \
87+
lint \
88+
lint-fix \
89+
format \
90+
format-fix

‎test.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
3-
python -m venv .venv
3+
if ! [ -d .venv ];then
4+
python -m venv .venv
5+
fi
46
if [ -f .venv/Scripts/activate ]; then
57
. .venv/Scripts/activate
68
elif [ -f .venv/bin/activate ]; then

0 commit comments

Comments
 (0)