Skip to content

Commit 1a8368e

Browse files
authored
Convert project into an uv workspace (#319)
1 parent 2a8dafa commit 1a8368e

11 files changed

Lines changed: 105 additions & 28 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ repos:
4848
rev: v25.8.1
4949
hooks:
5050
- id: ansible-lint
51-
language_version: python3.10 # minimal supported officially
5251
args: [--fix]
5352
- repo: https://github.com/adrienverge/yamllint.git
5453
rev: v1.37.1

packages/mk-pre/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# mk-pre
2+
3+
mk-pre plugin

packages/mk-pre/pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build-system]
2+
build-backend = "uv_build"
3+
requires = ["uv_build>=0.8.6,<0.9.0"]
4+
5+
[project]
6+
authors = [{email = "sorin.sbarnea@gmail.com", name = "Sorin Sbarnea"}]
7+
dependencies = [
8+
"rich>=12.0.0",
9+
"typer>=0.16.0",
10+
"typer-config>=1.4.2"
11+
]
12+
description = "mk-pre plugin"
13+
name = "mk-pre"
14+
readme = "README.md"
15+
requires-python = ">=3.10.0"
16+
version = "0.1.0"
17+
18+
[project.entry-points."mk_tools"]
19+
pre = "mk_pre.pre:PreTool"

packages/mk-pre/src/mk_pre/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from pathlib import Path
1010

1111
from mk.exec import run_or_fail
12-
from mk.pre import CFG_FILE
1312
from mk.tools import Action, Tool
13+
from mk_pre.__main__ import CFG_FILE
1414

1515

1616
class PreTool(Tool):

packages/mk-pre/src/mk_pre/py.typed

Whitespace-only changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Tests"""
22

3+
from mk_pre.__main__ import app
34
from typer.testing import CliRunner
45

5-
from mk.pre import app
6-
76
runner = CliRunner()
87

98

pyproject.toml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ lower = [
5151
"typer-config==1.4.2",
5252
"typer==0.16.0"
5353
]
54+
pkg = ["tomli>=2.2.1; python_version<'3.11'"]
5455

5556
[project]
5657
authors = [{"email" = "sorin.sbarnea@gmail.com", "name" = "Sorin Sbarnea"}]
@@ -87,8 +88,8 @@ dependencies = [
8788
"subprocess-tee>=0.4.1",
8889
"tomli>=2.0.1 ; python_full_version < '3.11'",
8990
"twine>=3.4.1",
90-
"typer-config>=1.4.0",
91-
"typer>=0.16.0"
91+
"typer>=0.16.0",
92+
"mk-pre"
9293
]
9394
dynamic = ["version"]
9495
license = "MIT"
@@ -104,7 +105,6 @@ git = "mk.tools.git:GitTool"
104105
make = "mk.tools.make:MakeTool"
105106
node = "mk.tools.node:NodeTool"
106107
nox = "mk.tools.nox:NoxTool"
107-
pre = "mk.tools.pre:PreTool"
108108
pre-commit = "mk.tools.pre_commit:PreCommitTool"
109109
pypackage = "mk.tools.py_package:PyPackageTool"
110110
pytest = "mk.tools.pytest:PyTestTool"
@@ -179,13 +179,22 @@ profile = "black"
179179
[tool.mypy]
180180
color_output = true
181181
error_summary = true
182-
exclude = [".ansible", ".cache", ".tox", "build", "dist"]
182+
exclude = [
183+
".ansible",
184+
".cache",
185+
".tox",
186+
".venv",
187+
"node_modules",
188+
"build",
189+
"dist",
190+
"site"
191+
]
183192
python_version = "3.10"
184193
strict = true
185194

186195
[[tool.mypy.overrides]]
187196
ignore_missing_imports = true
188-
module = ["diskcache", "pytest_benchmark.fixture"]
197+
module = ["git.*", "diskcache", "pytest_benchmark.fixture"]
189198

190199
[tool.ruff]
191200
# Same as Black.
@@ -222,7 +231,7 @@ ignore = [
222231
select = ["ALL"]
223232
flake8-pytest-style.parametrize-values-type = "tuple"
224233
isort.known-first-party = ["mk"]
225-
per-file-ignores."test/**/*.py" = ["S"]
234+
per-file-ignores."**/test/**/*.py" = ["S"]
226235
pydocstyle.convention = "google"
227236

228237
[tool.setuptools_scm]
@@ -252,9 +261,9 @@ env_list = ["py", "lint", "docs", "pkg", "lower", "devel", "integration"]
252261
requires = [
253262
"pip>=24",
254263
"setuptools>=65.3",
255-
"tox>=4.28.3",
264+
"tox>=4.28.4",
256265
"tox-extra>=2.1",
257-
"tox-uv>=1.27"
266+
"tox-uv>=1.28"
258267
]
259268
skip_missing_interpreters = true
260269

@@ -333,14 +342,12 @@ commands = [
333342
]
334343
description = "Builds docs"
335344
extras = ["docs"]
336-
package = "editable"
337345
skip_install = false
338346

339347
[tool.tox.env.integration]
340348
commands = [["ansible", "--version"], ["nox", "--version"], ["mk", "test-integration"]]
341349
dependency_groups = ["integration"]
342350
description = "Run integrations tests"
343-
package = "editable"
344351

345352
[tool.tox.env.lint]
346353
commands = [
@@ -360,15 +367,18 @@ runner = "uv-venv-runner"
360367
skip_install = true
361368

362369
[tool.tox.env.lower]
370+
commands_post = [["uv", "pip", "check"]]
363371
dependency_groups = ["dev", "lower"]
364372
description = "Run the tests with lower constraints dependencies"
373+
editable = true
365374
runner = "uv-venv-runner"
366375

367376
[tool.tox.env.pkg]
368377
commands = [["bash", "./tools/pkg.sh"]]
369378
commands_post = []
370379
commands_pre = []
371380
description = "Build package, verify metadata, install package and assert behavior when ansible is missing."
381+
group = "pkg"
372382
skip_install = true
373383

374384
[tool.tox.env_run_base]
@@ -437,3 +447,11 @@ TERM = "dump"
437447
# do not include 'lower' constraints in default groups
438448
default-groups = ["dev", "docs"]
439449
package = true
450+
451+
[tool.uv.sources]
452+
mk-pre = {workspace = true}
453+
454+
[tool.uv.workspace]
455+
members = ["packages/*"]
456+
457+
# exclude = ["packages/seeds"]

tools/pkg.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#!/usr/bin/env bash
22
# cspell: ignore euox
3-
set -euox pipefail
4-
env | grep TOX
3+
set -euo pipefail
4+
5+
PROJECT=$(python -c '''
6+
import sys
7+
if sys.version_info >= (3, 11):
8+
import tomllib
9+
else: # pragma: no cover (py311+)
10+
import tomli as tomllib
11+
print(tomllib.load(open("pyproject.toml","rb"))["project"]["name"])
12+
''')
13+
echo "Packaging sanity testing for '${PROJECT}' ..."
14+
rm -rf dist
15+
python3 -c "import os.path, shutil, sys; dist_dir = 'dist'; os.path.isdir(dist_dir) or sys.exit(0); print('Removing {!s} contents...'.format(dist_dir), file=sys.stderr); shutil.rmtree(dist_dir)"
16+
# We cannot use python build for workspaces as it does not --all-packages
17+
# python3 -m build
18+
uv build --all-packages
19+
20+
python3 -m twine check --strict dist/*
21+
22+
echo "Building wheels cache into .cache/wheels ..."
23+
pip download -q --find-links=dist --dest=./.cache/wheels "dist/${PROJECT}-"*.whl
524

625
echo "Isolate pipx for testing..."
726
export PIPX_HOME="${TOX_WORK_DIR:-.tox}/.pipx"
827
export PIPX_BIN_DIR="${PIPX_HOME}/bin"
928
export PATH="${PIPX_BIN_DIR}:${PATH}"
29+
# shellcheck disable=SC2034
1030
rm -rf "${PIPX_HOME}"
11-
pipx install --force -e .
12-
13-
rm -rf dist
14-
python3 -c "import os.path, shutil, sys; dist_dir = 'dist'; os.path.isdir(dist_dir) or sys.exit(0); print('Removing {!s} contents...'.format(dist_dir), file=sys.stderr); shutil.rmtree(dist_dir)"
15-
python3 -m build
16-
17-
python3 -m twine check --strict dist/*
18-
python3 -m pip install "mk @ file://$(pwd)/$(echo dist/*.whl)"
19-
python3 -m pip uninstall -y mk
31+
PIP_ARGS="--find-links=.cache/wheels --find-links=.dist" pipx install --force "${PROJECT}"

0 commit comments

Comments
 (0)