Skip to content

Commit f4ac5ea

Browse files
feat: Add --meta uv for generating astral-sh/uv compatible packages. (#1286)
This PR adds support for `--meta uv` which then generates a `uv` compatible package with the `hatchling` build backend. Eventually, with newer versions of `uv`, it will probably use the `uv_build` backend. Resolves #1241 cc @johnthagen @dbanty --------- Co-authored-by: Alexander van Eck <[email protected]>
1 parent e934fd6 commit f4ac5ea

File tree

16 files changed

+137
-61
lines changed

16 files changed

+137
-61
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ htmlcov/
3636
# Generated end to end test data
3737
my-test-api-client/
3838
custom-e2e/
39-
3-1-features-client
39+
3-1-features-client
40+
tests/tmp

end_to_end_tests/docstrings-on-attributes-golden-record/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ description = "A client library for accessing My Test API"
55
authors = []
66
readme = "README.md"
77
packages = [
8-
{include = "my_test_api_client"},
8+
{ include = "my_test_api_client" },
99
]
1010
include = ["CHANGELOG.md", "my_test_api_client/py.typed"]
1111

12-
1312
[tool.poetry.dependencies]
1413
python = "^3.9"
1514
httpx = ">=0.23.0,<0.29.0"

end_to_end_tests/golden-record/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ description = "A client library for accessing My Test API"
55
authors = []
66
readme = "README.md"
77
packages = [
8-
{include = "my_test_api_client"},
8+
{ include = "my_test_api_client" },
99
]
1010
include = ["CHANGELOG.md", "my_test_api_client/py.typed"]
1111

12-
1312
[tool.poetry.dependencies]
1413
python = "^3.9"
1514
httpx = ">=0.23.0,<0.29.0"

end_to_end_tests/literal-enums-golden-record/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ description = "A client library for accessing My Enum API"
55
authors = []
66
readme = "README.md"
77
packages = [
8-
{include = "my_enum_api_client"},
8+
{ include = "my_enum_api_client" },
99
]
1010
include = ["CHANGELOG.md", "my_enum_api_client/py.typed"]
1111

12-
1312
[tool.poetry.dependencies]
1413
python = "^3.9"
1514
httpx = ">=0.23.0,<0.29.0"

end_to_end_tests/metadata_snapshots/poetry.pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ description = "A client library for accessing Test 3.1 Features"
55
authors = []
66
readme = "README.md"
77
packages = [
8-
{include = "test_3_1_features_client"},
8+
{ include = "test_3_1_features_client" },
99
]
1010
include = ["CHANGELOG.md", "test_3_1_features_client/py.typed"]
1111

12-
1312
[tool.poetry.dependencies]
1413
python = "^3.9"
1514
httpx = ">=0.23.0,<0.29.0"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[project]
2+
name = "test-3-1-features-client"
3+
version = "0.1.0"
4+
description = "A client library for accessing Test 3.1 Features"
5+
authors = []
6+
requires-python = "~=3.9"
7+
readme = "README.md"
8+
dependencies = [
9+
"httpx>=0.23.0,<0.29.0",
10+
"attrs>=22.2.0",
11+
"python-dateutil>=2.8.0,<3",
12+
]
13+
14+
[tool.hatch.build.targets.sdist]
15+
include = [
16+
"test_3_1_features_client",
17+
"CHANGELOG.md",
18+
"test_3_1_features_client/py.typed",
19+
]
20+
21+
[tool.hatch.build.targets.wheel]
22+
include = [
23+
"test_3_1_features_client",
24+
"CHANGELOG.md",
25+
"test_3_1_features_client/py.typed",
26+
]
27+
28+
[build-system]
29+
requires = ["hatchling"]
30+
build-backend = "hatchling.build"
31+
32+
[tool.ruff]
33+
line-length = 120
34+
35+
[tool.ruff.lint]
36+
select = ["F", "I", "UP"]

end_to_end_tests/regen_golden_record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def regen_metadata_snapshots():
7373
output_path = Path.cwd() / "test-3-1-features-client"
7474
snapshots_dir = Path(__file__).parent / "metadata_snapshots"
7575

76-
for (meta, file, rename_to) in (("setup", "setup.py", "setup.py"), ("pdm", "pyproject.toml", "pdm.pyproject.toml"), ("poetry", "pyproject.toml", "poetry.pyproject.toml")):
76+
for (meta, file, rename_to) in (("setup", "setup.py", "setup.py"), ("pdm", "pyproject.toml", "pdm.pyproject.toml"), ("poetry", "pyproject.toml", "poetry.pyproject.toml"), ("uv", "pyproject.toml", "uv.pyproject.toml")):
7777
_regenerate(
7878
spec_file_name="3.1_specific.openapi.yaml",
7979
output_dir="test-3-1-features-client",

end_to_end_tests/test-3-1-golden-record/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ description = "A client library for accessing Test 3.1 Features"
55
authors = []
66
readme = "README.md"
77
packages = [
8-
{include = "test_3_1_features_client"},
8+
{ include = "test_3_1_features_client" },
99
]
1010
include = ["CHANGELOG.md", "test_3_1_features_client/py.typed"]
1111

12-
1312
[tool.poetry.dependencies]
1413
python = "^3.9"
1514
httpx = ">=0.23.0,<0.29.0"

end_to_end_tests/test_end_to_end.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_literal_enums_end_to_end():
143143
("setup", "setup.py", "setup.py"),
144144
("pdm", "pyproject.toml", "pdm.pyproject.toml"),
145145
("poetry", "pyproject.toml", "poetry.pyproject.toml"),
146+
("uv", "pyproject.toml", "uv.pyproject.toml"),
146147
)
147148
)
148149
def test_meta(meta: str, generated_file: Optional[str], expected_file: Optional[str]):
@@ -284,7 +285,7 @@ def test_update_integration_tests():
284285
import mypy.api
285286

286287
out, err, status = mypy.api.run([str(temp_dir), "--strict"])
287-
assert status == 0, f"Type checking client failed: {out}"
288+
assert status == 0, f"Type checking client failed: {out=} {err=}"
288289

289290
finally:
290291
shutil.rmtree(temp_dir)

openapi_python_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _build_metadata(self) -> None:
184184
readme = self.project_dir / "README.md"
185185
readme_template = self.env.get_template("README.md.jinja")
186186
readme.write_text(
187-
readme_template.render(poetry=self.config.meta_type == MetaType.POETRY),
187+
readme_template.render(meta=self.config.meta_type),
188188
encoding=self.config.file_encoding,
189189
)
190190

0 commit comments

Comments
 (0)