Skip to content

Commit 25cf197

Browse files
committed
Add package mode
1 parent 705cda2 commit 25cf197

File tree

10 files changed

+99
-36
lines changed

10 files changed

+99
-36
lines changed

infrahub_sdk/ctl/example_repo/copier.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ tests:
2626
type: bool
2727
help: Would you like to have testing?
2828
default: false
29+
package_mode:
30+
type: bool
31+
help: Would you like to have a python library initialized?
32+
default: false

infrahub_sdk/ctl/example_repo/poetry.lock

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

infrahub_sdk/ctl/example_repo/pyproject.toml.jinja

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ version = "0.1.0"
44
description = "Infrahub Repository"
55
authors = []
66
readme = "README.md"
7+
{% if package_mode %}
8+
packages = [
9+
{ include = "lib" }
10+
]
11+
{% else %}
12+
package-mode = false
13+
{% endif %}
714

815
[tool.poetry.dependencies]
916
python = ">=3.9,<3.13"
10-
17+
infrahub-sdk = {extras = ["ctl"], version = "^1.7.2"}
1118
1219
[tool.poetry.group.dev.dependencies]
13-
ruff = "^0.9.6"
20+
ruff = "^0.9.10"
21+
pytest = "^8.3.5"
22+
infrahub-testcontainers = "^1.1.8"
23+
pytest-asyncio = "^0.25.3"
1424
1525
[build-system]
1626
requires = ["poetry-core"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
2+
---
3+
version: "1.0"
4+
nodes:
5+
- name: Device
6+
namespace: Network
7+
human_friendly_id: ['hostname__value']
8+
attributes:
9+
- name: hostname
10+
kind: Text
11+
unique: true
12+
- name: model
13+
kind: Text
14+
relationships:
15+
- name: interfaces
16+
cardinality: many
17+
peer: NetworkInterface
18+
kind: Component
19+
- name: Interface
20+
namespace: Network
21+
attributes:
22+
- name: name
23+
kind: Text
24+
- name: description
25+
kind: Text
26+
optional: true
27+
relationships:
28+
- name: device
29+
cardinality: one
30+
peer: NetworkDevice
31+
optional: false
32+
kind: Parent

infrahub_sdk/ctl/example_repo/{% if package_mode %}lib{% endif %}/__init__.py

Whitespace-only changes.

infrahub_sdk/ctl/example_repo/{% if package_mode %}lib{% endif %}/example.py

Whitespace-only changes.

infrahub_sdk/ctl/example_repo/{% if tests %}tests{% endif %}/__init__.py

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
from pathlib import Path
3+
4+
from typing import Any
5+
from infrahub_sdk.yaml import SchemaFile
6+
7+
CURRENT_DIRECTORY = Path(__file__).parent.resolve()
8+
9+
10+
@pytest.fixture
11+
def root_directory() -> Path:
12+
"""
13+
Return the path of the root directory of the repository.
14+
"""
15+
return CURRENT_DIRECTORY.parent.parent
16+
17+
18+
@pytest.fixture
19+
def schemas_directory(root_directory: Path) -> Path:
20+
return root_directory / "schema"
21+
22+
23+
@pytest.fixture
24+
def schemas(schemas_directory: Path) -> list[dict[str, Any]]:
25+
schema_files = SchemaFile.load_from_disk(paths=[schemas_directory])
26+
return [item.content for item in schema_files if item.content]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
from pathlib import Path
3+
from infrahub_sdk import InfrahubClient
4+
from infrahub_sdk.testing.docker import TestInfrahubDockerClient
5+
from infrahub_sdk.protocols import CoreGenericRepository
6+
from infrahub_sdk.testing.repository import GitRepo
7+
8+
9+
class TestInfrahub(TestInfrahubDockerClient):
10+
@pytest.fixture(scope="class")
11+
def infrahub_version(self) -> str:
12+
"""Required to define the version of infrahub to use."""
13+
return "1.1.8"
14+
15+
@pytest.mark.asyncio
16+
async def test_load_schema(
17+
self, default_branch: str, client: InfrahubClient, schemas
18+
):
19+
await client.schema.wait_until_converged(branch=default_branch)
20+
21+
resp = await client.schema.load(
22+
schemas=schemas, branch=default_branch, wait_until_converged=True
23+
)
24+
assert resp.errors == {}

tests/unit/ctl/test_repository_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ def test_repo_init(self) -> None:
307307
"scripts": True,
308308
"tests": True,
309309
"transforms": True,
310+
"package_mode": False,
310311
}
311312

312313
yaml.safe_dump(answers, temp_yaml)
313314
temp_yaml.close()
314315
runner.invoke(app, ["repository", "init", str(dst), "--data", str(yaml_path)])
315-
316316
coppied_answers = yaml.safe_load((dst / ".copier-answers.yml").read_text())
317317
coppied_answers.pop("_src_path")
318318

0 commit comments

Comments
 (0)