ledgered 0.6.3.dev2__py3-none-any.whl → 0.6.4.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ledgered/__version__.py +2 -2
- ledgered/github.py +129 -0
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/METADATA +2 -1
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/RECORD +8 -7
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/LICENSE +0 -0
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/WHEEL +0 -0
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/entry_points.txt +0 -0
- {ledgered-0.6.3.dev2.dist-info → ledgered-0.6.4.dev2.dist-info}/top_level.txt +0 -0
ledgered/__version__.py
CHANGED
|
@@ -12,5 +12,5 @@ __version__: str
|
|
|
12
12
|
__version_tuple__: VERSION_TUPLE
|
|
13
13
|
version_tuple: VERSION_TUPLE
|
|
14
14
|
|
|
15
|
-
__version__ = version = '0.6.
|
|
16
|
-
__version_tuple__ = version_tuple = (0, 6,
|
|
15
|
+
__version__ = version = '0.6.4.dev2'
|
|
16
|
+
__version_tuple__ = version_tuple = (0, 6, 4, 'dev2')
|
ledgered/github.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from enum import IntEnum, auto
|
|
2
|
+
from github import ContentFile as PyContentFile, Github as PyGithub, Repository as PyRepository
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
from ledgered.manifest import MANIFEST_FILE_NAME, Manifest
|
|
8
|
+
|
|
9
|
+
LEDGER_ORG_NAME = "ledgerhq"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Condition(IntEnum):
|
|
13
|
+
WITH = auto()
|
|
14
|
+
WITHOUT = auto()
|
|
15
|
+
ONLY = auto()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AppRepository(PyRepository.Repository):
|
|
19
|
+
|
|
20
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
21
|
+
super().__init__(*args, **kwargs)
|
|
22
|
+
self._manifest: Optional[Manifest] = None
|
|
23
|
+
self._makefile: Optional[str] = None
|
|
24
|
+
self._branch: str = self.default_branch
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def manifest(self) -> Manifest:
|
|
28
|
+
if self._manifest is None:
|
|
29
|
+
manifest = self.get_contents(MANIFEST_FILE_NAME, ref=self.current_branch)
|
|
30
|
+
# `get_contents` can return a list, but here there can only be one manifest
|
|
31
|
+
assert isinstance(manifest, PyContentFile.ContentFile)
|
|
32
|
+
manifest_content = manifest.decoded_content.decode()
|
|
33
|
+
self._manifest = Manifest.from_string(manifest_content)
|
|
34
|
+
return self._manifest
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def makefile_path(self) -> Path:
|
|
38
|
+
location = self.manifest.app.build_directory
|
|
39
|
+
if self.manifest.app.is_rust:
|
|
40
|
+
location /= "Cargo.toml"
|
|
41
|
+
else:
|
|
42
|
+
location /= "Makefile"
|
|
43
|
+
return location
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def makefile(self) -> str:
|
|
47
|
+
if self._makefile is None:
|
|
48
|
+
# paths on Windows contain "\" which are not compatible with GitHub remote paths
|
|
49
|
+
makefile = self.get_contents(str(self.makefile_path).replace("\\", "/"),
|
|
50
|
+
ref=self.current_branch)
|
|
51
|
+
# `get_contents` can return a list, but here there can only be one Makefile / Cargo.toml
|
|
52
|
+
assert isinstance(makefile, PyContentFile.ContentFile)
|
|
53
|
+
self._makefile = makefile.decoded_content.decode()
|
|
54
|
+
return self._makefile
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def variants(self) -> List[str]:
|
|
58
|
+
variants = []
|
|
59
|
+
for line in self.makefile.splitlines():
|
|
60
|
+
if "VARIANTS" in line:
|
|
61
|
+
variants.extend(line.split(' ')[3:])
|
|
62
|
+
elif "VARIANT_VALUES = " in line:
|
|
63
|
+
variants.extend(line.split(" = ")[1].split(' '))
|
|
64
|
+
return variants
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def current_branch(self) -> str:
|
|
68
|
+
return self._branch
|
|
69
|
+
|
|
70
|
+
@current_branch.setter
|
|
71
|
+
def current_branch(self, new_branch: str) -> None:
|
|
72
|
+
self._branch = self.get_branch(new_branch).name
|
|
73
|
+
# invalidating previously fetched info, as they may differ on another branch
|
|
74
|
+
self._manifest = None
|
|
75
|
+
self._makefile = None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class GitHubApps(list):
|
|
79
|
+
|
|
80
|
+
def __init__(self, apps: List[AppRepository]):
|
|
81
|
+
super().__init__([r for r in apps if r.name.startswith("app-")])
|
|
82
|
+
|
|
83
|
+
def filter(self,
|
|
84
|
+
name: Optional[str] = None,
|
|
85
|
+
archived: Condition = Condition.WITH,
|
|
86
|
+
private: Condition = Condition.WITH) -> "GitHubApps":
|
|
87
|
+
new_list = [i for i in self]
|
|
88
|
+
# archived filtering
|
|
89
|
+
if archived == Condition.WITHOUT:
|
|
90
|
+
new_list = [r for r in new_list if not r.archived]
|
|
91
|
+
elif archived == Condition.ONLY:
|
|
92
|
+
new_list = [r for r in new_list if r.archived]
|
|
93
|
+
# private filtering
|
|
94
|
+
if private == Condition.WITHOUT:
|
|
95
|
+
new_list = [r for r in new_list if not r.private]
|
|
96
|
+
elif private == Condition.ONLY:
|
|
97
|
+
new_list = [r for r in new_list if r.private]
|
|
98
|
+
# name filtering
|
|
99
|
+
if name is not None:
|
|
100
|
+
new_list = [r for r in new_list if name.lower() in r.name.lower()]
|
|
101
|
+
return GitHubApps(new_list)
|
|
102
|
+
|
|
103
|
+
def first(self, *args, **kwargs) -> Optional[AppRepository]:
|
|
104
|
+
results = self.filter(*args, **kwargs)
|
|
105
|
+
return results[0] if results else None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class GitHubLedgerHQ(PyGithub):
|
|
109
|
+
|
|
110
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
111
|
+
super().__init__(*args, **kwargs)
|
|
112
|
+
self._org = self.get_organization(LEDGER_ORG_NAME)
|
|
113
|
+
self._apps: Optional[GitHubApps] = None
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def apps(self) -> GitHubApps:
|
|
117
|
+
if self._apps is None:
|
|
118
|
+
with patch("github.Repository.Repository", AppRepository):
|
|
119
|
+
self._apps = GitHubApps(self._org.get_repos())
|
|
120
|
+
return self._apps
|
|
121
|
+
|
|
122
|
+
def get_app(self, name) -> AppRepository:
|
|
123
|
+
"""
|
|
124
|
+
Fetch a specific application repository on GitHub.
|
|
125
|
+
The name must be exact.
|
|
126
|
+
"""
|
|
127
|
+
assert name.startswith("app-"), f"'{name}' is not prefixed with 'app-'!"
|
|
128
|
+
with patch("github.Repository.Repository", AppRepository):
|
|
129
|
+
return self._org.get_repo(name)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ledgered
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.4.dev2
|
|
4
4
|
Summary: Python tools, utils, libraries, to be used with Ledger cryptodevices
|
|
5
5
|
Author-email: Ledger <hello@ledger.fr>
|
|
6
6
|
License: MIT License
|
|
@@ -39,6 +39,7 @@ Description-Content-Type: text/markdown
|
|
|
39
39
|
License-File: LICENSE
|
|
40
40
|
Requires-Dist: toml
|
|
41
41
|
Requires-Dist: pyelftools
|
|
42
|
+
Requires-Dist: pygithub
|
|
42
43
|
Provides-Extra: dev
|
|
43
44
|
Requires-Dist: pytest ; extra == 'dev'
|
|
44
45
|
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
ledgered/__init__.py,sha256=aRY9b0H6CrS8gUFvdWHz-IPvyBm0i8i8paMzmE1BuK4,126
|
|
2
|
-
ledgered/__version__.py,sha256=
|
|
2
|
+
ledgered/__version__.py,sha256=4wLUjzmHgQNi7bVKFz4hZ6hhGMcqPKB0yt1QF0yGfkI,424
|
|
3
3
|
ledgered/binary.py,sha256=J49o5kDwmvo_hBsHfl88qxRteo6AqleoUJcjBDHp-Os,2664
|
|
4
|
+
ledgered/github.py,sha256=qpIYoaprwjh2dR1H8_I_aw-_Nl4i-whdwO2FH59yIHI,4708
|
|
4
5
|
ledgered/serializers.py,sha256=DKcz7X3hz3Qoumv9neoqK4xLh13ZBE5rOJv0KdZxZes,1624
|
|
5
6
|
ledgered/manifest/__init__.py,sha256=YbsDtjHJsUO0T37GQKoMSrC44sfcSq0JTSjDN6xrc64,243
|
|
6
7
|
ledgered/manifest/app.py,sha256=xK9vW7nABsuxPNzj1wpeZd5T9y3PVBhwSAw3LlHdtGQ,1084
|
|
@@ -12,9 +13,9 @@ ledgered/manifest/tests.py,sha256=Zh-c_pZ4XzMKU7Pp7P-iltBnfrG8iRjO9drRtyJIUW8,33
|
|
|
12
13
|
ledgered/manifest/use_cases.py,sha256=Zu5ufX29iBlFEWYAQhx3YDY_ajd0539F5pW8aULMyEw,898
|
|
13
14
|
ledgered/manifest/utils.py,sha256=HnqQVH6MTNGjs6JAEGVjs6IUcywio6mCNlMrp7xhUu4,509
|
|
14
15
|
ledgered/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
ledgered-0.6.
|
|
16
|
-
ledgered-0.6.
|
|
17
|
-
ledgered-0.6.
|
|
18
|
-
ledgered-0.6.
|
|
19
|
-
ledgered-0.6.
|
|
20
|
-
ledgered-0.6.
|
|
16
|
+
ledgered-0.6.4.dev2.dist-info/LICENSE,sha256=rcYmKw35vfzxANXv5w2DgsSVXV8LXcOnTDo6lslFYp0,1063
|
|
17
|
+
ledgered-0.6.4.dev2.dist-info/METADATA,sha256=GviDjmfnin05RoZ8RvjRmdZLyutS9n5BLWJBBI5BrFg,2956
|
|
18
|
+
ledgered-0.6.4.dev2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
19
|
+
ledgered-0.6.4.dev2.dist-info/entry_points.txt,sha256=absOELBtJLqnlB9NdfOQCh1RLDPVbCNgnPXX8fSUw_8,100
|
|
20
|
+
ledgered-0.6.4.dev2.dist-info/top_level.txt,sha256=LWTGn6fYa3YI2253y1orMdCyI1DcSMp86wOJ-rj_RQE,9
|
|
21
|
+
ledgered-0.6.4.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|