Skip to content

Commit bf09cfd

Browse files
authored
Use ufmt makefile/CI workflow, use uv when available (#22)
1 parent 282f8c2 commit bf09cfd

File tree

4 files changed

+108
-64
lines changed

4 files changed

+108
-64
lines changed

.github/workflows/build.yml

-55
This file was deleted.

.github/workflows/ci.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- v*
8+
pull_request:
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
UV_SYSTEM_PYTHON: 1
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
23+
os: [macos-latest, ubuntu-latest, windows-latest]
24+
exclude:
25+
- os: macos-latest
26+
python-version: "3.7"
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
- name: Set Up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
allow-prereleases: true
36+
- uses: astral-sh/setup-uv@v2
37+
with:
38+
enable-cache: true
39+
cache-dependency-glob: pyproject.toml
40+
cache-suffix: ${{ matrix.python-version }}
41+
- name: Install
42+
run: make EXTRAS=dev install
43+
- name: Test
44+
run: make test
45+
- name: Lint
46+
run: make lint
47+
48+
build:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-python@v5
53+
with:
54+
python-version: '3.12'
55+
- uses: astral-sh/setup-uv@v2
56+
with:
57+
enable-cache: true
58+
cache-dependency-glob: pyproject.toml
59+
- name: Install
60+
run: make EXTRAS=dev install
61+
- name: Build
62+
run: python -m build
63+
- name: Upload
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: sdist
67+
path: dist
68+
69+
publish:
70+
needs: [build, test]
71+
runs-on: ubuntu-latest
72+
if: startsWith(github.ref, 'refs/tags/v')
73+
permissions:
74+
id-token: write
75+
steps:
76+
- uses: actions/download-artifact@v3
77+
with:
78+
name: sdist
79+
path: dist
80+
- uses: pypa/gh-action-pypi-publish@release/v1

makefile

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1+
SRCS:=diff_match_patch
2+
EXTRAS:=dev
3+
4+
ifeq ($(OS),Windows_NT)
5+
ACTIVATE:=.venv/Scripts/activate
6+
else
7+
ACTIVATE:=.venv/bin/activate
8+
endif
9+
10+
UV:=$(shell uv --version)
11+
ifdef UV
12+
VENV:=uv venv
13+
PIP:=uv pip
14+
else
15+
VENV:=python -m venv
16+
PIP:=python -m pip
17+
endif
18+
119
.venv:
2-
python -m venv .venv
3-
source .venv/bin/activate && make install
4-
echo 'run `source .venv/bin/activate` to develop diff-match-patch'
20+
$(VENV) .venv
521

622
venv: .venv
23+
source $(ACTIVATE) && make install
24+
echo 'run `source $(ACTIVATE)` to use virtualenv'
725

826
install:
9-
python -m pip install -e .[dev]
27+
$(PIP) install -Ue .[$(EXTRAS)]
1028

1129
release: lint test clean
1230
python -m flit publish
1331

1432
format:
15-
python -m ufmt format diff_match_patch
33+
python -m ufmt format $(SRCS)
1634

1735
lint:
18-
python -m ufmt check diff_match_patch
19-
python -m mypy -p diff_match_patch
36+
python -m ufmt check $(SRCS)
37+
python -m mypy -p $(SRCS)
2038

2139
test:
22-
python -m unittest -v diff_match_patch.tests
40+
python -m unittest -v $(SRCS).tests
2341

2442
clean:
2543
rm -rf build dist html README MANIFEST *.egg-info

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies = []
2626
[project.optional-dependencies]
2727
dev = [
2828
"attribution==1.6.2",
29+
"build>=1",
2930
"black==23.3.0",
3031
"flit==3.9.0",
3132
"mypy==1.2.0",
@@ -50,4 +51,4 @@ signed_tags = true
5051
version_file = true
5152

5253
[tool.mypy]
53-
python_version = "3.7"
54+
python_version = "3.7"

0 commit comments

Comments
 (0)