hippogriffe 0.1.0__py3-none-any.whl → 0.1.2__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.
hippogriffe/_extension.py CHANGED
@@ -23,6 +23,10 @@ def get_templates_path():
23
23
  return _here / "templates"
24
24
 
25
25
 
26
+ class _NotInPublicApiException(Exception):
27
+ pass
28
+
29
+
26
30
  class _PublicApi:
27
31
  def __init__(
28
32
  self,
@@ -100,7 +104,8 @@ class _PublicApi:
100
104
  for m in self._public_modules:
101
105
  if key.startswith(m + "."):
102
106
  return key, False
103
- raise Exception(
107
+ # Not using `KeyError` because that displays its message with `repr`.
108
+ raise _NotInPublicApiException(
104
109
  f"Tried and failed to find {key} in the public API. Commons reasons "
105
110
  "for this error are:\n"
106
111
  "- If it is from outside this package, then that package is not listed "
@@ -216,7 +221,7 @@ def _collect_bases(
216
221
  elif isinstance(base, griffe.Class):
217
222
  try:
218
223
  base, autoref = public_api[base.path]
219
- except KeyError:
224
+ except _NotInPublicApiException:
220
225
  bases.update(_collect_bases(base, public_api, public_modules))
221
226
  else:
222
227
  bases[base] = autoref
@@ -230,18 +235,6 @@ def _get_repo_url(repo_url: None | str) -> tuple[pathlib.Path, str]:
230
235
  "`hippogriffe.show_source_links` requires specifying a top-level "
231
236
  "`repo_url`."
232
237
  )
233
- is_github = (
234
- repo_url.removeprefix("https://")
235
- .removeprefix("https://")
236
- .startswith("github.com")
237
- )
238
- if not is_github:
239
- # We need to format the `repo_url` to what the repo expects, so we have to
240
- # hardcode this in.
241
- raise ValueError(
242
- "`hippogriffe.show_source_links` currently only supports "
243
- "`repo_url: https://github.com/...`."
244
- )
245
238
  try:
246
239
  git_head = subprocess.run(
247
240
  ["git", "rev-parse", "HEAD"], capture_output=True, check=False
@@ -259,9 +252,19 @@ def _get_repo_url(repo_url: None | str) -> tuple[pathlib.Path, str]:
259
252
  else:
260
253
  toplevel = pathlib.Path(git_toplevel.stdout.decode().strip())
261
254
  commit_hash = git_head.stdout.decode().strip()
262
- repo_url = (
263
- f"{repo_url.removesuffix('/')}/blob/{commit_hash}/{{path}}#L{{start}}-{{end}}"
264
- )
255
+ raw_url = repo_url.removeprefix("https://").removeprefix("https://")
256
+ if raw_url.startswith("github.com") or raw_url.startswith("gitlab.com"):
257
+ repo_url = (
258
+ f"{repo_url.removesuffix('/')}/blob/{commit_hash}/{{path}}"
259
+ "#L{start}-{end}"
260
+ )
261
+ else:
262
+ # We need to format the `repo_url` to what the repo expects, so we have to
263
+ # hardcode this in.
264
+ raise ValueError(
265
+ "`hippogriffe.show_source_links` currently only supports "
266
+ "`repo_url: https://github.com/...` and `repo_url: https://gitlab.com/...`."
267
+ )
265
268
  return toplevel, repo_url
266
269
 
267
270
 
@@ -283,7 +286,31 @@ class HippogriffeExtension(griffe.Extension):
283
286
  ) -> None:
284
287
  del agent, kwargs
285
288
  assert not isinstance(node, ast.AST)
286
- func.extra["hippogriffe"]["signature"] = inspect.signature(node.obj)
289
+ signature = inspect.signature(node.obj)
290
+ try:
291
+ name = node.obj.__name__
292
+ except AttributeError:
293
+ pass
294
+ else:
295
+ if name == "__init__":
296
+ signature = signature.replace(return_annotation=inspect.Signature.empty)
297
+ func.extra["hippogriffe"]["signature"] = signature
298
+
299
+ def on_attribute_instance(
300
+ self,
301
+ *,
302
+ node: ast.AST | griffe.ObjectNode,
303
+ attr: griffe.Attribute,
304
+ agent: griffe.Visitor | griffe.Inspector,
305
+ **kwargs: Any,
306
+ ) -> None:
307
+ del node, agent, kwargs
308
+ # Knowing the value is IMO usually not useful. That is what documentation
309
+ # directly is for.
310
+ attr.value = None
311
+ # This is used to indicate that it is a module attribute, but IMO that's not
312
+ # super clear in the docs.
313
+ attr.labels.discard("module")
287
314
 
288
315
  def on_package_loaded(
289
316
  self, *, pkg: griffe.Module, loader: griffe.GriffeLoader, **kwargs: Any
hippogriffe/_plugin.py CHANGED
@@ -12,6 +12,10 @@ from mkdocstrings import AutoDocProcessor
12
12
 
13
13
 
14
14
  _here = pathlib.Path(__file__).resolve().parent
15
+ _regex = re.compile(
16
+ r"^\s*" + AutoDocProcessor.regex.pattern.removeprefix("^"),
17
+ AutoDocProcessor.regex.flags,
18
+ )
15
19
 
16
20
 
17
21
  class PluginConfig(Config):
@@ -102,7 +106,7 @@ class HippogriffePlugin(BasePlugin[PluginConfig]):
102
106
  top_level_public_api.remove("")
103
107
  for file in files:
104
108
  if file.is_documentation_page():
105
- for match in AutoDocProcessor.regex.finditer(file.content_string):
109
+ for match in _regex.finditer(file.content_string):
106
110
  top_level_public_api.add(match["name"])
107
111
  files.append(
108
112
  File.generated(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hippogriffe
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: A simple ipynb->md converter for MkDocs
5
5
  Project-URL: repository, https://github.com/patrick-kidger/hippogriffe
6
6
  Author-email: Patrick Kidger <contact@kidger.site>
@@ -229,6 +229,8 @@ This is a set of tweaks on top of the MkDocs + `mkdocstrings[python]` + `griffe`
229
229
  - Fixes unions/generics/etc. to display as e.g. `int | str` rather than just `Union`, or `tuple[int, str]` rather than just `tuple`.
230
230
  - Respects your public API: if a type is declared in your documentation as `::: yourlib.Foo` then its usage in type annotations will match: `some_fn(foo: yourlib.Foo)`.
231
231
  - Show base classes inline after the class.
232
+ - Drops the `-> None` return annotation from `__init__` methods.
233
+ - Attributes display as `[attr] somelib.someattr` instead of `[attr] somelib.someattr = some_value [module]`. (I don't find usually-long default values to be useful documentation, nor the 'module' tag to be informative.)
232
234
 
233
235
  Before | After
234
236
  :---------------------:|:----------------------:
@@ -1,12 +1,12 @@
1
1
  hippogriffe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- hippogriffe/_extension.py,sha256=hkcHakdZO2l4IWfmz6gXY4lNItj8pVlJjlLAIoz9TMA,12970
3
- hippogriffe/_plugin.py,sha256=OQ6B_iWSur3yiYr5rxTpGahFtWzuRLqCQVndWoegFcY,4459
2
+ hippogriffe/_extension.py,sha256=zg3Q5h5ziLOX46BXYOpwrXQ7EFGJP7UwKXjKMh7GYjY,14014
3
+ hippogriffe/_plugin.py,sha256=H0oPka_7URED9wOVYAWUNTWTJXFmH6q7g2W2G5hy64c,4564
4
4
  hippogriffe/assets/_hippogriffe.css,sha256=BgyZLCaOaZNgQErdUb01vpNso4ilUMmoZ5d_OeVpfRE,147
5
5
  hippogriffe/templates/material/hippogriffe/class.html.jinja,sha256=5i624gIuZfnf5toH3jWclzg1qlekqIZ2ODbpzeZcULw,954
6
6
  hippogriffe/templates/material/hippogriffe/fn.html.jinja,sha256=vxrWOPkPkGD3Po9hbcYlyEjsJKhJmOHic4G5t2J0djc,196
7
7
  hippogriffe/templates/material/hippogriffe/hippogriffe.jinja,sha256=KxTBKY0XqiFzqTT1iqFxhN2GhmtwLT4GWc8S86zyjOc,583
8
- hippogriffe-0.1.0.dist-info/METADATA,sha256=VON3g_gsdXPZ1g1A_hxcCs8i7g5aqPFSSULd5T9kx0A,15988
9
- hippogriffe-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- hippogriffe-0.1.0.dist-info/entry_points.txt,sha256=Et3dFNWG-biZ7XCvPI9na-buFT_hht1YT0p0JDNEQQM,158
11
- hippogriffe-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- hippogriffe-0.1.0.dist-info/RECORD,,
8
+ hippogriffe-0.1.2.dist-info/METADATA,sha256=IiWbdutZDQd0mrtyQyES29rTdHJEyrZmK7I0jQL0UJ0,16274
9
+ hippogriffe-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ hippogriffe-0.1.2.dist-info/entry_points.txt,sha256=Et3dFNWG-biZ7XCvPI9na-buFT_hht1YT0p0JDNEQQM,158
11
+ hippogriffe-0.1.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ hippogriffe-0.1.2.dist-info/RECORD,,