Skip to content

Commit 7b8d0d4

Browse files
committed
Add makefile
1 parent 85c24aa commit 7b8d0d4

3 files changed

Lines changed: 107 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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
git clean --force -dX
28+
29+
build: wheel
30+
31+
release: wheel sdist
32+
33+
sdist: dist/${PACKAGE}-${VERSION}.tar.gz
34+
35+
wheel: dist/${PACKAGE}-${VERSION}-py3-none-any.whl
36+
37+
dist:
38+
mkdir -p dist
39+
40+
dist/${PACKAGE}-${VERSION}.tar.gz: ${VENV_BIN_ACTIVATE} dist $(OBJ)
41+
. ${VENV_BIN_ACTIVATE}; \
42+
python -m build --sdist
43+
44+
dist/${PACKAGE}-${VERSION}-py3-none-any.whl: ${VENV_BIN_ACTIVATE} dist $(OBJ)
45+
. ${VENV_BIN_ACTIVATE}; \
46+
python -m build --wheel
47+
48+
${VENV_BIN_ACTIVATE}: requirements.txt
49+
@echo "Setting up development virtual env in .venv"
50+
python -m venv .venv
51+
. ${VENV_BIN_ACTIVATE}; \
52+
python -m pip install wheel build ruff; \
53+
python -m pip install \
54+
-r requirements.txt
55+
56+
test: ${VENV_BIN_ACTIVATE}
57+
bash test.sh
58+
59+
all: release
60+
61+
lint: $(VENV_BIN_ACTIVATE)
62+
. $(VENV_BIN_ACTIVATE); \
63+
python -m ruff check
64+
65+
lint-fix: $(VENV_BIN_ACTIVATE)
66+
. $(VENV_BIN_ACTIVATE); \
67+
python -m ruff check --fix
68+
69+
format: $(VENV_BIN_ACTIVATE)
70+
. $(VENV_BIN_ACTIVATE); \
71+
python -m ruff format --diff
72+
73+
format-fix: $(VENV_BIN_ACTIVATE)
74+
. $(VENV_BIN_ACTIVATE); \
75+
python -m ruff format
76+
77+
.PHONY: \
78+
all \
79+
build \
80+
clean \
81+
sdist \
82+
wheel \
83+
test \
84+
lint \
85+
lint-fix \
86+
format \
87+
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)