Skip to content

Commit 0827cb6

Browse files
committed
fix: support version arg in Pull()
These changes add the version argument to the Pull function + moar tests.
1 parent fe2c17c commit 0827cb6

File tree

12 files changed

+955
-46
lines changed

12 files changed

+955
-46
lines changed

go/shim/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func helm_sdkpy_history(handle C.helm_sdkpy_handle, release_name *C.char, result
545545
// Pull action
546546

547547
//export helm_sdkpy_pull
548-
func helm_sdkpy_pull(handle C.helm_sdkpy_handle, chart_ref *C.char, dest_dir *C.char) C.int {
548+
func helm_sdkpy_pull(handle C.helm_sdkpy_handle, chart_ref *C.char, dest_dir *C.char, version *C.char) C.int {
549549
state, err := getConfig(handle)
550550
if err != nil {
551551
return setError(err)
@@ -556,13 +556,18 @@ func helm_sdkpy_pull(handle C.helm_sdkpy_handle, chart_ref *C.char, dest_dir *C.
556556

557557
chartRef := C.GoString(chart_ref)
558558
destDir := C.GoString(dest_dir)
559+
chartVersion := C.GoString(version)
559560

560561
// Create pull action
561562
client := action.NewPull()
562563
client.Settings = state.envs
563564
if destDir != "" {
564565
client.DestDir = destDir
565566
}
567+
// Set version if provided
568+
if chartVersion != "" {
569+
client.Version = chartVersion
570+
}
566571

567572
// Run the pull
568573
_, err = client.Run(chartRef)

helm_sdkpy/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Python bindings for Helm - The Kubernetes Package Manager."""
1616

17+
from importlib.metadata import version as _get_version
18+
1719
from ._ffi import get_version
1820
from .actions import (
1921
Configuration,
@@ -28,7 +30,7 @@
2830
Uninstall,
2931
Upgrade,
3032
)
31-
from .chart import Lint, Package, Pull, Push, Show, Test
33+
from .chart import Lint, Package, Pull, Push, ReleaseTest, Show
3234
from .exceptions import (
3335
ChartError,
3436
ConfigurationError,
@@ -44,7 +46,10 @@
4446
)
4547
from .repo import RepoAdd, RepoList, RepoRemove, RepoUpdate
4648

47-
__version__ = "0.0.1"
49+
# Backwards compatibility alias - ReleaseTest renamed to avoid pytest collection
50+
Test = ReleaseTest
51+
52+
__version__ = _get_version("helm-sdkpy")
4853

4954
__all__ = [
5055
# Core classes
@@ -63,7 +68,8 @@
6368
# Chart classes
6469
"Pull",
6570
"Show",
66-
"Test",
71+
"Test", # Alias for ReleaseTest
72+
"ReleaseTest",
6773
"Lint",
6874
"Package",
6975
"Push",

helm_sdkpy/_ffi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
int helm_sdkpy_history(helm_sdkpy_handle handle, const char *release_name, char **result_json);
5959
6060
// Pull action
61-
int helm_sdkpy_pull(helm_sdkpy_handle handle, const char *chart_ref, const char *dest_dir);
61+
int helm_sdkpy_pull(helm_sdkpy_handle handle, const char *chart_ref, const char *dest_dir, const char *version);
6262
6363
// Show chart action
6464
int helm_sdkpy_show_chart(helm_sdkpy_handle handle, const char *chart_path, char **result_json);
@@ -84,7 +84,7 @@
8484
// Registry management actions
8585
int helm_sdkpy_registry_login(helm_sdkpy_handle handle, const char *hostname, const char *username, const char *password, const char *options_json);
8686
int helm_sdkpy_registry_logout(helm_sdkpy_handle handle, const char *hostname);
87-
87+
8888
// Push action (for OCI registries)
8989
int helm_sdkpy_push(helm_sdkpy_handle handle, const char *chart_ref, const char *remote, const char *options_json);
9090

helm_sdkpy/actions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ async def run(
613613
Raises:
614614
RegistryError: If login fails
615615
"""
616-
from .exceptions import RegistryError
617616

618617
def _registry_login():
619618
hostname_cstr = ffi.new("char[]", hostname.encode("utf-8"))
@@ -678,7 +677,6 @@ async def run(self, hostname: str) -> None:
678677
Raises:
679678
RegistryError: If logout fails
680679
"""
681-
from .exceptions import RegistryError
682680

683681
def _registry_logout():
684682
hostname_cstr = ffi.new("char[]", hostname.encode("utf-8"))

helm_sdkpy/chart.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ def __init__(self, config):
4343
self.config = config
4444
self._lib = get_library()
4545

46-
async def run(self, chart_ref: str, dest_dir: str | None = None) -> None:
46+
async def run(
47+
self, chart_ref: str, dest_dir: str | None = None, version: str | None = None
48+
) -> None:
4749
"""Pull a chart asynchronously.
4850
4951
Args:
5052
chart_ref: Chart reference (e.g., "repo/chart" or "oci://...")
5153
dest_dir: Destination directory (default: current directory)
54+
version: Chart version to pull (e.g., "1.2.3"). If not specified, uses latest
5255
5356
Raises:
5457
ChartError: If pull fails
@@ -57,8 +60,12 @@ async def run(self, chart_ref: str, dest_dir: str | None = None) -> None:
5760
def _pull():
5861
ref_cstr = ffi.new("char[]", chart_ref.encode("utf-8"))
5962
dest_cstr = ffi.new("char[]", dest_dir.encode("utf-8")) if dest_dir else ffi.NULL
63+
version_str = version or ""
64+
version_cstr = ffi.new("char[]", version_str.encode("utf-8"))
6065

61-
result = self._lib.helm_sdkpy_pull(self.config._handle_value, ref_cstr, dest_cstr)
66+
result = self._lib.helm_sdkpy_pull(
67+
self.config._handle_value, ref_cstr, dest_cstr, version_cstr
68+
)
6269

6370
if result != 0:
6471
check_error(result)
@@ -149,7 +156,7 @@ def _values():
149156
return await asyncio.to_thread(_values)
150157

151158

152-
class Test:
159+
class ReleaseTest:
153160
"""Helm test action.
154161
155162
Runs tests for a release.
@@ -160,7 +167,7 @@ class Test:
160167
Example:
161168
>>> import asyncio
162169
>>> config = Configuration()
163-
>>> test = Test(config)
170+
>>> test = ReleaseTest(config)
164171
>>> result = asyncio.run(test.run("my-release"))
165172
"""
166173

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dev = [
2525
# Testing
2626
"coverage[toml] ~= 7.8",
2727
"pytest ~= 8.3",
28+
"pytest-asyncio ~= 0.24",
2829
"pytest-mock ~= 3.14",
2930
"pytest-order ~= 1.3",
3031
"python-dotenv ~= 1.0",
@@ -38,6 +39,12 @@ dev = [
3839
[tool.pytest.ini_options]
3940
addopts = "-ra"
4041
testpaths = ["tests"]
42+
asyncio_mode = "auto"
43+
asyncio_default_fixture_loop_scope = "function"
44+
filterwarnings = [
45+
"ignore:'asyncio.get_event_loop_policy':DeprecationWarning",
46+
"ignore:cannot collect test class 'ReleaseTest':pytest.PytestCollectionWarning",
47+
]
4148

4249
[build-system]
4350
requires = ["hatchling"]
@@ -47,6 +54,7 @@ build-backend = "hatchling.build"
4754
dev = [
4855
"codespell>=2.4.1",
4956
"pyright>=1.1.406",
57+
"pytest-asyncio>=0.24",
5058
"pytest-cov>=7.0.0",
5159
"ruff>=0.14.1",
5260
]

0 commit comments

Comments
 (0)