Skip to content

Commit 49116c8

Browse files
authored
Merge pull request #417 from opsmill/stable
Merge stable into develop
2 parents 7bda36c + 80b50f4 commit 49116c8

File tree

8 files changed

+205
-39
lines changed

8 files changed

+205
-39
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ env:
2929
METRICS_ENDPOINT: ${{ secrets.METRICS_ENDPOINT }}
3030

3131
jobs:
32-
# ------------------------------------------ Check Files Changes ------------------------------------------
32+
prepare-environment:
33+
uses: ./.github/workflows/define-versions.yml
34+
# ------------------------------------------ Check Files Changes ------------------------------------------
3335
files-changed:
3436
name: Detect which file has changed
3537
runs-on: ubuntu-latest
@@ -154,7 +156,7 @@ jobs:
154156
!contains(needs.*.result, 'failure') &&
155157
!contains(needs.*.result, 'cancelled') &&
156158
(needs.files-changed.outputs.python == 'true') || (needs.files-changed.outputs.documentation_generated == 'true')
157-
needs: ["files-changed", "yaml-lint", "python-lint"]
159+
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
158160
runs-on: "ubuntu-22.04"
159161
timeout-minutes: 5
160162
steps:
@@ -168,7 +170,7 @@ jobs:
168170
python-version: "3.12"
169171
- name: "Setup Python environment"
170172
run: |
171-
pipx install poetry==2.1
173+
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
172174
poetry config virtualenvs.create true --local
173175
poetry env use 3.12
174176
- name: "Install dependencies"
@@ -220,7 +222,7 @@ jobs:
220222
!contains(needs.*.result, 'failure') &&
221223
!contains(needs.*.result, 'cancelled') &&
222224
needs.files-changed.outputs.python == 'true'
223-
needs: ["files-changed", "yaml-lint", "python-lint"]
225+
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
224226
runs-on: ubuntu-latest
225227
timeout-minutes: 30
226228
steps:
@@ -232,7 +234,7 @@ jobs:
232234
python-version: ${{ matrix.python-version }}
233235
- name: "Setup environment"
234236
run: |
235-
pipx install poetry==2.1 --python python${{ matrix.python-version }}
237+
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }} --python python${{ matrix.python-version }}
236238
poetry config virtualenvs.create true --local
237239
pip install invoke toml codecov
238240
- name: "Install Package"
@@ -268,7 +270,7 @@ jobs:
268270
!contains(needs.*.result, 'failure') &&
269271
!contains(needs.*.result, 'cancelled') &&
270272
needs.files-changed.outputs.python == 'true'
271-
needs: ["files-changed", "yaml-lint", "python-lint"]
273+
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
272274
runs-on:
273275
group: "huge-runners"
274276
timeout-minutes: 30
@@ -285,7 +287,7 @@ jobs:
285287
echo "PYTEST_DEBUG_TEMPROOT=/var/lib/github/${RUNNER_NAME}/_temp" >> $GITHUB_ENV
286288
- name: "Setup environment"
287289
run: |
288-
pipx install poetry==2.1
290+
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
289291
poetry config virtualenvs.create true --local
290292
pip install invoke toml codecov
291293
- name: "Install Package"
@@ -308,7 +310,7 @@ jobs:
308310
# !contains(needs.*.result, 'cancelled') &&
309311
# needs.files-changed.outputs.python == 'true' &&
310312
# (github.base_ref == 'stable' || github.base_ref == 'develop')
311-
# needs: ["files-changed", "yaml-lint", "python-lint"]
313+
# needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
312314
# runs-on:
313315
# group: "huge-runners"
314316
# timeout-minutes: 30
@@ -358,7 +360,7 @@ jobs:
358360

359361
# - name: "Setup environment"
360362
# run: |
361-
# pipx install poetry==2.1
363+
# pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
362364
# poetry config virtualenvs.create true --local
363365
# pip install invoke toml codecov
364366

.github/workflows/define-versions.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
# yamllint disable rule:truthy rule:truthy rule:line-length
3+
name: "Define versions"
4+
on:
5+
workflow_call:
6+
outputs:
7+
POETRY_VERSION:
8+
value: "2.1.3"
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- run: "true"

.github/workflows/publish-pypi.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ on:
2929
default: false
3030

3131
jobs:
32+
prepare-environment:
33+
uses: ./.github/workflows/define-versions.yml
3234
publish_to_pypi:
3335
name: "Publish Infrahub SDK to PyPI"
3436
runs-on: "ubuntu-22.04"
37+
needs: prepare-environment
3538
steps:
3639
- name: "Set up Python"
3740
uses: "actions/setup-python@v5"
@@ -41,7 +44,7 @@ jobs:
4144
- name: "Install Poetry"
4245
uses: "snok/install-poetry@v1"
4346
with:
44-
version: 1.8.5
47+
version: ${{ needs.prepare-environment.outputs.POETRY_VERSION }}
4548
virtualenvs-create: true
4649
virtualenvs-in-project: true
4750
installer-parallel: true

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ on:
88
- published
99

1010
jobs:
11+
prepare-environment:
12+
uses: ./.github/workflows/define-versions.yml
1113
check_release:
1214
runs-on: ubuntu-22.04
15+
needs: prepare-environment
1316
outputs:
1417
is_prerelease: ${{ steps.release.outputs.is_prerelease }}
1518
is_devrelease: ${{ steps.release.outputs.is_devrelease }}
@@ -30,7 +33,7 @@ jobs:
3033
- name: "Install Poetry"
3134
uses: "snok/install-poetry@v1"
3235
with:
33-
version: 1.8.5
36+
version: ${{ needs.prepare-environment.outputs.POETRY_VERSION }}
3437
virtualenvs-create: true
3538
virtualenvs-in-project: true
3639
installer-parallel: true

docs/docs/python-sdk/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The Infrahub Python SDK greatly simplifies how you can interact with Infrahub pr
77
## Blog posts
88

99
- [Querying Data in Infrahub via the Python SDK](https://www.opsmill.com/querying-data-in-infrahub-via-the-python-sdk/)
10+
- [Creating, Modifying, and Deleting Data in Infrahub Using the Python SDK](https://www.opsmill.com/infrahub-python-sdk-create-modify-delete/)
1011

1112
## Guides
1213

docs/package-lock.json

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

infrahub_sdk/client.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,27 @@ async def count(
562562
at: Timestamp | None = None,
563563
branch: str | None = None,
564564
timeout: int | None = None,
565+
partial_match: bool = False,
565566
**kwargs: Any,
566567
) -> int:
567568
"""Return the number of nodes of a given kind."""
568-
filters = kwargs
569-
schema = await self.schema.get(kind=kind, branch=branch)
569+
filters: dict[str, Any] = dict(kwargs)
570570

571+
if partial_match:
572+
filters["partial_match"] = True
573+
574+
schema = await self.schema.get(kind=kind, branch=branch)
571575
branch = branch or self.default_branch
572576
if at:
573577
at = Timestamp(at)
574578

579+
data: dict[str, Any] = {
580+
"count": None,
581+
"@filters": filters,
582+
}
583+
575584
response = await self.execute_graphql(
576-
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
585+
query=Query(query={schema.kind: data}).render(),
577586
branch_name=branch,
578587
at=at,
579588
timeout=timeout,
@@ -801,7 +810,7 @@ async def process_batch() -> tuple[list[InfrahubNode], list[InfrahubNode]]:
801810
nodes = []
802811
related_nodes = []
803812
batch_process = await self.create_batch()
804-
count = await self.count(kind=schema.kind, **filters)
813+
count = await self.count(kind=schema.kind, partial_match=partial_match, **filters)
805814
total_pages = (count + pagination_size - 1) // pagination_size
806815

807816
for page_number in range(1, total_pages + 1):
@@ -1683,18 +1692,27 @@ def count(
16831692
at: Timestamp | None = None,
16841693
branch: str | None = None,
16851694
timeout: int | None = None,
1695+
partial_match: bool = False,
16861696
**kwargs: Any,
16871697
) -> int:
16881698
"""Return the number of nodes of a given kind."""
1689-
filters = kwargs
1690-
schema = self.schema.get(kind=kind, branch=branch)
1699+
filters: dict[str, Any] = dict(kwargs)
16911700

1701+
if partial_match:
1702+
filters["partial_match"] = True
1703+
1704+
schema = self.schema.get(kind=kind, branch=branch)
16921705
branch = branch or self.default_branch
16931706
if at:
16941707
at = Timestamp(at)
16951708

1709+
data: dict[str, Any] = {
1710+
"count": None,
1711+
"@filters": filters,
1712+
}
1713+
16961714
response = self.execute_graphql(
1697-
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
1715+
query=Query(query={schema.kind: data}).render(),
16981716
branch_name=branch,
16991717
at=at,
17001718
timeout=timeout,
@@ -1957,7 +1975,7 @@ def process_batch() -> tuple[list[InfrahubNodeSync], list[InfrahubNodeSync]]:
19571975
related_nodes = []
19581976
batch_process = self.create_batch()
19591977

1960-
count = self.count(kind=schema.kind, **filters)
1978+
count = self.count(kind=schema.kind, partial_match=partial_match, **filters)
19611979
total_pages = (count + pagination_size - 1) // pagination_size
19621980

19631981
for page_number in range(1, total_pages + 1):

0 commit comments

Comments
 (0)