Skip to content

Commit 4ce6b04

Browse files
authored
Merge pull request #48 from opsmill/fac-merge-stable
Merge stable into develop
2 parents 352e6ec + ad77743 commit 4ce6b04

File tree

12 files changed

+131
-44
lines changed

12 files changed

+131
-44
lines changed

.github/workflows/publish-python-sdk.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Publish Infrahub Python SDK
44
on: # yamllint disable rule:truthy
55
push:
66
tags:
7-
- "python-sdk-v*"
7+
- "v*"
88

99
jobs:
1010
publish_to_pypi:
@@ -14,7 +14,7 @@ jobs:
1414
- name: "Set up Python"
1515
uses: "actions/setup-python@v5"
1616
with:
17-
python-version: "3.11"
17+
python-version: "3.12"
1818

1919
- name: "Install Poetry"
2020
uses: "snok/install-poetry@v1"
@@ -35,20 +35,16 @@ jobs:
3535

3636
- name: "Install Dependencies"
3737
run: "poetry install"
38-
working-directory: "./python_sdk"
3938
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
4039

4140
- name: "Add PyPI secret"
4241
run: "poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}"
4342

4443
- name: "Poetry build"
4544
run: "poetry build"
46-
working-directory: "./python_sdk"
4745

4846
- name: "show output"
4947
run: "ls -la dist/"
50-
working-directory: "./python_sdk"
5148

5249
- name: "Poetry push PyPI"
5350
run: "poetry publish"
54-
working-directory: "./python_sdk"

.gitignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ coverage.xml
66
script.py
77
**/*.local.*
88
.vscode/settings.json
9-
node_modules/*
10-
development/docker-compose.override.yml
11-
development/docker-compose.dev-override.yml
129
.DS_Store
1310
.python-version
1411
.ruff_cache
@@ -23,13 +20,11 @@ docs/build
2320

2421
storage/*
2522
.coverage.*
26-
python_sdk/dist/*
23+
dist/*
2724
.benchmarks/*
2825

2926
# Test reports
3027
**/*.csv
3128

3229
# Generated files
33-
generated/
34-
query_performance_results/
35-
sync/dist/
30+
generated/

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1010
This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/opsmill/infrahub/tree/develop/infrahub/python_sdk/changelog/>.
1111

1212
<!-- towncrier release notes start -->
13+
14+
## [0.13.1.dev0](https://github.com/opsmill/infrahub-sdk-python/tree/v0.13.1.dev0) - 2024-09-24
15+
16+
### Added
17+
18+
- Allow id filters to be combined when executing a query ([#3](https://github.com/opsmill/infrahub-sdk-python/issues/3))
19+
20+
### Fixed
21+
22+
- Add ability to construct HFIDs from payload for upsert mutations ([#45](https://github.com/opsmill/infrahub-sdk-python/issues/45))
23+
- Fix pytest plugin integration tests unable to run because we were not properly setting the api_token configuration setting for the SDK.

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11

2-
> ⚠️ **Warning**
3-
> This repository is still a WORK IN PROGRESS. Soon it will be the new home of the Python SDK for Infrahub but for now the project still lives in the main repository
4-
</br>
5-
62
<!-- markdownlint-disable -->
73
![Infrahub Logo](https://assets-global.website-files.com/657aff4a26dd8afbab24944b/657b0e0678f7fd35ce130776_Logo%20INFRAHUB.svg)
84
<!-- markdownlint-restore -->

changelog/46.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`execute_graphql` method for InfrahubClient(Sync) now properly considers the `default_branch` setting

infrahub_sdk/client.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ async def get(
486486
filters[schema.default_filter] = id
487487
else:
488488
filters["ids"] = [id]
489-
elif hfid:
489+
if hfid:
490490
if isinstance(schema, NodeSchema) and schema.human_friendly_id:
491491
filters["hfid"] = hfid
492492
else:
493493
raise ValueError("Cannot filter by HFID if the node doesn't have an HFID defined")
494-
elif kwargs:
495-
filters = kwargs
496-
else:
494+
if kwargs:
495+
filters.update(kwargs)
496+
if len(filters) == 0:
497497
raise ValueError("At least one filter must be provided to get()")
498498

499499
results = await self.filters(
@@ -777,6 +777,7 @@ async def execute_graphql(
777777
_type_: _description_
778778
"""
779779

780+
branch_name = branch_name or self.default_branch
780781
url = self._graphql_url(branch_name=branch_name, at=at)
781782

782783
payload: dict[str, Union[str, dict]] = {"query": query}
@@ -1520,6 +1521,7 @@ def execute_graphql(
15201521
dict: The result of the GraphQL query or mutation.
15211522
"""
15221523

1524+
branch_name = branch_name or self.default_branch
15231525
url = self._graphql_url(branch_name=branch_name, at=at)
15241526

15251527
payload: dict[str, Union[str, dict]] = {"query": query}
@@ -1927,14 +1929,14 @@ def get(
19271929
filters[schema.default_filter] = id
19281930
else:
19291931
filters["ids"] = [id]
1930-
elif hfid:
1932+
if hfid:
19311933
if isinstance(schema, NodeSchema) and schema.human_friendly_id:
19321934
filters["hfid"] = hfid
19331935
else:
19341936
raise ValueError("Cannot filter by HFID if the node doesn't have an HFID defined")
1935-
elif kwargs:
1936-
filters = kwargs
1937-
else:
1937+
if kwargs:
1938+
filters.update(kwargs)
1939+
if len(filters) == 0:
19381940
raise ValueError("At least one filter must be provided to get()")
19391941

19401942
results = self.filters(

infrahub_sdk/node.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,11 @@ def get_human_friendly_id(self) -> Optional[list[str]]:
724724
if not self._schema.human_friendly_id:
725725
return None
726726

727-
# If all components of an HFID are null, we cannot identify a single node
727+
# If an HFID component is missing we assume that it is invalid and not usable for this node
728728
hfid_components = [self.get_path_value(path=item) for item in self._schema.human_friendly_id]
729-
if all(c is None for c in hfid_components):
729+
if None in hfid_components:
730730
return None
731-
732-
return [str(c) for c in hfid_components]
731+
return [str(hfid) for hfid in hfid_components]
733732

734733
def get_human_friendly_id_as_string(self, include_kind: bool = False) -> Optional[str]:
735734
hfid = self.get_human_friendly_id()

infrahub_sdk/pytest_plugin/plugin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23
from typing import Optional, Union
34

@@ -34,6 +35,7 @@ def pytest_addoption(parser: Parser) -> None:
3435
action="store",
3536
dest="infrahub_key",
3637
metavar="INFRAHUB_TESTS_API_KEY",
38+
default=os.getenv("INFRAHUB_API_TOKEN"),
3739
help="Key to use when querying the Infrahub instance for live testing",
3840
)
3941
group.addoption(
@@ -74,12 +76,11 @@ def pytest_sessionstart(session: Session) -> None:
7476
"default_branch": session.config.option.infrahub_branch,
7577
}
7678
if hasattr(session.config.option, "infrahub_key"):
77-
client_config = {"api_token": session.config.option.infrahub_key}
79+
client_config["api_token"] = session.config.option.infrahub_key
7880
elif hasattr(session.config.option, "infrahub_username") and hasattr(session.config.option, "infrahub_password"):
79-
client_config = {
80-
"username": session.config.option.infrahub_username,
81-
"password": session.config.option.infrahub_password,
82-
}
81+
client_config.pop("api_token")
82+
client_config["username"] = session.config.option.infrahub_username
83+
client_config["password"] = session.config.option.infrahub_password
8384

8485
infrahub_client = InfrahubClientSync(config=client_config)
8586
session.infrahub_client = infrahub_client # type: ignore[attr-defined]

poetry.lock

Lines changed: 89 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ruff = "0.5.0"
6464
pytest-xdist = "^3.3.1"
6565
types-python-slugify = "^8.0.0.3"
6666
invoke = "^2.2.0"
67+
towncrier = "^24.8.0"
6768

6869
[tool.poetry.extras]
6970
ctl = ["Jinja2", "numpy", "pyarrow", "pyyaml", "rich", "toml", "typer"]
@@ -346,7 +347,7 @@ max-complexity = 17
346347

347348
[tool.towncrier]
348349

349-
package = "infrahub-sdk"
350+
package = "infrahub_sdk"
350351
directory = "changelog"
351352
filename = "CHANGELOG.md"
352353
start_string = "<!-- towncrier release notes start -->\n"

0 commit comments

Comments
 (0)