Skip to content

Commit bab312d

Browse files
authored
Merge pull request #156 from opsmill/develop
Merge develop into stable
2 parents b32796f + 08f2762 commit bab312d

27 files changed

+327
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: "Check out repository code"
9292
uses: "actions/checkout@v4"
9393
- name: "Linting: markdownlint"
94-
uses: DavidAnson/markdownlint-cli2-action@v17
94+
uses: DavidAnson/markdownlint-cli2-action@v18
9595
with:
9696
config: .markdownlint.yaml
9797
globs: |

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang
1111

1212
<!-- towncrier release notes start -->
1313

14+
## [1.1.0rc0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.1.0rc0) - 2024-11-26
15+
16+
### Fixed
17+
18+
- CTL: `schema load` return a proper error message when authentication is missing or when the user doesn't have the permission to update the schema. ([#127](https://github.com/opsmill/infrahub-sdk-python/issues/127))
19+
- CTL: List available transforms and generators if no name is provided ([#140](https://github.com/opsmill/infrahub-sdk-python/issues/140))
20+
1421
## [1.0.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.0.1) - 2024-11-12
1522

1623
### Removed

changelog/+0e61a54f.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added InfrahubClient.schema.wait_until_converged() which allowes you to wait until the schema has converged across all Infrahub workers before proceeding with an operation. The InfrahubClient.schema.load() method has also been updated with a new parameter "wait_until_converged".

changelog/140.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CTL: List available transforms and generators if no name is provided

infrahub_sdk/batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
from collections.abc import AsyncGenerator, Awaitable
23
from dataclasses import dataclass
3-
from typing import Any, AsyncGenerator, Awaitable, Callable, Optional
4+
from typing import Any, Callable, Optional
45

56
from .node import InfrahubNode
67

infrahub_sdk/branch.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Optional, Union
3+
import warnings
4+
from typing import TYPE_CHECKING, Any, Literal, Optional, Union, overload
45
from urllib.parse import urlencode
56

67
from pydantic import BaseModel
@@ -72,14 +73,44 @@ class InfrahubBranchManager(InfraHubBranchManagerBase):
7273
def __init__(self, client: InfrahubClient):
7374
self.client = client
7475

76+
@overload
7577
async def create(
7678
self,
7779
branch_name: str,
7880
sync_with_git: bool = True,
7981
description: str = "",
80-
background_execution: bool = False,
81-
) -> BranchData:
82+
wait_until_completion: Literal[True] = True,
83+
background_execution: Optional[bool] = False,
84+
) -> BranchData: ...
85+
86+
@overload
87+
async def create(
88+
self,
89+
branch_name: str,
90+
sync_with_git: bool = True,
91+
description: str = "",
92+
wait_until_completion: Literal[False] = False,
93+
background_execution: Optional[bool] = False,
94+
) -> str: ...
95+
96+
async def create(
97+
self,
98+
branch_name: str,
99+
sync_with_git: bool = True,
100+
description: str = "",
101+
wait_until_completion: bool = True,
102+
background_execution: Optional[bool] = False,
103+
) -> Union[BranchData, str]:
104+
if background_execution is not None:
105+
warnings.warn(
106+
"`background_execution` is deprecated, please use `wait_until_completion` instead.",
107+
DeprecationWarning,
108+
stacklevel=1,
109+
)
110+
111+
background_execution = background_execution or not wait_until_completion
82112
input_data = {
113+
# Should be switched to `wait_until_completion` once `background_execution` is removed server side.
83114
"background_execution": background_execution,
84115
"data": {
85116
"name": branch_name,
@@ -91,6 +122,10 @@ async def create(
91122
query = Mutation(mutation="BranchCreate", input_data=input_data, query=MUTATION_QUERY_DATA)
92123
response = await self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")
93124

125+
# Make sure server version is recent enough to support background execution, as previously
126+
# using background_execution=True had no effect.
127+
if background_execution and "task" in response["BranchCreate"]:
128+
return BranchData(**response["BranchCreate"]["task"]["id"])
94129
return BranchData(**response["BranchCreate"]["object"])
95130

96131
async def delete(self, branch_name: str) -> bool:
@@ -209,14 +244,44 @@ def get(self, branch_name: str) -> BranchData:
209244
raise BranchNotFoundError(identifier=branch_name)
210245
return BranchData(**data["Branch"][0])
211246

247+
@overload
248+
def create(
249+
self,
250+
branch_name: str,
251+
sync_with_git: bool = True,
252+
description: str = "",
253+
wait_until_completion: Literal[True] = True,
254+
background_execution: Optional[bool] = False,
255+
) -> BranchData: ...
256+
257+
@overload
258+
def create(
259+
self,
260+
branch_name: str,
261+
sync_with_git: bool = True,
262+
description: str = "",
263+
wait_until_completion: Literal[False] = False,
264+
background_execution: Optional[bool] = False,
265+
) -> str: ...
266+
212267
def create(
213268
self,
214269
branch_name: str,
215270
sync_with_git: bool = True,
216271
description: str = "",
217-
background_execution: bool = False,
218-
) -> BranchData:
272+
wait_until_completion: bool = True,
273+
background_execution: Optional[bool] = False,
274+
) -> Union[BranchData, str]:
275+
if background_execution is not None:
276+
warnings.warn(
277+
"`background_execution` is deprecated, please use `wait_until_completion` instead.",
278+
DeprecationWarning,
279+
stacklevel=1,
280+
)
281+
282+
background_execution = background_execution or not wait_until_completion
219283
input_data = {
284+
# Should be switched to `wait_until_completion` once `background_execution` is removed server side.
220285
"background_execution": background_execution,
221286
"data": {
222287
"name": branch_name,
@@ -228,6 +293,10 @@ def create(
228293
query = Mutation(mutation="BranchCreate", input_data=input_data, query=MUTATION_QUERY_DATA)
229294
response = self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")
230295

296+
# Make sure server version is recent enough to support background execution, as previously
297+
# using background_execution=True had no effect.
298+
if background_execution and "task" in response["BranchCreate"]:
299+
return BranchData(**response["BranchCreate"]["task"]["id"])
231300
return BranchData(**response["BranchCreate"]["object"])
232301

233302
def delete(self, branch_name: str) -> bool:

infrahub_sdk/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import asyncio
44
import copy
55
import logging
6+
from collections.abc import Coroutine, MutableMapping
67
from functools import wraps
78
from time import sleep
89
from typing import (
910
TYPE_CHECKING,
1011
Any,
1112
Callable,
12-
Coroutine,
1313
Literal,
14-
MutableMapping,
1514
Optional,
1615
TypedDict,
1716
TypeVar,

infrahub_sdk/code_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Mapping, Optional
1+
from collections.abc import Mapping
2+
from typing import Any, Optional
23

34
import jinja2
45

infrahub_sdk/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class ConfigBase(BaseSettings):
5454
pagination_size: int = Field(default=50, description="Page size for queries to the server")
5555
retry_delay: int = Field(default=5, description="Number of seconds to wait until attempting a retry.")
5656
retry_on_failure: bool = Field(default=False, description="Retry operation in case of failure")
57+
schema_converge_timeout: int = Field(
58+
default=60, description="Number of seconds to wait for schema to have converged"
59+
)
5760
timeout: int = Field(default=60, description="Default connection timeout in seconds")
5861
transport: RequesterTransport = Field(
5962
default=RequesterTransport.HTTPX, description="Set an alternate transport using a predefined option"

infrahub_sdk/ctl/cli_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def render(
267267
variables_dict = parse_cli_vars(variables)
268268
repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))
269269

270-
if list_available:
270+
if list_available or not transform_name:
271271
list_jinja2_transforms(config=repository_config)
272272
return
273273

@@ -317,7 +317,7 @@ def transform(
317317
variables_dict = parse_cli_vars(variables)
318318
repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))
319319

320-
if list_available:
320+
if list_available or not transform_name:
321321
list_transforms(config=repository_config)
322322
return
323323

0 commit comments

Comments
 (0)