Skip to content

Commit dd32694

Browse files
authored
Fix custom package install in CI is not working (#2302)
* Fix custom package install in CI is overriden Signed-off-by: Bernát Gábor <[email protected]> * Instal toml for custom isort Signed-off-by: Bernát Gábor <[email protected]> * Ignore black doesn't support experimental string processing Signed-off-by: Bernát Gábor <[email protected]> * Add custom test environments to tox Signed-off-by: Bernát Gábor <[email protected]> --------- Signed-off-by: Bernát Gábor <[email protected]>
1 parent 0204b72 commit dd32694

13 files changed

+1577
-176
lines changed

.github/workflows/codeql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
- cron: "26 1 * * 4"
1010
workflow_dispatch:
1111

12+
concurrency:
13+
group: codeql-${{ github.ref }}
14+
cancel-in-progress: true
15+
1216
jobs:
1317
analyze:
1418
name: Analyze

.github/workflows/codespell.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
pull_request:
99
branches: [main]
1010

11+
concurrency:
12+
group: codespell-${{ github.ref }}
13+
cancel-in-progress: true
14+
1115
permissions:
1216
contents: read
1317

.github/workflows/codspeed.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
# performance analysis in order to generate initial data.
1010
workflow_dispatch:
1111

12+
concurrency:
13+
group: codespeed-${{ github.ref }}
14+
cancel-in-progress: true
15+
1216
jobs:
1317
benchmarks:
1418
runs-on: ubuntu-24.04

.github/workflows/docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
workflow_dispatch:
88

9+
concurrency:
10+
group: docs-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
build-deploy:
1115
runs-on: ubuntu-24.04

.github/workflows/test.yml

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,28 @@ on:
77
branches: [main]
88
workflow_dispatch:
99

10+
concurrency:
11+
group: test-${{ github.ref }}
12+
cancel-in-progress: true
13+
1014
jobs:
1115
test:
1216
name: >-
13-
Test ${{ matrix.py }}
17+
${{ matrix.py || matrix.tox_env }} on
1418
${{ matrix.os == 'windows-latest' && 'Windows' || (matrix.os == 'macos-latest' && 'macOS' || 'Ubuntu') }}
15-
${{ matrix.isort != '' && format('isort={0} ', matrix.isort) || ''}}
16-
${{ matrix.black != '' && format('black={0} ', matrix.black) || ''}}
17-
${{ matrix.pydantic != '' && format('pydantic={0} ', matrix.pydantic) || ''}}
1819
strategy:
1920
fail-fast: false
2021
matrix:
2122
py: ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8"]
2223
os: [ubuntu-24.04, windows-latest, macos-latest]
23-
isort: [''] # '' mean not set, aka use the default
24-
black: ['']
25-
pydantic: ['']
24+
tox_env: ['']
2625
include:
27-
- py: 3.12
28-
black: 24.1.0
29-
- py: 3.12
30-
black: 23.12.1
31-
- py: 3.12
32-
black: 22.1.0
33-
- py: 3.9
34-
black: 19.10b0
35-
pydantic: 1.8.2
36-
- py: 3.8
37-
pydantic: 1.8.2
38-
- py: 3.8
39-
isort: 4.3.21
40-
pydantic: 1.5.1
26+
- tox_env: py3.12-black24
27+
- tox_env: py3.12-black23
28+
- tox_env: py3.12-black22
29+
- tox_env: py3.9-black19
30+
- tox_env: py3.8-pydantic18
31+
- tox_env: py3.8-isort4
4132
runs-on: ${{ matrix.os == '' && 'ubuntu-24.04' || matrix.os }}
4233
env:
4334
OS: ${{ matrix.os == '' && 'ubuntu-24.04' || matrix.os}}
@@ -47,36 +38,31 @@ jobs:
4738
fetch-depth: 0
4839
- name: Install the latest version of uv
4940
uses: astral-sh/setup-uv@v5
50-
with:
51-
python-version: ${{ matrix.py }}
5241
- name: Install tox
5342
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
5443
- name: Setup Python test environment
55-
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py }}
56-
- name: Install custom package versions
57-
if: ${{ matrix.isort != '' || matrix.black != '' || matrix.pydantic != ''}}
58-
run: >-
59-
tox exec --no-list-dependencies --skip-pkg-install -e ${{ matrix.py }} -- uv pip install
60-
${{ matrix.isort != '' && format('isort=={0} ', matrix.isort) || ''}}
61-
${{ matrix.black != '' && format('black=={0} ', matrix.black) || ''}}
62-
${{ matrix.pydantic != '' && format('pydantic=={0} ', matrix.pydantic) || ''}}
44+
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py || matrix.tox_env }}
45+
env:
46+
UV_PYTHON_PREFERENCE: "only-managed"
6347
- name: Run test suite
64-
run: tox run --skip-pkg-install -e ${{ matrix.py }}
48+
run: tox run --skip-uv-sync --skip-pkg-install -e ${{ matrix.py || matrix.tox_env }}
49+
env:
50+
UV_PYTHON_PREFERENCE: "only-managed"
6551
- name: Rename coverage report file
6652
run: |
6753
import os; import sys
68-
os.rename(f".tox/.coverage.${{ matrix.py }}", f".tox/.coverage.${{ matrix.py }}-${{ matrix.os }}-${{ matrix.isort }}-${{ matrix.black }}-${{ matrix.pydantic }}")
54+
os.rename(f".tox/.coverage.${{ matrix.py || matrix.tox_env }}", f".tox/.coverage.${{ matrix.py || matrix.tox_env}}-${{ matrix.os }}")
6955
shell: python
7056
- name: Upload coverage data
7157
uses: actions/upload-artifact@v4
7258
with:
7359
include-hidden-files: true
74-
name: .coverage.${{ matrix.py }}.${{ matrix.os }}.${{ matrix.isort }}.${{ matrix.black }}.${{ matrix.pydantic }}
60+
name: .coverage.${{ matrix.py || matrix.tox_env }}-${{ matrix.os == '' && 'ubuntu-24.04' || matrix.os }}
7561
path: ".tox/.coverage.*"
7662
retention-days: 3
7763

7864
coverage:
79-
name: Combine coverage
65+
name: combine coverage
8066
runs-on: ubuntu-latest
8167
needs: test
8268
steps:
@@ -94,7 +80,7 @@ jobs:
9480
- name: Build package to generate version
9581
run: uv build --python 3.13 --python-preference only-managed --wheel . --out-dir dist
9682
- name: Setup coverage tool
97-
run: tox -e coverage --notest
83+
run: tox run -e coverage --notest
9884
env:
9985
UV_PYTHON_PREFERENCE: only-managed
10086
- name: Download coverage data
@@ -104,7 +90,7 @@ jobs:
10490
pattern: .coverage.*
10591
merge-multiple: true
10692
- name: Combine and report coverage
107-
run: tox -e coverage --skip-pkg-install
93+
run: tox run -e coverage --skip-uv-sync --skip-pkg-install
10894
env:
10995
UV_PYTHON_PREFERENCE: only-managed
11096
- name: Upload HTML report
@@ -120,9 +106,10 @@ jobs:
120106
fail_ci_if_error: true
121107
env:
122108
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
109+
123110
check:
124-
name: tox env ${{ matrix.tox_env }} on ${{ matrix.os }}
125-
runs-on: ${{ matrix.os }}
111+
name: ${{ matrix.tox_env }}
112+
runs-on: ubuntu-latest
126113
strategy:
127114
fail-fast: false
128115
matrix:
@@ -132,8 +119,6 @@ jobs:
132119
- docs
133120
- pkg_meta
134121
- readme
135-
os:
136-
- ubuntu-latest
137122
steps:
138123
- uses: actions/checkout@v4
139124
with:
@@ -144,5 +129,9 @@ jobs:
144129
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
145130
- name: Setup check suite
146131
run: tox r -vv --notest --skip-missing-interpreters false -e ${{ matrix.tox_env }}
132+
env:
133+
UV_PYTHON_PREFERENCE: "only-managed"
147134
- name: Run check for ${{ matrix.tox_env }}
148-
run: tox r --skip-pkg-install -e ${{ matrix.tox_env }}
135+
run: tox run --skip-uv-sync --skip-pkg-install -e ${{ matrix.tox_env }}
136+
env:
137+
UV_PYTHON_PREFERENCE: "only-managed"

pyproject.toml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies = [
4242
"openapi-spec-validator>=0.2.8,<0.7",
4343
"packaging",
4444
"prance>=0.18.2",
45-
"pydantic>=1.10",
45+
"pydantic>=1.5",
4646
"pysnooper>=0.4.1,<2",
4747
"pyyaml>=6.0.1",
4848
"tomli>=2.2.1,<3; python_version<='3.11'",
@@ -75,6 +75,7 @@ test = [
7575
"pytest-cov>=5",
7676
"pytest-mock>=3.14",
7777
"pytest-xdist>=3.3.1",
78+
"setuptools; python_version<'3.9'",
7879
]
7980
type = [
8081
"pyright>=1.1.393",
@@ -88,6 +89,12 @@ docs = [
8889
"mkdocs>=1.6",
8990
"mkdocs-material>=9.5.31",
9091
]
92+
black19-pydantic18 = [ "black==19.10b0", "pydantic==1.8.2" ]
93+
black22 = [ "black==22.1" ]
94+
black23 = [ "black==23.12" ]
95+
black24 = [ "black==24.1" ]
96+
pydantic18 = [ "pydantic==1.8.2" ]
97+
isort4-pydantic15 = [ "isort[pyproject]==4.3.21", "pydantic==1.5.1" ]
9198
fix = [ "pre-commit>=3.5" ]
9299
pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.22" ]
93100
coverage = [
@@ -128,14 +135,16 @@ filterwarnings = [
128135
"ignore:^.*Field name `name` is duplicated on Pet.*",
129136
"ignore:^.*format of 'unknown-type' not understood for 'string' - using default.*",
130137
"ignore:^.*unclosed file.*",
131-
138+
"ignore:^.*black doesn't support `experimental-string-processing` option for wrapping string literal in .*",
139+
"ignore:^.*jsonschema.exceptions.RefResolutionError is deprecated as of version 4.18.0. If you wish to catch potential reference resolution errors, directly catch referencing.exceptions.Unresolvable..*",
140+
"ignore:^.*`experimental string processing` has been included in `preview` and deprecated. Use `preview` instead..*",
132141
]
133142
norecursedirs = "tests/data/*"
134143

135144
[tool.coverage]
136145
run.source = [ "datamodel_code_generator" ]
137146
run.branch = true
138-
run.omit = [ "scripts/*" ]
147+
run.omit = [ "scripts/*", "tests/*" ]
139148
report.ignore_errors = true
140149
report.exclude_lines = [
141150
"if self.debug:",
@@ -145,11 +154,39 @@ report.exclude_lines = [
145154
"if TYPE_CHECKING:",
146155
"if not TYPE_CHECKING:",
147156
]
148-
report.omit = [ "tests/*" ]
157+
paths.source = [
158+
"datamodel_code_generator",
159+
".tox*/*/lib/python*/site-packages/datamodel_code_generator",
160+
".tox*\\*\\Lib\\site-packages/datamodel_code_generator",
161+
"*/datamodel_code_generator",
162+
"*\\datamodel_code_generator",
163+
]
149164

150165
[tool.pyright]
151166
reportPrivateImportUsage = false
152167

153168
[tool.pydantic-pycharm-plugin]
154169
ignore-init-method-arguments = true
155170
parsable-types.str = [ "int", "float" ]
171+
172+
[tool.uv]
173+
conflicts = [
174+
[
175+
{ group = "black24" },
176+
{ group = "black22" },
177+
{ group = "black23" },
178+
{ group = "black19-pydantic18" },
179+
{ group = "pydantic18" },
180+
{ group = "isort4-pydantic15" },
181+
{ group = "pkg-meta" },
182+
],
183+
[
184+
{ group = "black24" },
185+
{ group = "black22" },
186+
{ group = "black23" },
187+
{ group = "black19-pydantic18" },
188+
{ group = "pydantic18" },
189+
{ group = "isort4-pydantic15" },
190+
{ group = "dev" },
191+
],
192+
]

tests/main/openapi/test_main_openapi.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ def test_main_modular_filename(tmpdir_factory: TempdirFactory) -> None:
282282
)
283283

284284

285-
def test_main_openapi_no_file(capsys: CaptureFixture) -> None:
285+
def test_main_openapi_no_file(
286+
capsys: CaptureFixture, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
287+
) -> None:
286288
"""Test main function on non-modular file with no output name."""
287-
289+
monkeypatch.chdir(tmp_path)
288290
input_filename = OPEN_API_DATA_PATH / 'api.yaml'
289291

290292
with freeze_time(TIMESTAMP):
@@ -313,10 +315,15 @@ def test_main_openapi_no_file(capsys: CaptureFixture) -> None:
313315
reason="Installed black doesn't support the old style",
314316
)
315317
def test_main_openapi_extra_template_data_config(
316-
capsys: CaptureFixture, output_model, expected_output
318+
capsys: CaptureFixture,
319+
output_model,
320+
expected_output,
321+
tmp_path: Path,
322+
monkeypatch: pytest.MonkeyPatch,
317323
) -> None:
318324
"""Test main function with custom config data in extra template."""
319325

326+
monkeypatch.chdir(tmp_path)
320327
input_filename = OPEN_API_DATA_PATH / 'api.yaml'
321328
extra_template_data = OPEN_API_DATA_PATH / 'extra_data.json'
322329

@@ -337,9 +344,12 @@ def test_main_openapi_extra_template_data_config(
337344
assert captured.err == inferred_message.format('openapi') + '\n'
338345

339346

340-
def test_main_custom_template_dir_old_style(capsys: CaptureFixture) -> None:
347+
def test_main_custom_template_dir_old_style(
348+
capsys: CaptureFixture, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
349+
) -> None:
341350
"""Test main function with custom template directory."""
342351

352+
monkeypatch.chdir(tmp_path)
343353
input_filename = OPEN_API_DATA_PATH / 'api.yaml'
344354
custom_template_dir = DATA_PATH / 'templates_old_style'
345355
extra_template_data = OPEN_API_DATA_PATH / 'extra_data.json'
@@ -363,7 +373,10 @@ def test_main_custom_template_dir_old_style(capsys: CaptureFixture) -> None:
363373
assert captured.err == inferred_message.format('openapi') + '\n'
364374

365375

366-
def test_main_openapi_custom_template_dir(capsys: CaptureFixture) -> None:
376+
def test_main_openapi_custom_template_dir(
377+
capsys: CaptureFixture, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
378+
) -> None:
379+
monkeypatch.chdir(tmp_path)
367380
"""Test main function with custom template directory."""
368381

369382
input_filename = OPEN_API_DATA_PATH / 'api.yaml'

tests/parser/test_jsonschema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ def test_parse_array_schema():
377377
)
378378

379379

380-
def test_parse_nested_array():
380+
def test_parse_nested_array(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
381+
monkeypatch.chdir(tmp_path)
381382
parser = JsonSchemaParser(
382383
DATA_PATH / 'nested_array.json',
383384
data_model_field_type=DataModelFieldBase,

0 commit comments

Comments
 (0)