You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A couple of things drive this change—first, PEP621 has been around for a
while now and Poetry shows no signs of adopting it, so while I don't
want to ditch Poetry support (it's very popular), I do want a way to
generate that style of metadata. PDM seems like a good target for that.
Second, Poetry has deprecated some plugins we use... or something. I
didn't look into it, but we're getting warnings on every project build
now. So, seems like time to switch over to something else. Conveniently,
this will make the development commands shorter (`poetry run task check`
becomes `pdm check`).
TODO:
- [x] Convert this project to PDM
- [x] Support PDM metadata (which is partially [PEP
621](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-pyproject-toml))
- [x] Update release workflows to use PDM as well
- [x] Document using PDM metadata in README
- [x] Double-check that `py.typed` is included with a generated PDM
project
- [x] Add snapshot tests for different metadata types and test them as
much as possible
---------
Co-authored-by: Dylan Anthony <[email protected]>
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+4-5
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,9 @@ To request a feature:
40
40
41
41
### Setting up a Dev Environment
42
42
43
-
1. Make sure you have [Poetry](https://python-poetry.org/) installed and up to date.
44
-
2. Make sure you have a supported Python version (e.g. 3.8) installed and accessible to Poetry (e.g. with [pyenv](https://github.com/pyenv/pyenv)).
45
-
3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies.
46
-
4. Enter a `poetry shell` to make running commands easier.
43
+
1. Make sure you have [PDM](https://pdm-project.org) installed and up to date.
44
+
2. Make sure you have a supported Python version (e.g. 3.8) installed.
45
+
3. Use `pdm install` in the project directory to create a virtual environment with the relevant dependencies.
47
46
48
47
### Writing tests
49
48
@@ -57,7 +56,7 @@ If you think that some of the added code is not testable (or testing it would ad
57
56
58
57
#### End-to-end tests
59
58
60
-
This project aims to have all "happy paths" (types of code which _can_ be generated) covered by end to end tests (snapshot tests). In order to check code changes against the previous set of snapshots (called a "golden record" here), you can run `poetry run task e2e`. To regenerate the snapshots, run `poetry run task regen`.
59
+
This project aims to have all "happy paths" (types of code which _can_ be generated) covered by end to end tests (snapshot tests). In order to check code changes against the previous set of snapshots (called a "golden record" here), you can run `pdm e2e`. To regenerate the snapshots, run `pdm regen`.
61
60
62
61
There are 4 types of snapshots generated right now, you may have to update only some or all of these depending on the changes you're making. Within the `end_to_end_tets` directory:
Copy file name to clipboardexpand all lines: README.md
+6-5
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ This tool focuses on creating the best developer experience for Python developer
26
26
27
27
I recommend you install with [pipx](https://pipxproject.github.io/pipx/) so you don't conflict with any other packages you might have: `pipx install openapi-python-client --include-deps`.
28
28
29
-
> Note the `--include-deps` option which will also make `black` and `ruff` available in your path so that `openapi-python-client` can use them to clean up the generated code.
29
+
> Note the `--include-deps` option makes `ruff` available in your path so that `openapi-python-client` can use it to clean up the generated code.
30
30
31
31
**If you use `pipx run` then the post-generation hooks will not be available unless you install them manually.**
32
32
@@ -52,8 +52,6 @@ If you have an `openapi.json` file available on disk, in any CLI invocation you
> For more usage details run `openapi-python-client --help` or read [usage](usage.md)
56
-
57
55
### Using custom templates
58
56
59
57
This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom-template-path` flag to the `generate` and `update` commands. For instance,
@@ -68,14 +66,15 @@ _Be forewarned, this is a beta-level feature in the sense that the API exposed i
68
66
69
67
## What You Get
70
68
71
-
1. A `pyproject.toml` filewith some basic metadata intended to be used with [Poetry].
69
+
1. A `pyproject.toml` file, optionally with [Poetry]metadata (default), [PDM] (with `--meta=pdm`), or only [Ruff] config.
72
70
2. A `README.md` you'll most definitely need to update with your project's details
73
71
3. A Python module named just like the auto-generated project name (e.g. "my_api_client") which contains:
74
72
1. A `client` module which will have both a `Client` class and an `AuthenticatedClient` class. You'll need these
75
73
for calling the functions in the `api` module.
76
74
2. An `api` module which will contain one module for each tag in your OpenAPI spec, as well as a `default` module
77
75
for endpoints without a tag. Each of these modules in turn contains one function for calling each endpoint.
78
76
3. A `models` module which has all the classes defined by the various schemas in your OpenAPI spec
77
+
4. A `setup.py` file _if_ you use `--meta=setup` (default is `--meta=poetry`)
79
78
80
79
For a full example you can look at the `end_to_end_tests` directory which has `baseline_openapi_3.0.json` and `baseline_openapi_3.1.yaml` files.
81
80
The "golden-record" in that same directory is the generated client from either of those OpenAPI documents.
In the config file, there's an easy way to tell `openapi-python-client` to run additional commands after generation. Here's an example showing the default commands that will run if you don't override them in config:
139
+
In the config file, there's an easy way to tell `openapi-python-client` to run additional commands after generation. Here's an example showing the default commands (using [Ruff]) that will run if you don't override them in config:
141
140
142
141
```yaml
143
142
post_hooks:
@@ -159,3 +158,5 @@ By default, the timeout for retrieving the schema file via HTTP is 5 seconds. In
0 commit comments