Skip to content

Merge stable into develop #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [1.12.2](https://github.com/opsmill/infrahub-sdk-python/tree/v1.12.2) - 2025-06-05

### Fixed

- fix bug in Timestamp.add by @ajtmccarty in [#403](https://github.com/opsmill/infrahub-sdk-python/pull/403)
- utils.py: improve file not found exception message by @granoe668 in [#425](https://github.com/opsmill/infrahub-sdk-python/pull/425)

### Changed

- Add partial_match to the client.count() by @BeArchiTek in [#411](https://github.com/opsmill/infrahub-sdk-python/pull/411)

### Housekeeping

- Loosen pinned requirement for `whenever` to allow versions from 0.7.2 up to but not including 0.8.0.
- Bump http-proxy-middleware from 2.0.7 to 2.0.9 in /docs by @dependabot in [#418](https://github.com/opsmill/infrahub-sdk-python/pull/418)

## [1.12.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.12.1) - 2025-05-12

### Changed
Expand Down
1 change: 0 additions & 1 deletion changelog/+26b92d23.housekeeping.md

This file was deleted.

3 changes: 2 additions & 1 deletion infrahub_sdk/pytest_plugin/items/python_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ujson
from httpx import HTTPStatusError

from ...node import InfrahubNode
from ..exceptions import OutputMatchError, PythonTransformDefinitionError
from ..models import InfrahubTestExpectedResult
from .base import InfrahubItem
Expand Down Expand Up @@ -41,7 +42,7 @@ def instantiate_transform(self) -> None:
)
client = self.session.infrahub_client # type: ignore[attr-defined]
# TODO: Look into seeing how a transform class may use the branch, but set as a empty string for the time being to keep current behaviour
self.transform_instance = transform_class(branch="", client=client)
self.transform_instance = transform_class(branch="", client=client, infrahub_node=InfrahubNode)

def run_transform(self, variables: dict[str, Any]) -> Any:
self.instantiate_transform()
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "infrahub-sdk"
version = "1.12.1"
version = "1.12.2"
description = "Python Client to interact with Infrahub"
authors = ["OpsMill <info@opsmill.com>"]
readme = "README.md"
Expand Down Expand Up @@ -35,7 +35,7 @@ numpy = [
{ version = "^1.26.2", optional = true, python = ">=3.12" },
]
pyarrow = { version = ">=14", optional = true }
rich = { version = "^13", optional = true }
rich = { version = ">=12, <14", optional = true }
toml = { version = "^0.10", optional = true }
typer = { version = "^0.12.3", optional = true }
pytest = { version = "*", optional = true }
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/pytest_plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,61 @@ def test_jinja2_transform_unexpected_output(pytester):

result = pytester.runpytest("--infrahub-repo-config=infrahub_config.yml")
result.assert_outcomes(failed=1)


def test_python_transform(pytester):
pytester.makefile(
".yml",
test_python_transform="""
---
version: "1.0"
infrahub_tests:
- resource: "PythonTransform"
resource_name: "device_config"
tests:
- name: "base_config"
expect: PASS
spec:
kind: "python-transform-unit-process"
directory: device_config/base_config
""",
)
pytester.makefile(
".yml",
infrahub_config="""
---
schemas:
- schemas/dcim.yml

python_transforms:
- name: device_config
class_name: "DeviceConfig"
file_path: "transforms/device_config.py"
""",
)
test_input = pytester.makefile(
".json", input='{"data": { "InfraDevice": { "edges": [ { "node": { "name": {"value": "atl1-edge1"} } } ] } } }'
)
test_output = pytester.makefile(".json", output='{"hostname": "atl1-edge1"}')
test_template = pytester.makefile(
".py",
device_config="""
from infrahub_sdk.transforms import InfrahubTransform

class DeviceConfig(InfrahubTransform):
query = "device_config"
async def transform(self, data):
return {"hostname": data["InfraDevice"]["edges"][0]["node"]["name"]["value"]}
""",
)

pytester.mkdir("device_config")
test_dir = pytester.mkdir("device_config/base_config")
pytester.run("mv", test_input, test_dir)
pytester.run("mv", test_output, test_dir)

transform_dir = pytester.mkdir("transforms")
pytester.run("mv", test_template, transform_dir)

result = pytester.runpytest("--infrahub-repo-config=infrahub_config.yml")
result.assert_outcomes(passed=1)