Skip to content

Commit a3fe75f

Browse files
Merge pull request #44 from LedgerHQ/cev/fix_variant
Fix variant
2 parents 3097efc + 65ccb4b commit a3fe75f

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.9.1] - 2025-03-26
9+
10+
### Fixed
11+
12+
- Issue with `variant_values` when computed from a Makefile variable
13+
814
## [0.9.0] - 2025-03-25
915

1016
### Added

src/ledgered/github.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ def makefile(self) -> str:
7474
@property
7575
def variants(self) -> List[str]:
7676
if not self._variant_values:
77-
self.__set_variants()
77+
self._set_variants()
7878
return self._variant_values
7979

8080
@property
8181
def variant_param(self) -> Optional[str]:
8282
if self._variant_param is None:
83-
self.__set_variants()
83+
self._set_variants()
8484
return self._variant_param
8585

8686
@property
@@ -96,16 +96,19 @@ def current_branch(self, new_branch: str) -> None:
9696
self._variant_param = None
9797
self._variant_values.clear()
9898

99-
def __set_variants(self) -> None:
99+
def _set_variants(self) -> None:
100100
"""Extracts the variants from the app Makefile"""
101101

102102
for line in self.makefile.splitlines():
103103
if "VARIANTS" in line:
104104
# Ex: `@echo VARIANTS COIN ACA ACA_XL`
105+
# Sometimes, it can be a computed value in the Makefile, ex: `@echo VARIANTS CHAIN $(SUPPORTED_CHAINS)`
106+
# => No solution to get them for now
105107
parts = line.split(" ")
106108
if len(parts) >= 3:
107109
self._variant_param = parts[2]
108-
self._variant_values = parts[3:]
110+
if not parts[3].startswith("$("):
111+
self._variant_values = parts[3:]
109112
elif "VARIANT_PARAM" in line and "=" in line:
110113
# There should be a single word here, ex: `VARIANT_PARAM = COIN`
111114
self._variant_param = line.split("=")[1].split()[0]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from unittest import TestCase
2+
from unittest.mock import patch
3+
from github import Github
4+
5+
from ledgered.github import AppRepository
6+
7+
8+
class TestAppRepository(TestCase):
9+
def setUp(self):
10+
self.gh = Github()
11+
12+
def test__set_variants_VARIANTS(self):
13+
param = "COIN"
14+
coins = ["COIN1", "COIN2"]
15+
AppRepository.makefile = f"@echo VARIANTS {param} {' '.join(coins)}"
16+
with patch("github.Repository.Repository", AppRepository):
17+
app_repo = self.gh.get_repo("LedgerHQ/ledgered")
18+
self.assertIsNone(app_repo._variant_param)
19+
self.assertListEqual(app_repo._variant_values, [])
20+
21+
self.assertIsNone(app_repo._set_variants())
22+
23+
self.assertEqual(app_repo._variant_param, param)
24+
self.assertListEqual(app_repo._variant_values, coins)
25+
26+
def test__set_variants_VARIANTS_variable(self):
27+
param = "COIN"
28+
AppRepository.makefile = f"@echo VARIANTS {param} $(COINS)"
29+
with patch("github.Repository.Repository", AppRepository):
30+
app_repo = self.gh.get_repo("LedgerHQ/ledgered")
31+
self.assertIsNone(app_repo._variant_param)
32+
self.assertListEqual(app_repo._variant_values, [])
33+
34+
self.assertIsNone(app_repo._set_variants())
35+
36+
# `$(COIN)` can not be interpreted from Ledgered, so the variants can not be parsed
37+
self.assertIsNone(app_repo._variant_param)
38+
self.assertListEqual(app_repo._variant_values, [])
39+
40+
def test__set_variants_standard(self):
41+
param = "COIN"
42+
coins = ["COIN1", "COIN2"]
43+
AppRepository.makefile = f"VARIANT_PARAM={param}\nVARIANT_VALUES = {' '.join(coins)}"
44+
with patch("github.Repository.Repository", AppRepository):
45+
app_repo = self.gh.get_repo("LedgerHQ/ledgered")
46+
self.assertIsNone(app_repo._variant_param)
47+
self.assertListEqual(app_repo._variant_values, [])
48+
49+
self.assertIsNone(app_repo._set_variants())
50+
51+
self.assertEqual(app_repo._variant_param, param)
52+
self.assertListEqual(app_repo._variant_values, coins)
53+
54+
def test__set_variants_standard_variable(self):
55+
param = "COIN"
56+
AppRepository.makefile = f"VARIANT_PARAM= {param}\nVARIANT_VALUES = $(COINS)"
57+
with patch("github.Repository.Repository", AppRepository):
58+
app_repo = self.gh.get_repo("LedgerHQ/ledgered")
59+
self.assertIsNone(app_repo._variant_param)
60+
self.assertListEqual(app_repo._variant_values, [])
61+
62+
self.assertIsNone(app_repo._set_variants())
63+
64+
# `$(COIN)` can not be interpreted from Ledgered, so the variants can not be parsed
65+
self.assertIsNone(app_repo._variant_param)
66+
self.assertListEqual(app_repo._variant_values, [])

0 commit comments

Comments
 (0)