mkdocstrings-github 0.4.5__py3-none-any.whl → 0.5.1__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.
- {mkdocstrings_github-0.4.5.dist-info → mkdocstrings_github-0.5.1.dist-info}/METADATA +24 -4
- {mkdocstrings_github-0.4.5.dist-info → mkdocstrings_github-0.5.1.dist-info}/RECORD +9 -9
- mkdocstrings_handlers/github/config.py +9 -11
- mkdocstrings_handlers/github/handler.py +29 -32
- mkdocstrings_handlers/github/objects.py +62 -29
- mkdocstrings_handlers/github/templates/material/action.html.jinja +1 -1
- mkdocstrings_handlers/github/templates/material/workflow.html.jinja +7 -1
- {mkdocstrings_github-0.4.5.dist-info → mkdocstrings_github-0.5.1.dist-info}/WHEEL +0 -0
- {mkdocstrings_github-0.4.5.dist-info → mkdocstrings_github-0.5.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocstrings-github
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: A GitHub Action handler for mkdocstrings
|
|
5
5
|
Author-email: Mark Hu <watermarkhu@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -33,14 +33,26 @@ Description-Content-Type: text/markdown
|
|
|
33
33
|
|
|
34
34
|
<p align="center">A GitHub Actions handler for <a href="https://github.com/mkdocstrings/mkdocstrings"><i>mkdocstrings</i></a>.</p>
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
<!-- --8<-- [end:header] -->
|
|
37
|
+
|
|
38
|
+
<p align="center"><img width=300px src="docs/img/logo.png"></p>
|
|
37
39
|
|
|
38
40
|
[](https://github.com/watermarkhu/mkdocstrings-github/actions/workflows/qualify.yaml)
|
|
39
41
|
[](https://watermarkhu.nl/mkdocstrings-github)
|
|
40
42
|
[](https://pypi.org/project/mkdocstrings-github/)
|
|
41
43
|
[](https://codecov.io/github/watermarkhu/mkdocstrings-github)
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
For example, the following page is generated from [actions/checkout](https://github.com/actions/checkout):
|
|
48
|
+
|
|
49
|
+
<picture>
|
|
50
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/img/example_dark.png">
|
|
51
|
+
<source media="(prefers-color-scheme: light)" srcset="docs/img/example_light.png">
|
|
52
|
+
<img alt="Fallback image description" src="docs/img/example_light.png">
|
|
53
|
+
</picture>
|
|
54
|
+
|
|
55
|
+
|
|
44
56
|
<!-- --8<-- [start:install] -->
|
|
45
57
|
You can install the GitHub handler by specifying it as a dependency:
|
|
46
58
|
|
|
@@ -49,9 +61,17 @@ You can install the GitHub handler by specifying it as a dependency:
|
|
|
49
61
|
# adapt to your dependencies manager
|
|
50
62
|
[project]
|
|
51
63
|
dependencies = [
|
|
52
|
-
"mkdocstrings-github
|
|
64
|
+
"mkdocstrings-github",
|
|
53
65
|
]
|
|
54
66
|
```
|
|
67
|
+
|
|
68
|
+
after which the generated documentation can be inserted in the markdown page with:
|
|
69
|
+
|
|
70
|
+
```md
|
|
71
|
+
::: <path-to-action-or-workflow>
|
|
72
|
+
handler: github
|
|
73
|
+
```
|
|
74
|
+
|
|
55
75
|
<!-- --8<-- [end:install] -->
|
|
56
76
|
|
|
57
77
|
<!-- --8<-- [start:footer] -->
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
mkdocstrings_handlers/github/__init__.py,sha256=0WdFUIq4Xu2ZFtlZNIYCQSoqcx3Ot9Wv41_X_dwbFww,248
|
|
2
|
-
mkdocstrings_handlers/github/config.py,sha256=
|
|
3
|
-
mkdocstrings_handlers/github/handler.py,sha256=
|
|
4
|
-
mkdocstrings_handlers/github/objects.py,sha256=
|
|
2
|
+
mkdocstrings_handlers/github/config.py,sha256=LJuMsZ4_wFZzwFIhOQypi2sTONaB3G4niyPwLh297yk,6045
|
|
3
|
+
mkdocstrings_handlers/github/handler.py,sha256=ShE0EUsWDgonE4LtR3MFPEzCLwvDb2UztrAiXqQs_oc,8415
|
|
4
|
+
mkdocstrings_handlers/github/objects.py,sha256=ckMEEoj3pdLasGHzZMwYY7XdjwbUdHRch07dAzgEHs0,8217
|
|
5
5
|
mkdocstrings_handlers/github/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
mkdocstrings_handlers/github/rendering.py,sha256=6xcE2WwyTRW_38g7Ek55hlm53EsFFqueazFw12__DyA,2820
|
|
7
|
-
mkdocstrings_handlers/github/templates/material/action.html.jinja,sha256=
|
|
7
|
+
mkdocstrings_handlers/github/templates/material/action.html.jinja,sha256=C7S8I9bjnrEUahyDB7CkFxtakFrr53KE3t3uyczBPzc,2864
|
|
8
8
|
mkdocstrings_handlers/github/templates/material/heading.html.jinja,sha256=wnvZpNED8Dhb935qnddeDExXN-MIUz8frRRfgq-A9VA,1396
|
|
9
9
|
mkdocstrings_handlers/github/templates/material/inputs.html.jinja,sha256=CIcw3OBQdCP4e5A4srLu1v3xoOjsedIw1Zh3qxtG0-A,3482
|
|
10
10
|
mkdocstrings_handlers/github/templates/material/outputs.html.jinja,sha256=jlzVF93q5AyJfOiSl3_1VBVL3c6rjmEcS81s3sri5Gg,2670
|
|
11
11
|
mkdocstrings_handlers/github/templates/material/secrets.html.jinja,sha256=1lMJoxjjeiqetVu0mdLKmZ1faYRReeyjiYvYTZESots,2881
|
|
12
12
|
mkdocstrings_handlers/github/templates/material/style.css,sha256=R2hh1RfHwJ6XNT4YQl_txNkNXcPBZJMCBZn5kQEMQ6M,962
|
|
13
|
-
mkdocstrings_handlers/github/templates/material/workflow.html.jinja,sha256=
|
|
14
|
-
mkdocstrings_github-0.
|
|
15
|
-
mkdocstrings_github-0.
|
|
16
|
-
mkdocstrings_github-0.
|
|
17
|
-
mkdocstrings_github-0.
|
|
13
|
+
mkdocstrings_handlers/github/templates/material/workflow.html.jinja,sha256=5dLdHRSQyulyFAVCVZAR_pkw-WXxCtM20cj6RS7IH1Q,4206
|
|
14
|
+
mkdocstrings_github-0.5.1.dist-info/METADATA,sha256=5gZeD09qgRS0XV18PjIw0uhDNoKOkCq9ohHAjuRDkzE,3867
|
|
15
|
+
mkdocstrings_github-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
mkdocstrings_github-0.5.1.dist-info/licenses/LICENSE,sha256=5enZtJ4zSp0Ps3jTqFQ4kadcx62BhgTaDNPrXWb3g3E,1069
|
|
17
|
+
mkdocstrings_github-0.5.1.dist-info/RECORD,,
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import re
|
|
6
5
|
import sys
|
|
7
6
|
from typing import Literal
|
|
8
7
|
|
|
@@ -92,6 +91,15 @@ class GitHubOptions(BaseModel):
|
|
|
92
91
|
description="Whether to show the signature in the documentation.",
|
|
93
92
|
)
|
|
94
93
|
|
|
94
|
+
signature_repository: str = Field(
|
|
95
|
+
default="",
|
|
96
|
+
description="""The GitHub repository in the format *owner/repo*.
|
|
97
|
+
|
|
98
|
+
By default, the repository is inferred from the current git repository using the default origin remote.
|
|
99
|
+
If it cannot be inferred, it must be set manually.
|
|
100
|
+
""",
|
|
101
|
+
)
|
|
102
|
+
|
|
95
103
|
signature_show_secrets: bool = Field(
|
|
96
104
|
default=False,
|
|
97
105
|
description="Whether to show secrets in the signature.",
|
|
@@ -171,16 +179,6 @@ class GitHubOptions(BaseModel):
|
|
|
171
179
|
class GitHubConfig(BaseModel):
|
|
172
180
|
"""Configuration options for the GitHub handler."""
|
|
173
181
|
|
|
174
|
-
repo: str = Field(
|
|
175
|
-
default="",
|
|
176
|
-
description="""The GitHub repository in the format *owner/repo*.
|
|
177
|
-
|
|
178
|
-
By default, the repository is inferred from the current git repository using the default origin remote.
|
|
179
|
-
If it cannot be inferred, it must be set manually.
|
|
180
|
-
""",
|
|
181
|
-
pattern=re.compile(r"^[\w.-]+/[\w.-]+$"),
|
|
182
|
-
)
|
|
183
|
-
|
|
184
182
|
feather_icons_source: str = Field(
|
|
185
183
|
default="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js",
|
|
186
184
|
description="""The source URL for Feather icons.
|
|
@@ -70,41 +70,9 @@ class GitHubHandler(BaseHandler):
|
|
|
70
70
|
self.major: str = ""
|
|
71
71
|
self.semver: str = ""
|
|
72
72
|
|
|
73
|
-
# Determine owner and repo name
|
|
74
|
-
if not self.config.repo:
|
|
75
|
-
self.get_repo()
|
|
76
|
-
|
|
77
73
|
if rendering.ENV_MAJOR_TAG not in os.environ or rendering.ENV_SEMVER_TAG not in os.environ:
|
|
78
74
|
self.get_releases()
|
|
79
75
|
|
|
80
|
-
def get_repo(self) -> None:
|
|
81
|
-
# Get repo from environment variable or git remotes.
|
|
82
|
-
if os.environ.get("GITHUB_ACTIONS") == "true" and (
|
|
83
|
-
repo := os.environ.get("GITHUB_REPOSITORY")
|
|
84
|
-
):
|
|
85
|
-
self.config.repo = repo
|
|
86
|
-
else:
|
|
87
|
-
# Try each remote to find a valid GitHub owner/repo
|
|
88
|
-
owner = None
|
|
89
|
-
repo_name = None
|
|
90
|
-
for remote in self.repo.remotes:
|
|
91
|
-
for url in remote.urls:
|
|
92
|
-
match = re.search(
|
|
93
|
-
r"(?P<host>[\w\.-]+)[/:](?P<owner>[^/]+)/(?P<repo>[^/.]+?)(?:\.git)?$",
|
|
94
|
-
url,
|
|
95
|
-
)
|
|
96
|
-
if match:
|
|
97
|
-
owner = match.group("owner")
|
|
98
|
-
repo_name = match.group("repo")
|
|
99
|
-
break
|
|
100
|
-
if owner and repo_name:
|
|
101
|
-
break
|
|
102
|
-
if not (owner and repo_name):
|
|
103
|
-
raise PluginError(
|
|
104
|
-
f"Could not determine GitHub repository owner/name from config.repo='{self.config.repo}' or any git remote URL."
|
|
105
|
-
)
|
|
106
|
-
self.config.repo = f"{owner}/{repo_name}"
|
|
107
|
-
|
|
108
76
|
def get_releases(self) -> None:
|
|
109
77
|
# Get all tags from the local git repository.
|
|
110
78
|
try:
|
|
@@ -167,6 +135,34 @@ class GitHubHandler(BaseHandler):
|
|
|
167
135
|
except Exception as error:
|
|
168
136
|
raise PluginError(f"Invalid options: {error}") from error
|
|
169
137
|
|
|
138
|
+
def get_repository_name(self) -> str:
|
|
139
|
+
# Get repo from environment variable or git remotes.
|
|
140
|
+
if os.environ.get("GITHUB_ACTIONS") == "true" and (
|
|
141
|
+
repo := os.environ.get("GITHUB_REPOSITORY")
|
|
142
|
+
):
|
|
143
|
+
return repo
|
|
144
|
+
else:
|
|
145
|
+
# Try each remote to find a valid GitHub owner/repo
|
|
146
|
+
owner = None
|
|
147
|
+
repo_name = None
|
|
148
|
+
for remote in self.repo.remotes:
|
|
149
|
+
for url in remote.urls:
|
|
150
|
+
match = re.search(
|
|
151
|
+
r"(?P<host>[\w\.-]+)[/:](?P<owner>[^/]+)/(?P<repo>[^/.]+?)(?:\.git)?$",
|
|
152
|
+
url,
|
|
153
|
+
)
|
|
154
|
+
if match:
|
|
155
|
+
owner = match.group("owner")
|
|
156
|
+
repo_name = match.group("repo")
|
|
157
|
+
break
|
|
158
|
+
if owner and repo_name:
|
|
159
|
+
break
|
|
160
|
+
if not (owner and repo_name):
|
|
161
|
+
raise PluginError(
|
|
162
|
+
"Could not determine GitHub repository owner/name from any git remote URL."
|
|
163
|
+
)
|
|
164
|
+
return f"{owner}/{repo_name}"
|
|
165
|
+
|
|
170
166
|
def update_env(self, config: Any) -> None:
|
|
171
167
|
self.env.trim_blocks = True
|
|
172
168
|
self.env.lstrip_blocks = True
|
|
@@ -179,6 +175,7 @@ class GitHubHandler(BaseHandler):
|
|
|
179
175
|
self.env.globals["semver_tag"] = self.semver
|
|
180
176
|
self.env.globals["major_tag"] = self.major
|
|
181
177
|
self.env.globals["git_repo"] = self.repo
|
|
178
|
+
self.env.globals["repository_name"] = self.get_repository_name()
|
|
182
179
|
|
|
183
180
|
def collect(self, identifier: str, options: GitHubOptions) -> Workflow | Action | None:
|
|
184
181
|
path = Path(self.repo.working_tree_dir) / identifier
|
|
@@ -106,10 +106,6 @@ class Action:
|
|
|
106
106
|
branding: dict = field(default_factory=dict)
|
|
107
107
|
template: Literal["action.html.jinja"] = "action.html.jinja"
|
|
108
108
|
|
|
109
|
-
@property
|
|
110
|
-
def members(self) -> list[Input | Output]:
|
|
111
|
-
return self.inputs + self.outputs
|
|
112
|
-
|
|
113
109
|
@staticmethod
|
|
114
110
|
def from_file(file: PathLike, id: str) -> "Action":
|
|
115
111
|
source, data = _read_file(file)
|
|
@@ -131,6 +127,25 @@ class Action:
|
|
|
131
127
|
return action
|
|
132
128
|
|
|
133
129
|
|
|
130
|
+
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idpermissions
|
|
131
|
+
PERMISSION_SCOPES: list[str] = [
|
|
132
|
+
"actions",
|
|
133
|
+
"attestations",
|
|
134
|
+
"checks",
|
|
135
|
+
"contents",
|
|
136
|
+
"deployments",
|
|
137
|
+
"discussions",
|
|
138
|
+
"id-token",
|
|
139
|
+
"issues",
|
|
140
|
+
"models",
|
|
141
|
+
"packages",
|
|
142
|
+
"pages",
|
|
143
|
+
"pull-requests",
|
|
144
|
+
"security-events",
|
|
145
|
+
"statuses",
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
|
|
134
149
|
class PermissionLevel(Enum):
|
|
135
150
|
none = ("none", 0)
|
|
136
151
|
read = ("read", 1)
|
|
@@ -151,21 +166,6 @@ class PermissionLevel(Enum):
|
|
|
151
166
|
return perm
|
|
152
167
|
raise ValueError(f"No Permission with label '{label}'")
|
|
153
168
|
|
|
154
|
-
def __le__(self, other):
|
|
155
|
-
if isinstance(other, PermissionLevel):
|
|
156
|
-
return self.number <= other.number
|
|
157
|
-
return NotImplemented
|
|
158
|
-
|
|
159
|
-
def __lt__(self, other):
|
|
160
|
-
if isinstance(other, PermissionLevel):
|
|
161
|
-
return self.number < other.number
|
|
162
|
-
return NotImplemented
|
|
163
|
-
|
|
164
|
-
def __ge__(self, other):
|
|
165
|
-
if isinstance(other, PermissionLevel):
|
|
166
|
-
return self.number >= other.number
|
|
167
|
-
return NotImplemented
|
|
168
|
-
|
|
169
169
|
def __gt__(self, other):
|
|
170
170
|
if isinstance(other, PermissionLevel):
|
|
171
171
|
return self.number > other.number
|
|
@@ -187,8 +187,18 @@ class Workflow:
|
|
|
187
187
|
template: Literal["workflow.html.jinja"] = "workflow.html.jinja"
|
|
188
188
|
|
|
189
189
|
@property
|
|
190
|
-
def
|
|
191
|
-
return
|
|
190
|
+
def permission_read_all(self) -> bool:
|
|
191
|
+
return all(
|
|
192
|
+
scope in self.permissions and self.permissions[scope] == PermissionLevel.read
|
|
193
|
+
for scope in PERMISSION_SCOPES
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def permission_write_all(self) -> bool:
|
|
198
|
+
return all(
|
|
199
|
+
scope in self.permissions and self.permissions[scope] == PermissionLevel.write
|
|
200
|
+
for scope in PERMISSION_SCOPES
|
|
201
|
+
)
|
|
192
202
|
|
|
193
203
|
@staticmethod
|
|
194
204
|
def from_file(file: PathLike, id: str) -> "Workflow | None":
|
|
@@ -213,13 +223,36 @@ class Workflow:
|
|
|
213
223
|
workflow.outputs.append(Output.from_data(key, **value))
|
|
214
224
|
for key, value in call.get("secrets", {}).items():
|
|
215
225
|
workflow.secrets.append(Secret.from_data(key, **value))
|
|
216
|
-
|
|
217
|
-
|
|
226
|
+
|
|
227
|
+
def set_all_permissions(level: str):
|
|
228
|
+
if level == "read-all":
|
|
229
|
+
for key in PERMISSION_SCOPES:
|
|
230
|
+
workflow.permissions[key] = PermissionLevel.read
|
|
231
|
+
elif level == "write-all":
|
|
232
|
+
for key in PERMISSION_SCOPES:
|
|
233
|
+
workflow.permissions[key] = PermissionLevel.write
|
|
234
|
+
else:
|
|
235
|
+
raise ValueError(f"Unknown permission level '{level}'")
|
|
236
|
+
|
|
237
|
+
if isinstance(permissions := data.get("permissions", {}), str):
|
|
238
|
+
set_all_permissions(permissions)
|
|
239
|
+
elif isinstance(permissions, dict):
|
|
240
|
+
for key, label in permissions.items():
|
|
241
|
+
workflow.permissions[key] = PermissionLevel.from_label(label)
|
|
242
|
+
else:
|
|
243
|
+
raise ValueError("permissions must be a string or a dictionary")
|
|
218
244
|
for job in data.get("jobs", {}).values():
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
245
|
+
if isinstance(permissions := job.get("permissions", {}), str):
|
|
246
|
+
set_all_permissions(permissions)
|
|
247
|
+
elif isinstance(permissions, dict):
|
|
248
|
+
for key, label in job.get("permissions", {}).items():
|
|
249
|
+
if key in workflow.permissions:
|
|
250
|
+
permission = PermissionLevel.from_label(label)
|
|
251
|
+
if permission > workflow.permissions[key]:
|
|
252
|
+
workflow.permissions[key] = permission
|
|
253
|
+
else:
|
|
254
|
+
workflow.permissions[key] = PermissionLevel.from_label(label)
|
|
255
|
+
else:
|
|
256
|
+
raise ValueError("permissions must be a string or a dictionary")
|
|
257
|
+
|
|
225
258
|
return workflow
|
|
@@ -22,7 +22,7 @@ Context:
|
|
|
22
22
|
|
|
23
23
|
{% include "heading.html.jinja" with context %}
|
|
24
24
|
|
|
25
|
-
{% set signature = data.id | format_action_signature(
|
|
25
|
+
{% set signature = data.id | format_action_signature(options.signature_repository if options.signature_repository else repository_name, options) %}
|
|
26
26
|
|
|
27
27
|
{% block signature scoped %}
|
|
28
28
|
{% if options.show_signature %}
|
|
@@ -20,7 +20,7 @@ Context:
|
|
|
20
20
|
<div class="doc doc-object doc-workflow">
|
|
21
21
|
{% include "heading.html.jinja" with context %}
|
|
22
22
|
|
|
23
|
-
{% set signature = data.id | format_action_signature(
|
|
23
|
+
{% set signature = data.id | format_action_signature(options.signature_repository if options.signature_repository else repository_name, options) %}
|
|
24
24
|
|
|
25
25
|
{% block signature scoped %}
|
|
26
26
|
{% if options.show_signature %}
|
|
@@ -29,11 +29,17 @@ Context:
|
|
|
29
29
|
{% filter highlight(language="yaml", inline=False, linenums=False) %}
|
|
30
30
|
uses: {{ signature }}
|
|
31
31
|
{% if options.signature_show_permissions and data.permissions|length > 0 %}
|
|
32
|
+
{% if data.permission_read_all %}
|
|
33
|
+
permissions: read-all
|
|
34
|
+
{% elif data.permission_write_all %}
|
|
35
|
+
permissions: write-all
|
|
36
|
+
{% else %}
|
|
32
37
|
permissions:
|
|
33
38
|
{% for scope, level in data.permissions | items %}
|
|
34
39
|
{{ scope }}: {{ level.label }}
|
|
35
40
|
{% endfor %}
|
|
36
41
|
{% endif %}
|
|
42
|
+
{% endif %}
|
|
37
43
|
{% if inputs|length > 0 %}
|
|
38
44
|
with:
|
|
39
45
|
{% for input in inputs %}
|
|
File without changes
|
{mkdocstrings_github-0.4.5.dist-info → mkdocstrings_github-0.5.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|