Skip to content

Commit 8622520

Browse files
authored
Merge branch 'develop' into atg-20250103-ihs-55
2 parents 5a31ff5 + 60d001e commit 8622520

31 files changed

+933
-485
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: "Check out repository code"
7676
uses: "actions/checkout@v4"
7777
- name: "Setup environment"
78-
run: "pip install ruff==0.7.1"
78+
run: "pip install ruff==0.8.6"
7979
- name: "Linting: ruff check"
8080
run: "ruff check ."
8181
- name: "Linting: ruff format"
@@ -141,7 +141,7 @@ jobs:
141141
python-version: ${{ matrix.python-version }}
142142
- name: "Setup environment"
143143
run: |
144-
pipx install poetry
144+
pipx install poetry==1.8.5
145145
poetry config virtualenvs.prefer-active-python true
146146
pip install invoke toml codecov
147147
- name: "Install Package"
@@ -192,7 +192,7 @@ jobs:
192192
python-version: "3.12"
193193
- name: "Setup environment"
194194
run: |
195-
pipx install poetry
195+
pipx install poetry==1.8.5
196196
poetry config virtualenvs.prefer-active-python true
197197
pip install invoke toml codecov
198198
- name: "Install Package"

.github/workflows/publish-pypi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- name: "Install Poetry"
4242
uses: "snok/install-poetry@v1"
4343
with:
44+
version: 1.8.5
4445
virtualenvs-create: true
4546
virtualenvs-in-project: true
4647
installer-parallel: true

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: "Install Poetry"
3131
uses: "snok/install-poetry@v1"
3232
with:
33+
version: 1.8.5
3334
virtualenvs-create: true
3435
virtualenvs-in-project: true
3536
installer-parallel: true
@@ -56,7 +57,7 @@ jobs:
5657
| jq -r '.tag_name') >> "$GITHUB_OUTPUT"
5758
5859
- name: Check tag version
59-
if: github.event.release.tag_name != format('infrahub-v{0}', steps.release.outputs.version)
60+
if: github.event.release.tag_name != format('v{0}', steps.release.outputs.version)
6061
run: |
6162
echo "Tag version does not match python project version"
6263
exit 1

CHANGELOG.md

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

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

14+
## [1.4.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.3.0) - 2025-01-05
15+
16+
### Fixed
17+
18+
- Fixes an issue introduced in 1.4 that would prevent a node with relationship of cardinality one from being updated.
19+
20+
## [1.4.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.4.0) - 2025-01-03
21+
22+
### Changed
23+
24+
- The inclusion of properties for Attribute and Relationships by default has been disabled when querying nodes from Infrahub.
25+
it can be enabled by using the parameter `property` in `client.get|all|filters` method ([#191](https://github.com/opsmill/infrahub-sdk-python/issues/191))
26+
- Fix an issue with python-transform-unit-process failing to run ([#198](https://github.com/opsmill/infrahub-sdk-python/issues/198))
27+
- Add processing of nodes when no variable are passed into the command to run generators ([#176](https://github.com/opsmill/infrahub-sdk-python/issues/176))
28+
1429
## [1.3.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.3.0) - 2024-12-30
1530

1631
### Added

changelog/158.added.me

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `count` method to both sync and async clients to retrieve the number of objects of a given kind

changelog/191.changed.md

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

infrahub_sdk/branch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class BranchData(BaseModel):
4040

4141

4242
MUTATION_QUERY_DATA = {"ok": None, "object": BRANCH_DATA}
43+
MUTATION_QUERY_TASK = {"ok": None, "task": {"id": None}}
4344

4445
QUERY_ALL_BRANCHES_DATA = {"Branch": BRANCH_DATA}
4546

@@ -119,13 +120,14 @@ async def create(
119120
},
120121
}
121122

122-
query = Mutation(mutation="BranchCreate", input_data=input_data, query=MUTATION_QUERY_DATA)
123+
mutation_query = MUTATION_QUERY_TASK if background_execution else MUTATION_QUERY_DATA
124+
query = Mutation(mutation="BranchCreate", input_data=input_data, query=mutation_query)
123125
response = await self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")
124126

125127
# Make sure server version is recent enough to support background execution, as previously
126128
# using background_execution=True had no effect.
127129
if background_execution and "task" in response["BranchCreate"]:
128-
return BranchData(**response["BranchCreate"]["task"]["id"])
130+
return response["BranchCreate"]["task"]["id"]
129131
return BranchData(**response["BranchCreate"]["object"])
130132

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

infrahub_sdk/checks.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
from git.repo import Repo
1212
from pydantic import BaseModel, Field
1313

14-
from .exceptions import InfrahubCheckNotFoundError, UninitializedError
14+
from .exceptions import UninitializedError
1515

1616
if TYPE_CHECKING:
17-
from pathlib import Path
18-
1917
from . import InfrahubClient
20-
from .schema.repository import InfrahubCheckDefinitionConfig
2118

2219
INFRAHUB_CHECK_VARIABLE_TO_IMPORT = "INFRAHUB_CHECKS"
2320

@@ -176,27 +173,3 @@ async def run(self, data: dict | None = None) -> bool:
176173
self.log_info("Check succesfully completed")
177174

178175
return self.passed
179-
180-
181-
def get_check_class_instance(
182-
check_config: InfrahubCheckDefinitionConfig, search_path: Path | None = None
183-
) -> InfrahubCheck:
184-
if check_config.file_path.is_absolute() or search_path is None:
185-
search_location = check_config.file_path
186-
else:
187-
search_location = search_path / check_config.file_path
188-
189-
try:
190-
spec = importlib.util.spec_from_file_location(check_config.class_name, search_location)
191-
module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
192-
spec.loader.exec_module(module) # type: ignore[union-attr]
193-
194-
# Get the specified class from the module
195-
check_class = getattr(module, check_config.class_name)
196-
197-
# Create an instance of the class
198-
check_instance = check_class()
199-
except (FileNotFoundError, AttributeError) as exc:
200-
raise InfrahubCheckNotFoundError(name=check_config.name) from exc
201-
202-
return check_instance

infrahub_sdk/client.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
from types import TracebackType
5959

6060

61-
# pylint: disable=redefined-builtin disable=too-many-lines
62-
6361
SchemaType = TypeVar("SchemaType", bound=CoreNode)
6462
SchemaTypeSync = TypeVar("SchemaTypeSync", bound=CoreNodeSync)
6563

@@ -543,6 +541,25 @@ async def _process_nodes_and_relationships(
543541

544542
return ProcessRelationsNode(nodes=nodes, related_nodes=related_nodes)
545543

544+
async def count(
545+
self,
546+
kind: str | type[SchemaType],
547+
at: Timestamp | None = None,
548+
branch: str | None = None,
549+
timeout: int | None = None,
550+
) -> int:
551+
"""Return the number of nodes of a given kind."""
552+
schema = await self.schema.get(kind=kind, branch=branch)
553+
554+
branch = branch or self.default_branch
555+
if at:
556+
at = Timestamp(at)
557+
558+
response = await self.execute_graphql(
559+
query=Query(query={schema.kind: {"count": None}}).render(), branch_name=branch, at=at, timeout=timeout
560+
)
561+
return int(response.get(schema.kind, {}).get("count", 0))
562+
546563
@overload
547564
async def all(
548565
self,
@@ -727,7 +744,7 @@ async def filters(
727744
fragment=fragment,
728745
prefetch_relationships=prefetch_relationships,
729746
partial_match=partial_match,
730-
# property=property,
747+
property=property,
731748
)
732749
query = Query(query=query_data)
733750
response = await self.execute_graphql(
@@ -1163,7 +1180,7 @@ async def allocate_next_ip_address(
11631180
async def allocate_next_ip_address(
11641181
self,
11651182
resource_pool: CoreNode,
1166-
kind: type[SchemaType] | None = None, # pylint: disable=unused-argument
1183+
kind: type[SchemaType] | None = None, # noqa: ARG002
11671184
identifier: str | None = None,
11681185
prefix_length: int | None = None,
11691186
address_type: str | None = None,
@@ -1313,7 +1330,7 @@ async def allocate_next_ip_prefix(
13131330
async def allocate_next_ip_prefix(
13141331
self,
13151332
resource_pool: CoreNode,
1316-
kind: type[SchemaType] | None = None, # pylint: disable=unused-argument
1333+
kind: type[SchemaType] | None = None, # noqa: ARG002
13171334
identifier: str | None = None,
13181335
prefix_length: int | None = None,
13191336
member_type: str | None = None,
@@ -1583,6 +1600,25 @@ def execute_graphql(
15831600

15841601
# TODO add a special method to execute mutation that will check if the method returned OK
15851602

1603+
def count(
1604+
self,
1605+
kind: str | type[SchemaType],
1606+
at: Timestamp | None = None,
1607+
branch: str | None = None,
1608+
timeout: int | None = None,
1609+
) -> int:
1610+
"""Return the number of nodes of a given kind."""
1611+
schema = self.schema.get(kind=kind, branch=branch)
1612+
1613+
branch = branch or self.default_branch
1614+
if at:
1615+
at = Timestamp(at)
1616+
1617+
response = self.execute_graphql(
1618+
query=Query(query={schema.kind: {"count": None}}).render(), branch_name=branch, at=at, timeout=timeout
1619+
)
1620+
return int(response.get(schema.kind, {}).get("count", 0))
1621+
15861622
@overload
15871623
def all(
15881624
self,
@@ -2213,7 +2249,7 @@ def allocate_next_ip_address(
22132249
def allocate_next_ip_address(
22142250
self,
22152251
resource_pool: CoreNodeSync,
2216-
kind: type[SchemaTypeSync] | None = None, # pylint: disable=unused-argument
2252+
kind: type[SchemaTypeSync] | None = None, # noqa: ARG002
22172253
identifier: str | None = None,
22182254
prefix_length: int | None = None,
22192255
address_type: str | None = None,
@@ -2359,7 +2395,7 @@ def allocate_next_ip_prefix(
23592395
def allocate_next_ip_prefix(
23602396
self,
23612397
resource_pool: CoreNodeSync,
2362-
kind: type[SchemaTypeSync] | None = None, # pylint: disable=unused-argument
2398+
kind: type[SchemaTypeSync] | None = None, # noqa: ARG002
23632399
identifier: str | None = None,
23642400
prefix_length: int | None = None,
23652401
member_type: str | None = None,

infrahub_sdk/ctl/branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def create(
8383
sync_with_git: bool = typer.Option(
8484
False, help="Extend the branch to Git and have Infrahub create the branch in connected repositories."
8585
),
86-
isolated: bool = typer.Option(True, hidden=True, help="Set the branch to isolated mode (deprecated)"), # pylint: disable=unused-argument
86+
isolated: bool = typer.Option(True, hidden=True, help="Set the branch to isolated mode (deprecated)"), # noqa: ARG001
8787
_: str = CONFIG_PARAM,
8888
) -> None:
8989
"""Create a new branch."""

0 commit comments

Comments
 (0)