mkdocstrings-github 0.2.3__py3-none-any.whl → 0.2.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocstrings-github
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: A GitHub Action handler for mkdocstrings
5
5
  Author-email: Mark Hu <watermarkhu@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  mkdocstrings_handlers/github/__init__.py,sha256=0WdFUIq4Xu2ZFtlZNIYCQSoqcx3Ot9Wv41_X_dwbFww,248
2
- mkdocstrings_handlers/github/config.py,sha256=pSjA6gU-kC_mXQqNIIGOYEOhtX5VzZDT0H1hRFlGaj8,6089
3
- mkdocstrings_handlers/github/handler.py,sha256=aqrayPGjHONg1IbWxiw-VjgG38qBafW-_xOGww23xMg,9745
2
+ mkdocstrings_handlers/github/config.py,sha256=IxD1AiaQf3wC2cRabi3wUriimZDOhFOmpWw5CB-jSb4,6277
3
+ mkdocstrings_handlers/github/handler.py,sha256=gNmKpMfr1xc6WIlCZh3J3Oz9BAKDKvAsPJZt2C2oJWg,10813
4
4
  mkdocstrings_handlers/github/objects.py,sha256=qkRGcwwYCHsrc9JEmujnvIt00_B1y5cR0vGS5NRkuSg,7028
5
5
  mkdocstrings_handlers/github/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  mkdocstrings_handlers/github/rendering.py,sha256=8h5Zn62b3od9Dj3MNvMtAGg_ZyyLfJKv2Z2qGdFaKG8,2329
@@ -11,7 +11,7 @@ mkdocstrings_handlers/github/templates/material/outputs.html.jinja,sha256=ePu1v8
11
11
  mkdocstrings_handlers/github/templates/material/secrets.html.jinja,sha256=92ynVoZinsLEp7_sFS3mL2E2ngOXPPAtXzGAuGFvhmY,2782
12
12
  mkdocstrings_handlers/github/templates/material/style.css,sha256=R2hh1RfHwJ6XNT4YQl_txNkNXcPBZJMCBZn5kQEMQ6M,962
13
13
  mkdocstrings_handlers/github/templates/material/workflow.html.jinja,sha256=E1VUi2w7_NDkpS9VNrWRV52hhyhQvnKUrjPbV_j0Qcg,3312
14
- mkdocstrings_github-0.2.3.dist-info/METADATA,sha256=LKUKsU8uYtYxkKOZRZBhhEXu8dkRzUkogDIi4Ve_rus,3125
15
- mkdocstrings_github-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- mkdocstrings_github-0.2.3.dist-info/licenses/LICENSE,sha256=5enZtJ4zSp0Ps3jTqFQ4kadcx62BhgTaDNPrXWb3g3E,1069
17
- mkdocstrings_github-0.2.3.dist-info/RECORD,,
14
+ mkdocstrings_github-0.2.5.dist-info/METADATA,sha256=W0HKmmywoJdd-d5otuzbCWWI2hgQL77YYRJqR7YuJPM,3125
15
+ mkdocstrings_github-0.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ mkdocstrings_github-0.2.5.dist-info/licenses/LICENSE,sha256=5enZtJ4zSp0Ps3jTqFQ4kadcx62BhgTaDNPrXWb3g3E,1069
17
+ mkdocstrings_github-0.2.5.dist-info/RECORD,,
@@ -171,6 +171,11 @@ class GitHubOptions(BaseModel):
171
171
  class GitHubConfig(BaseModel):
172
172
  """Configuration options for the GitHub handler."""
173
173
 
174
+ hostname: str = Field(
175
+ default="github.com",
176
+ description="The hostname of the GitHub instance to use. This is only needed for GitHub Enterprise installations.",
177
+ )
178
+
174
179
  repo: str = Field(
175
180
  default="",
176
181
  description="""The GitHub repository in the format *owner/repo*.
@@ -74,76 +74,13 @@ class GitHubHandler(BaseHandler):
74
74
  self.major: str = ""
75
75
  self.semver: str = ""
76
76
 
77
- # Only run GitHub releases code if not running under pytest
78
- if (
77
+ # Only run GitHub releases code if required and not in testing
78
+ not_testing = "pytest" not in sys.modules
79
+ no_custom_tags = (
79
80
  rendering.ENV_MAJOR_TAG not in os.environ or rendering.ENV_SEMVER_TAG not in os.environ
80
- ) and "pytest" not in sys.modules:
81
- # Use PyGitHub to find last GitHub releases with tags matching vX.X.X and vX
82
-
83
- GH_HOST = os.environ.get("GH_HOST", "https://api.github.com")
84
-
85
- if (token_key := "GH_TOKEN") in os.environ:
86
- gh = Github(base_url=GH_HOST, auth=Auth.Token(os.environ[token_key]))
87
- elif (token_key := "GITHUB_TOKEN") in os.environ:
88
- gh = Github(base_url=GH_HOST, auth=Auth.Token(os.environ[token_key]))
89
- else:
90
- try:
91
- gh = Github(base_url=GH_HOST, auth=Auth.NetrcAuth())
92
- except RuntimeError:
93
- try:
94
- token = subprocess.check_output(["gh", "auth", "token"], text=True).strip()
95
- if token:
96
- gh = Github(base_url=GH_HOST, auth=Auth.Token(token))
97
- else:
98
- raise RuntimeError("No token from gh auth token")
99
- except Exception:
100
- _logger.warning(
101
- "Could not authenticate with GitHub to get releases. "
102
- "Consider setting .netrc, environment variable GH_TOKEN, "
103
- "or using GitHub CLI (`gh auth login`) to get GitHub releases.",
104
- )
105
- gh = Github(base_url=GH_HOST)
106
-
107
- owner, repo_name = self.config.repo.split("/", 1)
108
- gh_repo = gh.get_repo(f"{owner}/{repo_name}")
109
- releases = list(gh_repo.get_releases())
110
- for release in releases:
111
- tag = release.tag_name
112
- if not self.semver and SEMVER_PATTERN.match(tag):
113
- self.semver = tag
114
- if not self.major and MAJOR_PATTERN.match(tag):
115
- self.major = tag
116
- if self.semver and self.major:
117
- break
118
-
119
- if not self.semver or not self.major:
120
- if not self.semver and not self.major:
121
- messages = ("'vX.X.X' and 'vX'", "'semver and major'")
122
- elif not self.semver:
123
- messages = ("'vX.X.X'", "'semver'")
124
- else: # not self.major
125
- messages = ("'vX'", "'major'")
126
- _logger.warning(
127
- "Could not find suitable GitHub releases for repo '%s'. "
128
- "Make sure there are releases with tags matching %s, "
129
- "if you wish to use option signature_version %s.",
130
- self.config.repo,
131
- messages[0],
132
- messages[1],
133
- )
134
-
135
- if self.config.repo == ".":
136
- url = next(repo.remote("origin").urls)
137
- match = re.search(r"github.com[:/](?P<owner>[^/]+)/(?P<repo>[^/.]+)", url)
138
- if match:
139
- self.config.repo = f"{match.group('owner')}/{match.group('repo')}"
140
- else:
141
- _logger.warning(
142
- "Could not determine GitHub repository automatically from git remote URL '%s'. "
143
- "Make sure the remote URL is a GitHub URL, "
144
- "or set the 'repo' option in the configuration.",
145
- url,
146
- )
81
+ )
82
+ if not_testing and no_custom_tags:
83
+ self.get_releases()
147
84
 
148
85
  # Glob all workflow YAML files using pathlib
149
86
  working_tree_dir = Path(repo.working_tree_dir)
@@ -170,6 +107,98 @@ class GitHubHandler(BaseHandler):
170
107
  if action is not None:
171
108
  self.actions[action_file] = action
172
109
 
110
+ def get_releases(self) -> None:
111
+ gh_host = os.environ.get("GH_HOST", self.config.hostname)
112
+ if gh_host.startswith(("http://", "https://")):
113
+ base_url = gh_host
114
+ elif "/api/" in gh_host:
115
+ # If protocol is missing, default to https
116
+ base_url = f"https://{gh_host}"
117
+ elif gh_host.startswith("api."):
118
+ base_url = f"https://{gh_host}"
119
+ else:
120
+ base_url = f"https://api.{gh_host}"
121
+
122
+ _logger.debug(f"Using GitHub API base URL: {base_url}")
123
+
124
+ if (token_key := "GH_TOKEN") in os.environ:
125
+ gh = Github(base_url=base_url, auth=Auth.Token(os.environ[token_key]))
126
+ _logger.debug(f"Using GitHub authentication from environment variable {token_key}")
127
+ elif (token_key := "GITHUB_TOKEN") in os.environ:
128
+ gh = Github(base_url=base_url, auth=Auth.Token(os.environ[token_key]))
129
+ _logger.debug(f"Using GitHub authentication from environment variable {token_key}")
130
+ else:
131
+ try:
132
+ gh = Github(base_url=base_url, auth=Auth.NetrcAuth())
133
+ _logger.debug("Using GitHub authentication from .netrc")
134
+ except RuntimeError:
135
+ try:
136
+ token = subprocess.check_output(
137
+ ["gh", "auth", "token"], text=True, env=os.environ
138
+ ).strip()
139
+ if token:
140
+ gh = Github(base_url=base_url, auth=Auth.Token(token))
141
+ _logger.debug("Using GitHub authentication from gh cli.")
142
+ else:
143
+ raise RuntimeError("No token from gh auth token")
144
+ except Exception:
145
+ _logger.warning(
146
+ "Could not authenticate with GitHub to get releases. "
147
+ "Consider setting .netrc, environment variable GH_TOKEN, "
148
+ "or using GitHub CLI (`gh auth login`) to get GitHub releases.",
149
+ )
150
+ gh = Github(base_url=base_url)
151
+
152
+ # Determine owner and repo name
153
+ if "/" in self.config.repo:
154
+ owner, repo_name = self.config.repo.split("/", 1)
155
+ else:
156
+ # Try each remote to find a valid GitHub owner/repo
157
+ owner = None
158
+ repo_name = None
159
+ for remote in self.repo.remotes:
160
+ for url in remote.urls:
161
+ match = re.search(
162
+ r"(?P<host>[\w\.-]+)[/:](?P<owner>[^/]+)/(?P<repo>[^/.]+?)(?:\.git)?$",
163
+ url,
164
+ )
165
+ if match:
166
+ owner = match.group("owner")
167
+ repo_name = match.group("repo")
168
+ break
169
+ if owner and repo_name:
170
+ break
171
+ if not (owner and repo_name):
172
+ raise PluginError(
173
+ f"Could not determine GitHub repository owner/name from config.repo='{self.config.repo}' or any git remote URL."
174
+ )
175
+ self.config.repo = f"{owner}/{repo_name}"
176
+
177
+ # Get releases
178
+ gh_repo = gh.get_repo(f"{owner}/{repo_name}")
179
+ releases = list(gh_repo.get_releases())
180
+ for release in releases:
181
+ tag = release.tag_name
182
+ if not self.semver and SEMVER_PATTERN.match(tag):
183
+ self.semver = tag
184
+ if not self.major and MAJOR_PATTERN.match(tag):
185
+ self.major = tag
186
+ if self.semver and self.major:
187
+ break
188
+
189
+ if not self.semver or not self.major:
190
+ if not self.semver and not self.major:
191
+ messages = ("'vX.X.X' and 'vX'", "'semver and major'")
192
+ elif not self.semver:
193
+ messages = ("'vX.X.X'", "'semver'")
194
+ else: # not self.major
195
+ messages = ("'vX'", "'major'")
196
+ _logger.warning(
197
+ f"Could not find suitable GitHub releases for repo '{self.config.repo}'. "
198
+ f"Make sure there are releases with tags matching {messages[0]}, "
199
+ f"if you wish to use option signature_version {messages[1]}.",
200
+ )
201
+
173
202
  def get_options(self, local_options: Mapping[str, Any]) -> HandlerOptions:
174
203
  """Get combined default, global and local options.
175
204