Skip to content

Merge stable into develop #417

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 11 commits into from
May 26, 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
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ env:
METRICS_ENDPOINT: ${{ secrets.METRICS_ENDPOINT }}

jobs:
# ------------------------------------------ Check Files Changes ------------------------------------------
prepare-environment:
uses: ./.github/workflows/define-versions.yml
# ------------------------------------------ Check Files Changes ------------------------------------------
files-changed:
name: Detect which file has changed
runs-on: ubuntu-latest
Expand Down Expand Up @@ -152,7 +154,7 @@ jobs:
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
(needs.files-changed.outputs.python == 'true') || (needs.files-changed.outputs.documentation_generated == 'true')
needs: ["files-changed", "yaml-lint", "python-lint"]
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
runs-on: "ubuntu-22.04"
timeout-minutes: 5
steps:
Expand All @@ -166,7 +168,7 @@ jobs:
python-version: "3.12"
- name: "Setup Python environment"
run: |
pipx install poetry==2.1
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
poetry config virtualenvs.create true --local
poetry env use 3.12
- name: "Install dependencies"
Expand Down Expand Up @@ -218,7 +220,7 @@ jobs:
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.files-changed.outputs.python == 'true'
needs: ["files-changed", "yaml-lint", "python-lint"]
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -230,7 +232,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: "Setup environment"
run: |
pipx install poetry==2.1 --python python${{ matrix.python-version }}
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }} --python python${{ matrix.python-version }}
poetry config virtualenvs.create true --local
pip install invoke toml codecov
- name: "Install Package"
Expand Down Expand Up @@ -266,7 +268,7 @@ jobs:
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.files-changed.outputs.python == 'true'
needs: ["files-changed", "yaml-lint", "python-lint"]
needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
runs-on:
group: "huge-runners"
timeout-minutes: 30
Expand All @@ -283,7 +285,7 @@ jobs:
echo "PYTEST_DEBUG_TEMPROOT=/var/lib/github/${RUNNER_NAME}/_temp" >> $GITHUB_ENV
- name: "Setup environment"
run: |
pipx install poetry==2.1
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
poetry config virtualenvs.create true --local
pip install invoke toml codecov
- name: "Install Package"
Expand All @@ -306,7 +308,7 @@ jobs:
# !contains(needs.*.result, 'cancelled') &&
# needs.files-changed.outputs.python == 'true' &&
# (github.base_ref == 'stable' || github.base_ref == 'develop')
# needs: ["files-changed", "yaml-lint", "python-lint"]
# needs: ["prepare-environment", "files-changed", "yaml-lint", "python-lint"]
# runs-on:
# group: "huge-runners"
# timeout-minutes: 30
Expand Down Expand Up @@ -356,7 +358,7 @@ jobs:

# - name: "Setup environment"
# run: |
# pipx install poetry==2.1
# pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
# poetry config virtualenvs.create true --local
# pip install invoke toml codecov

Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/define-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# yamllint disable rule:truthy rule:truthy rule:line-length
name: "Define versions"
on:
workflow_call:
outputs:
POETRY_VERSION:
value: "2.1.3"

jobs:
prepare:
runs-on: ubuntu-latest
steps:
- run: "true"
5 changes: 4 additions & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ on:
default: false

jobs:
prepare-environment:
uses: ./.github/workflows/define-versions.yml
publish_to_pypi:
name: "Publish Infrahub SDK to PyPI"
runs-on: "ubuntu-22.04"
needs: prepare-environment
steps:
- name: "Set up Python"
uses: "actions/setup-python@v5"
Expand All @@ -41,7 +44,7 @@ jobs:
- name: "Install Poetry"
uses: "snok/install-poetry@v1"
with:
version: 1.8.5
version: ${{ needs.prepare-environment.outputs.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ on:
- published

jobs:
prepare-environment:
uses: ./.github/workflows/define-versions.yml
check_release:
runs-on: ubuntu-22.04
needs: prepare-environment
outputs:
is_prerelease: ${{ steps.release.outputs.is_prerelease }}
is_devrelease: ${{ steps.release.outputs.is_devrelease }}
Expand All @@ -30,7 +33,7 @@ jobs:
- name: "Install Poetry"
uses: "snok/install-poetry@v1"
with:
version: 1.8.5
version: ${{ needs.prepare-environment.outputs.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down
1 change: 1 addition & 0 deletions docs/docs/python-sdk/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Infrahub Python SDK greatly simplifies how you can interact with Infrahub pr
## Blog posts

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

## Guides

Expand Down
6 changes: 3 additions & 3 deletions docs/package-lock.json

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

34 changes: 26 additions & 8 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,27 @@ async def count(
at: Timestamp | None = None,
branch: str | None = None,
timeout: int | None = None,
partial_match: bool = False,
**kwargs: Any,
) -> int:
"""Return the number of nodes of a given kind."""
filters = kwargs
schema = await self.schema.get(kind=kind, branch=branch)
filters: dict[str, Any] = dict(kwargs)

if partial_match:
filters["partial_match"] = True

schema = await self.schema.get(kind=kind, branch=branch)
branch = branch or self.default_branch
if at:
at = Timestamp(at)

data: dict[str, Any] = {
"count": None,
"@filters": filters,
}

response = await self.execute_graphql(
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
query=Query(query={schema.kind: data}).render(),
branch_name=branch,
at=at,
timeout=timeout,
Expand Down Expand Up @@ -801,7 +810,7 @@ async def process_batch() -> tuple[list[InfrahubNode], list[InfrahubNode]]:
nodes = []
related_nodes = []
batch_process = await self.create_batch()
count = await self.count(kind=schema.kind, **filters)
count = await self.count(kind=schema.kind, partial_match=partial_match, **filters)
total_pages = (count + pagination_size - 1) // pagination_size

for page_number in range(1, total_pages + 1):
Expand Down Expand Up @@ -1683,18 +1692,27 @@ def count(
at: Timestamp | None = None,
branch: str | None = None,
timeout: int | None = None,
partial_match: bool = False,
**kwargs: Any,
) -> int:
"""Return the number of nodes of a given kind."""
filters = kwargs
schema = self.schema.get(kind=kind, branch=branch)
filters: dict[str, Any] = dict(kwargs)

if partial_match:
filters["partial_match"] = True

schema = self.schema.get(kind=kind, branch=branch)
branch = branch or self.default_branch
if at:
at = Timestamp(at)

data: dict[str, Any] = {
"count": None,
"@filters": filters,
}

response = self.execute_graphql(
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
query=Query(query={schema.kind: data}).render(),
branch_name=branch,
at=at,
timeout=timeout,
Expand Down Expand Up @@ -1957,7 +1975,7 @@ def process_batch() -> tuple[list[InfrahubNodeSync], list[InfrahubNodeSync]]:
related_nodes = []
batch_process = self.create_batch()

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

for page_number in range(1, total_pages + 1):
Expand Down
Loading