Skip to content

Commit 17291c1

Browse files
feat: Add --meta uv for generating astral-sh/uv compatible packages.
Resolves #1241
1 parent 365e196 commit 17291c1

File tree

9 files changed

+91
-9
lines changed

9 files changed

+91
-9
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
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_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

openapi_python_client/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MetaType(str, Enum):
2626
POETRY = "poetry"
2727
SETUP = "setup"
2828
PDM = "pdm"
29+
UV = "uv"
2930

3031

3132
class ConfigFile(BaseModel):

openapi_python_client/templates/README.md.jinja

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ client = Client(
109109
client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
110110
```
111111

112-
{% if poetry %}
112+
{% if meta == "poetry" %}
113113
## Building / publishing this package
114114
This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
115115
1. Update the metadata in pyproject.toml (e.g. authors, version)
@@ -123,4 +123,17 @@ If you want to install this client into another project without publishing it (e
123123
1. If that project is not using Poetry:
124124
1. Build a wheel with `poetry build -f wheel`
125125
1. Install that wheel from the other project `pip install <path-to-wheel>`
126+
{% elif meta == 'uv' %}
127+
## Building / publishing this package
128+
This project uses [uv](https://github.com/astral-sh/uv) to manage dependencies and packaging. Here are the basics:
129+
1. Update the metadata in `pyproject.toml` (e.g. authors, version).
130+
2. If you're using a private repository: https://docs.astral.sh/uv/guides/integration/alternative-indexes/
131+
3. Build a distribution with `uv build`, builds `sdist` and `wheel` by default.
132+
1. Publish the client with `uv publish`, see documentation for publishing to private indexes.
133+
134+
If you want to install this client into another project without publishing it (e.g. for development) then:
135+
1. If that project **is using uv**, you can simply do `uv add <path-to-this-client>` from that project
136+
1. If that project is not using uv:
137+
1. Build a wheel with `uv build --wheel`.
138+
1. Install that wheel from the other project `pip install <path-to-wheel>`.
126139
{% endif %}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{% set poetry = meta == "poetry" %}
2-
{% set pdm = meta == "pdm" %}
3-
{% if poetry %}
1+
{% if meta == "poetry" %}
42
{% include "pyproject_poetry.toml.jinja" %}
5-
{% elif pdm %}
3+
{% elif meta == "pdm" %}
64
{% include "pyproject_pdm.toml.jinja" %}
5+
{% elif meta == "uv" %}
6+
{% include "pyproject_uv.toml.jinja" %}
77
{% endif %}
88

99
{% include "pyproject_ruff.toml.jinja" %}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[project]
2+
name = "{{ project_name }}"
3+
version = "{{ package_version }}"
4+
description = "{{ package_description }}"
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+
"{{ package_name }}",
17+
"CHANGELOG.md",
18+
"{{ package_name }}/py.typed",
19+
]
20+
21+
[tool.hatch.build.targets.wheel]
22+
include = [
23+
"{{ package_name }}",
24+
"CHANGELOG.md",
25+
"{{ package_name }}/py.typed",
26+
]
27+
28+
[build-system]
29+
requires = ["hatchling"]
30+
build-backend = "hatchling.build"

0 commit comments

Comments
 (0)