Skip to content

Commit e16273b

Browse files
authored
eng: fix up project configuration - BNCH-112051 (#221)
* eng: fix package ID & description - BNCH-112051 * recreate project config with poetry instead of pdm
1 parent 55e26c5 commit e16273b

File tree

8 files changed

+1142
-1155
lines changed

8 files changed

+1142
-1155
lines changed

.github/workflows/checks.yml

+17-13
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ jobs:
3030
uses: actions/cache@v4
3131
with:
3232
path: .venv
33-
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/pdm.lock') }}
33+
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/poetry.lock') }}
3434
restore-keys: |
3535
${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies
36-
- name: Install PDM
37-
run: pip install pdm
36+
- name: Install Poetry
37+
run: pip install poetry
3838

3939
- name: Install Dependencies
40-
run: pdm install
40+
run: poetry install
4141

4242
- name: Check formatting
43-
run: pdm run ruff format . --check
43+
run: poetry run ruff format . --check
4444

4545
- name: Run mypy
46-
run: pdm mypy --show-error-codes
46+
run: poetry run task mypy --show-error-codes
4747

4848
- name: Lint
49-
run: pdm run ruff check .
49+
run: poetry run ruff check .
5050

5151
- name: Run pytest without coverage
5252
if: matrix.os != 'ubuntu-latest'
53-
run: pdm test
53+
run: poetry run task test
5454
env:
5555
TASKIPY: true
5656

5757
- name: Run pytest with coverage
5858
if: matrix.os == 'ubuntu-latest'
59-
run: pdm test_with_coverage
59+
run: poetry run task test_with_coverage
6060
env:
6161
TASKIPY: true
6262

@@ -131,27 +131,31 @@ jobs:
131131
- name: Set up Python
132132
uses: actions/[email protected]
133133
with:
134-
python-version: "3.8"
134+
python-version: "3.9"
135135
- name: Get Python Version
136136
id: get_python_version
137137
run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT
138138
- name: Cache dependencies
139139
uses: actions/cache@v4
140140
with:
141141
path: .venv
142-
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/pdm.lock') }}
142+
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/poetry.lock') }}
143143
restore-keys: |
144144
${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies
145+
# General note on this job: the main project uses poetry, but the project inside integration-tests/
146+
# uses pdm. That's because integration-tests/ is a generated client-- the output from running the
147+
# generator on a test API spec-- and the "make a pdm project" option was used in that process.
145148
- name: Install dependencies
146149
run: |
150+
pip install poetry
147151
pip install pdm
148152
python -m venv .venv
149-
pdm install
153+
poetry install
150154
- name: Cache Generated Client Dependencies
151155
uses: actions/cache@v4
152156
with:
153157
path: integration-tests/.venv
154-
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies-${{ hashFiles('**/pdm.lock') }}
158+
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies-${{ hashFiles('**/poetry.lock') }}
155159
restore-keys: |
156160
${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies
157161
- name: Set httpx version

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ my-test-api-client/
3838
custom-e2e/
3939
3-1-features-client
4040
localtest
41+
42+
!tests/.env

CONTRIBUTING.md

+24-43
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
1-
# Ways you can Contribute
1+
# Note: this is the fork of openapi-python-client maintained and used by Benchling.
22

3-
- Report bugs via [issues](https://github.com/openapi-generators/openapi-python-client/issues)
4-
- Request features via [discussions](https://github.com/openapi-generators/openapi-python-client/discussions)
5-
- Contribute code via [pull request](https://github.com/openapi-generators/openapi-python-client/pulls)
3+
If you want the official package, go to the upstream repository: https://github.com/openapi-generators/openapi-python-client
64

7-
## Reporting a bug
5+
For contribution guidelines (including contributing fixes from our fork to the upstream repo), see Benchling internal documentation.
86

9-
A bug is one of:
7+
This document mostly contains basic developer instructions.
108

11-
1. You get an exception when running the generator
12-
2. The generated code is invalid or incorrect
13-
3. An error message is unclear or incorrect
14-
4. Something which used to work no longer works, except:
15-
1. Intentional breaking changes, which are documented in the [changelog](https://github.com/openapi-generators/openapi-python-client/blob/main/CHANGELOG.md)
16-
2. Breaking changes to unstable features, like custom templates
9+
## Setting up environment
1710

18-
If your issue does not fall under one of the above, it is not a bug; check out "[Requesting a feature](#requesting-a-feature).
11+
Create a virtualenv with the lowest compatible Python version (currently 3.9).
1912

20-
### Report requirements
13+
To install dependencies:
2114

22-
A bug report **must** have an OpenAPI document that can be used to replicate the bug. Reports without a valid document will be closed.
15+
```
16+
pip install poetry
17+
poetry install
18+
```
2319

24-
## Requesting a feature
20+
## Running tests
2521

26-
A feature is usually:
22+
See the [upstream repo]() for a full description of how the tests in this project are written.
2723

28-
1. An improvement to the way the generated code works
29-
2. A feature of the generator itself which makes its use easier (e.g., a new config option)
30-
3. **Support for part of the OpenAPI spec**; this generator _does not yet_ support every OpenAPI feature, these missing features **are not bugs**.
24+
`poetry run task unit` runs only the basic unit tests.
3125

32-
To request a feature:
26+
`poetry run task test` runs unit tests plus end-to-end tests.
3327

34-
1. Search through [discussions](https://github.com/openapi-generators/openapi-python-client/discussions/categories/feature-request) to see if the feature you want has already been requested. If it has:
35-
1. Upvote it with the little arrow on the original post. This enables code contributors to prioritize the most-demanded features.
36-
2. Optionally leave a comment describing why _you_ want the feature, if no existing thread already covers your use-case
37-
2. If a relevant discussion does not already exist, create a new one. If you are not requesting support for part of the OpenAPI spec, **you must** describe _why_ you want the feature. What real-world use-case does it improve? For example, "raise exceptions for invalid responses" might have a description of "it's not worth the effort to check every error case by hand for the one-off scripts I'm writing".
28+
## Linting/type-checking
3829

39-
## Contributing Code
30+
The project uses ruff. `poetry run task lint` and `poetry run task format` run `ruff check` and `ruff format`.
31+
32+
`poetry run task mypy` runs `mypy` on only the package module (tests are excluded).
4033

41-
### Setting up a Dev Environment
34+
`poetry run task check` runs all of those plus tests.
4235

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.
36+
## Contributing Code
37+
38+
This section is a copy from the upstream repo, with some changes due to Benchling test framework additions that haven't yet been accepted upstream.
4639

4740
### Writing tests
4841

@@ -61,7 +54,7 @@ This project aims to have all "happy paths" (types of code which _can_ be genera
6154

6255
Snapshot tests verify that the generated code is identical to a previously-committed set of snapshots (called a "golden record" here). They are basically regression tests to catch any unintended changes in the generator output.
6356

64-
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`.
57+
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`.
6558

6659
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_tests` directory:
6760

@@ -84,15 +77,3 @@ These include:
8477

8578
* Regular unit tests of basic pieces of fairly self-contained low-level functionality, such as helper functions. These are implemented in the `tests` directory, using the `pytest` framework.
8679
* Older-style unit tests of low-level functions like `property_from_data` that have complex behavior. These are brittle and difficult to maintain, and should not be used going forward. Instead, they should be migrated to functional tests.
87-
88-
### Creating a Pull Request
89-
90-
Once you've written the tests and code and run the checks, the next step is to create a pull request against the `main` branch of this repository. This repository uses [Knope] to auto-generate release notes and version numbers. This can either be done by setting the title of the PR to a [conventional commit] (for simple changes) or by adding [changesets]. If the changes are not documented yet, a check will fail on GitHub. The details of this check will have suggestions for documenting the change (including an example change file for changesets).
91-
92-
### Wait for Review
93-
94-
As soon as possible, your PR will be reviewed. If there are any changes requested there will likely be a bit of back and forth. Once this process is done, your changes will be merged into main and included in the next release. If you need your changes available on PyPI by a certain time, please mention it in the PR, and we'll do our best to accommodate.
95-
96-
[Knope]: https://knope.tech
97-
[changesets]: https://knope.tech/reference/concepts/changeset/
98-
[Conventional Commits]: https://knope.tech/reference/concepts/conventional-commits/

openapi_python_client/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
from .parser.errors import ErrorLevel, GeneratorError
2323
from .parser.properties import LiteralEnumProperty
2424

25-
__version__ = version(__package__)
25+
# __version__ = version(__package__)
26+
# Benchling-specific change: the original line above won't work because the installed package name of
27+
# our fork (benchling-openapi-python-client) deliberately does not match the base module name (see
28+
# pyproject.toml)
29+
INSTALLED_PACKAGE = "benchling-openapi-python-client"
30+
__version__ = version(INSTALLED_PACKAGE)
2631

2732

2833
TEMPLATE_FILTERS = {

0 commit comments

Comments
 (0)