Skip to content

Commit 3cdc8f6

Browse files
authored
Use uv to install dev dependencies and build (#38)
1 parent 06d9a4a commit 3cdc8f6

File tree

5 files changed

+381
-35
lines changed

5 files changed

+381
-35
lines changed

.github/set-version

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@ import os
88
GIT_REF_PREFIX = "refs/tags/"
99

1010

11-
def github_ref_type(value: str) -> str:
11+
def github_ref_type(value: str | None) -> str:
12+
if value is None:
13+
raise ValueError("No GITHUB_REF environment variable")
14+
1215
if not value.startswith(GIT_REF_PREFIX):
1316
raise ValueError("Invalid GITHUB_REF format, expects `refs/tags/<tag name>`")
1417

1518
return value
1619

1720

18-
def write_about_file(file: io.TextIOWrapper, git_ref: str) -> None:
21+
def write_about_file(filename: str, git_ref: str) -> str:
1922
tag = git_ref[len(GIT_REF_PREFIX) :]
2023
value = f'__version__ = "{tag}"'
21-
print(value, file=file)
24+
25+
print(f"Writing version {tag} to {filename}")
26+
with open(filename, "w") as fp:
27+
print(value, file=fp)
28+
2229
return tag
2330

2431

@@ -28,7 +35,6 @@ def main() -> None:
2835
"-g",
2936
"--github-ref",
3037
default=os.environ.get("GITHUB_REF"),
31-
type=github_ref_type,
3238
help=(
3339
'The Git reference, like "refs/tags/<tag name>". '
3440
"Read automatically the GITHUB_REF environment variable, if possible."
@@ -38,12 +44,16 @@ def main() -> None:
3844
"-f",
3945
"--filename",
4046
default="structlog_gcp/__about__.py",
41-
type=argparse.FileType("w"),
4247
help="The file to write the version into.",
4348
)
4449
args = parser.parse_args()
4550

46-
write_about_file(args.filename, args.github_ref)
51+
try:
52+
github_ref = github_ref_type(args.github_ref)
53+
except Exception as exc:
54+
parser.error(str(exc))
55+
56+
write_about_file(args.filename, github_ref)
4757

4858

4959
if __name__ == "__main__":

.github/workflows/build-test-release.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,32 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@v4
2626

27-
- name: Setup Python
28-
uses: actions/setup-python@v5
27+
- name: Install the latest version of uv
28+
uses: astral-sh/setup-uv@v3
2929
with:
30-
python-version: "3.11"
31-
32-
- name: Setup Hatch
33-
run: pipx install hatch
30+
enable-cache: true
3431

3532
- name: Configure version
3633
if: github.event.action == 'published'
3734
run: ./.github/set-version
3835

3936
- name: Test
40-
run: hatch run pytest --color=yes
37+
run: make test
4138

4239
- name: mypy
43-
run: hatch run mypy
40+
run: make mypy
4441

4542
- name: lint
46-
run: hatch run ruff check
43+
run: uv run ruff check
4744

4845
- name: format
49-
run: hatch run ruff format --diff
46+
run: uv run ruff format --diff
5047

5148
- name: Build
52-
run: hatch build --clean
49+
run: make build
5350

5451
- name: Upload package
52+
if: github.event.action == 'published'
5553
uses: actions/upload-artifact@v4
5654
with:
5755
name: Packages

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ all: fmt mypy test
22

33
.PHONY: mypy
44
mypy:
5-
hatch run mypy
5+
uv run mypy
66

77
.PHONY: fmt
88
fmt:
9-
hatch run ruff format
10-
hatch run ruff check --fix
9+
uv run ruff format
10+
uv run ruff check --fix
1111

1212
.PHONY: test
1313
test:
14-
hatch run test
14+
uv run pytest
15+
16+
.PHONY: build
17+
build:
18+
uv run python -m build --installer=uv

pyproject.toml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
4-
51
[project]
62
name = "structlog-gcp"
73
description = "A structlog set of processors to output as Google Cloud Logging format"
84
readme = "README.md"
95
requires-python = ">=3.10"
10-
license = "MIT"
6+
license = { file = "LICENSE" }
117
keywords = []
128
authors = [
139
{ name = "Jonathan Ballet", email = "[email protected]" },
@@ -31,20 +27,22 @@ Documentation = "https://github.com/multani/structlog-gcp#readme"
3127
Issues = "https://github.com/multani/structlog-gcp/issues"
3228
Source = "https://github.com/multani/structlog-gcp"
3329

30+
[build-system]
31+
requires = ["hatchling"]
32+
build-backend = "hatchling.build"
33+
3434
[tool.hatch.version]
3535
path = "structlog_gcp/__about__.py"
3636

37-
[tool.hatch.envs.default]
38-
dependencies = [
39-
"ruff",
40-
"mypy",
41-
"pytest",
42-
"pytest-cov",
37+
[tool.uv]
38+
dev-dependencies = [
39+
"build[uv]>=1.2.2",
40+
"mypy>=1.11.2",
41+
"pytest>=8.3.3",
42+
"pytest-cov>=5.0.0",
43+
"ruff>=0.6.6",
4344
]
4445

45-
[tool.hatch.envs.default.scripts]
46-
test = "pytest"
47-
4846
[tool.pytest.ini_options]
4947
addopts = [
5048
"--doctest-modules",

0 commit comments

Comments
 (0)