Skip to content

Commit adf0c28

Browse files
committed
Move client generation to pixi
1 parent 01042de commit adf0c28

File tree

5 files changed

+52
-74
lines changed

5 files changed

+52
-74
lines changed

diracx-testing/src/diracx/testing/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
fernet_key,
1414
private_key_pem,
1515
pytest_addoption,
16-
pytest_collection_modifyitems,
1716
session_client_factory,
1817
test_auth_settings,
1918
test_dev_settings,
@@ -29,7 +28,6 @@
2928
"do_device_flow_with_dex",
3029
"test_login",
3130
"pytest_addoption",
32-
"pytest_collection_modifyitems",
3331
"private_key_pem",
3432
"fernet_key",
3533
"test_dev_settings",

diracx-testing/src/diracx/testing/client_generation.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33
__all__ = [
44
"regenerate_client",
5-
"AUTOREST_VERSION",
65
]
76

7+
import argparse
88
import ast
99
import importlib.util
10+
import shlex
1011
import subprocess
12+
import sys
1113
from pathlib import Path
1214

1315
import git
1416

15-
AUTOREST_VERSION = "6.13.7"
17+
AUTOREST_VERSION = "3.7.1"
18+
AUTOREST_CORE_VERSION = "3.10.4"
19+
AUTOREST_PUGINS = {
20+
"@autorest/python": "6.34.1",
21+
"@autorest/modelerfour": "4.23.7",
22+
}
1623

1724

1825
def extract_static_all(path):
@@ -109,20 +116,17 @@ def regenerate_client(openapi_spec: Path, client_module: str):
109116
"Client is currently in a modified state, skipping regeneration"
110117
)
111118

112-
cmd = [
113-
"autorest",
119+
cmd = ["autorest", f"--version={AUTOREST_CORE_VERSION}"]
120+
for plugin, version in AUTOREST_PUGINS.items():
121+
cmd.append(f"--use={plugin}@{version}")
122+
cmd += [
114123
"--python",
115124
f"--input-file={openapi_spec}",
116125
"--models-mode=msrest",
117126
"--namespace=_generated",
118127
f"--output-folder={client_root}",
119128
]
120129

121-
# This is required to be able to work offline
122-
# TODO: if offline, find the version already installed
123-
# and use it
124-
# cmd += [f"--use=@autorest/python@{AUTOREST_VERSION}"]
125-
126130
# ruff: disable=S603
127131
subprocess.run(cmd, check=True)
128132

@@ -154,3 +158,35 @@ def regenerate_client(openapi_spec: Path, client_module: str):
154158
if proc.returncode != 0:
155159
raise AssertionError("Pre-commit failed")
156160
raise AssertionError("Client was regenerated with changes")
161+
162+
163+
def main():
164+
from diracx.core.extensions import extensions_by_priority
165+
166+
parser = argparse.ArgumentParser(
167+
description="Regenerate the AutoREST client and run pre-commit checks on it."
168+
)
169+
parser.parse_args()
170+
171+
client_extension_name = min(extensions_by_priority(), key=lambda x: x == "diracx")
172+
173+
cmd = ["npm", "install", "-g", f"autorest@{AUTOREST_VERSION}"]
174+
print("Ensuring autorest is installed by running", shlex.join(cmd))
175+
subprocess.run(cmd, check=True)
176+
177+
cmd = [
178+
sys.executable,
179+
"-m",
180+
"pytest",
181+
"-pdiracx.testing",
182+
"--import-mode=importlib",
183+
f"--regenerate-client={client_extension_name}",
184+
str(Path(__file__).parent / "client_generation_pytest.py"),
185+
]
186+
print("Generating client for", client_extension_name)
187+
print("Running:", shlex.join(cmd))
188+
subprocess.run(cmd, check=True)
189+
190+
191+
if __name__ == "__main__":
192+
main()

diracx-client/tests/test_regenerate.py renamed to diracx-testing/src/diracx/testing/client_generation_pytest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from diracx.testing.client_generation import AUTOREST_VERSION, regenerate_client
5+
from diracx.testing.client_generation import regenerate_client
66

77
pytestmark = pytest.mark.enabled_dependencies([])
88

@@ -13,7 +13,7 @@ def test_client(client_factory):
1313
yield client
1414

1515

16-
def test_regenerate_client(test_client, tmp_path):
16+
def test_regenerate_client(test_client, tmp_path, request):
1717
"""Regenerate the AutoREST client and run pre-commit checks on it.
1818
1919
This test is skipped by default, and can be enabled by passing
@@ -25,13 +25,13 @@ def test_regenerate_client(test_client, tmp_path):
2525
2626
WARNING: This test will modify the source code of the client!
2727
"""
28+
client_name = request.config.getoption("--regenerate-client")
29+
if client_name is None:
30+
pytest.skip("--regenerate-client not specified")
31+
2832
r = test_client.get("/api/openapi.json")
2933
r.raise_for_status()
3034
openapi_spec = tmp_path / "openapi.json"
3135
openapi_spec.write_text(r.text)
3236

33-
regenerate_client(openapi_spec, "diracx.client")
34-
35-
36-
if __name__ == "__main__":
37-
print(AUTOREST_VERSION)
37+
regenerate_client(openapi_spec, f"{client_name}.client")

diracx-testing/src/diracx/testing/utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
def pytest_addoption(parser):
4444
parser.addoption(
4545
"--regenerate-client",
46-
action="store_true",
47-
default=False,
4846
help="Regenerate the AutoREST client",
4947
)
5048
parser.addoption(
@@ -55,17 +53,6 @@ def pytest_addoption(parser):
5553
)
5654

5755

58-
def pytest_collection_modifyitems(config, items):
59-
"""Disable the test_regenerate_client if not explicitly asked for."""
60-
if config.getoption("--regenerate-client"):
61-
# --regenerate-client given in cli: allow client re-generation
62-
return
63-
skip_regen = pytest.mark.skip(reason="need --regenerate-client option to run")
64-
for item in items:
65-
if item.name == "test_regenerate_client":
66-
item.add_marker(skip_regen)
67-
68-
6956
@pytest.fixture(scope="session")
7057
def private_key_pem() -> str:
7158
from cryptography.hazmat.primitives import serialization

extensions/gubbins/gubbins-client/tests/test_regenerate.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)