pdoc 14.3.0__tar.gz → 14.5.0__tar.gz

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.
Files changed (75) hide show
  1. {pdoc-14.3.0 → pdoc-14.5.0}/CHANGELOG.md +21 -0
  2. {pdoc-14.3.0/pdoc.egg-info → pdoc-14.5.0}/PKG-INFO +16 -6
  3. {pdoc-14.3.0 → pdoc-14.5.0}/README.md +0 -4
  4. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/__init__.py +22 -9
  5. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/doc.py +14 -3
  6. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/doc_ast.py +4 -7
  7. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/doc_pyi.py +11 -3
  8. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/doc_types.py +1 -0
  9. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/docstrings.py +39 -0
  10. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/extract.py +1 -0
  11. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/search.py +1 -0
  12. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/default/module.html.jinja2 +7 -4
  13. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/math.html.jinja2 +1 -0
  14. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/web.py +1 -0
  15. {pdoc-14.3.0 → pdoc-14.5.0/pdoc.egg-info}/PKG-INFO +16 -6
  16. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_doc.py +10 -0
  17. pdoc-14.5.0/test/test_docstrings.py +89 -0
  18. pdoc-14.3.0/test/test_docstrings.py +0 -31
  19. {pdoc-14.3.0 → pdoc-14.5.0}/LICENSE +0 -0
  20. {pdoc-14.3.0 → pdoc-14.5.0}/MANIFEST.in +0 -0
  21. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/__main__.py +0 -0
  22. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/_compat.py +0 -0
  23. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/markdown2/LICENSE +0 -0
  24. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/markdown2/README.md +0 -0
  25. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/markdown2/__init__.py +0 -0
  26. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/py.typed +0 -0
  27. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/render.py +0 -0
  28. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/render_helpers.py +0 -0
  29. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/README.md +0 -0
  30. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/build-search-index.js +0 -0
  31. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/content.css +0 -0
  32. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/custom.css +0 -0
  33. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/default/error.html.jinja2 +0 -0
  34. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/default/frame.html.jinja2 +0 -0
  35. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/default/index.html.jinja2 +0 -0
  36. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/README.md +0 -0
  37. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/bootstrap-reboot.min.css +0 -0
  38. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/box-arrow-in-left.svg +0 -0
  39. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/elasticlunr.min.js +0 -0
  40. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/favicon.svg +0 -0
  41. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/navtoggle.svg +0 -0
  42. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/pdoc-logo.svg +0 -0
  43. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/deprecated/resources/favicon.svg +0 -0
  44. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/layout.css +0 -0
  45. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/livereload.html.jinja2 +0 -0
  46. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/mermaid.html.jinja2 +0 -0
  47. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/bootstrap-reboot.min.css +0 -0
  48. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/box-arrow-in-left.svg +0 -0
  49. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/elasticlunr.min.js +0 -0
  50. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/exclamation-triangle-fill.svg +0 -0
  51. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/info-circle-fill.svg +0 -0
  52. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/lightning-fill.svg +0 -0
  53. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/navtoggle.svg +0 -0
  54. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/resources/pdoc-logo.svg +0 -0
  55. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/search.html.jinja2 +0 -0
  56. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/search.js.jinja2 +0 -0
  57. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/syntax-highlighting.css +0 -0
  58. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc/templates/theme.css +0 -0
  59. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc.egg-info/SOURCES.txt +0 -0
  60. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc.egg-info/dependency_links.txt +0 -0
  61. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc.egg-info/entry_points.txt +0 -0
  62. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc.egg-info/requires.txt +0 -0
  63. {pdoc-14.3.0 → pdoc-14.5.0}/pdoc.egg-info/top_level.txt +0 -0
  64. {pdoc-14.3.0 → pdoc-14.5.0}/pyproject.toml +0 -0
  65. {pdoc-14.3.0 → pdoc-14.5.0}/setup.cfg +0 -0
  66. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_doc_ast.py +0 -0
  67. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_doc_pyi.py +0 -0
  68. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_doc_types.py +0 -0
  69. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_extract.py +0 -0
  70. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_main.py +0 -0
  71. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_render_helpers.py +0 -0
  72. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_search.py +0 -0
  73. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_smoke.py +0 -0
  74. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_snapshot.py +0 -0
  75. {pdoc-14.3.0 → pdoc-14.5.0}/test/test_web.py +0 -0
@@ -5,6 +5,27 @@
5
5
  ## Unreleased: pdoc next
6
6
 
7
7
 
8
+ ## 2024-05-16: pdoc 14.5.0
9
+
10
+ - The `.. include:` rST directive now supports start-line, end-line, start-after, end-before options.
11
+ ([#684](https://github.com/mitmproxy/pdoc/pull/684), @frankharkins)
12
+ - Fix image embedding in included rST files.
13
+ ([#692](https://github.com/mitmproxy/pdoc/pull/692), @meghprkh)
14
+ - Support type-hints from stub-only packages. E.g: `scipy-stubs`
15
+ ([#671](https://github.com/mitmproxy/pdoc/pull/671), @erikdesmedt)
16
+ - Modify css styles for MathJax to remove unnessesary scroll bars
17
+ ([#675](https://github.com/mitmproxy/pdoc/pull/675), @thehappycheese)
18
+
19
+ ## 2024-01-18: pdoc 14.4.0
20
+
21
+ - Private methods can now be included in the documentation by adding `@public` to the docstring.
22
+ This complements the existing `@private` annotation.
23
+ ([#655](https://github.com/mitmproxy/pdoc/pull/655), @tmeyier)
24
+ - pdoc now correctly detects the source file for wrapped functions.
25
+ ([#657](https://github.com/mitmproxy/pdoc/pull/657), @tmeyier)
26
+ - Fixed a bug where memory addresses were not removed from output.
27
+ ([#663](https://github.com/mitmproxy/pdoc/pull/663), @mhils)
28
+
8
29
  ## 2023-12-22: pdoc 14.3.0
9
30
 
10
31
  - Improve rendering of `.pyi` type stubs containing `@typing.overload`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pdoc
3
- Version: 14.3.0
3
+ Version: 14.5.0
4
4
  Summary: API Documentation for Python Projects
5
5
  Author-email: Maximilian Hils <pdoc@maximilianhils.com>
6
6
  License: Unlicense
@@ -24,8 +24,22 @@ Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Typing :: Typed
25
25
  Requires-Python: >=3.8
26
26
  Description-Content-Type: text/markdown
27
- Provides-Extra: dev
28
27
  License-File: LICENSE
28
+ Requires-Dist: Jinja2>=2.11.0
29
+ Requires-Dist: pygments>=2.12.0
30
+ Requires-Dist: MarkupSafe
31
+ Requires-Dist: astunparse; python_version < "3.9"
32
+ Provides-Extra: dev
33
+ Requires-Dist: tox; extra == "dev"
34
+ Requires-Dist: ruff; extra == "dev"
35
+ Requires-Dist: mypy; extra == "dev"
36
+ Requires-Dist: types-pygments; extra == "dev"
37
+ Requires-Dist: pytest; extra == "dev"
38
+ Requires-Dist: pytest-cov; extra == "dev"
39
+ Requires-Dist: pytest-timeout; extra == "dev"
40
+ Requires-Dist: hypothesis; extra == "dev"
41
+ Requires-Dist: pygments>=2.14.0; extra == "dev"
42
+ Requires-Dist: pdoc-pyo3-sample-library==1.0.11; extra == "dev"
29
43
 
30
44
  <p align="center">
31
45
  <a href="https://pdoc.dev/"><img alt="pdoc" src="https://pdoc.dev/logo.svg" width="200" height="100" /></a>
@@ -95,10 +109,6 @@ As an open source project, pdoc welcomes contributions of all forms.
95
109
 
96
110
  [![Dev Guide](https://shields.mitmproxy.org/badge/dev_docs-CONTRIBUTING.md-blue)](https://github.com/mitmproxy/pdoc/blob/main/CONTRIBUTING.md)
97
111
 
98
- Also, please feel free to join our developer Slack!
99
-
100
- [![Slack Developer Chat](https://shields.mitmproxy.org/badge/slack-mitmproxy-E01563.svg)](http://slack.mitmproxy.org/)
101
-
102
112
 
103
113
  ## pdoc vs. pdoc3
104
114
 
@@ -66,10 +66,6 @@ As an open source project, pdoc welcomes contributions of all forms.
66
66
 
67
67
  [![Dev Guide](https://shields.mitmproxy.org/badge/dev_docs-CONTRIBUTING.md-blue)](https://github.com/mitmproxy/pdoc/blob/main/CONTRIBUTING.md)
68
68
 
69
- Also, please feel free to join our developer Slack!
70
-
71
- [![Slack Developer Chat](https://shields.mitmproxy.org/badge/slack-mitmproxy-E01563.svg)](http://slack.mitmproxy.org/)
72
-
73
69
 
74
70
  ## pdoc vs. pdoc3
75
71
 
@@ -176,18 +176,21 @@ class GoldenRetriever(Dog):
176
176
 
177
177
  The public interface of a module is determined through one of two
178
178
  ways.
179
-
180
179
  - If `__all__` is defined in the module, then all identifiers in that list will be considered public.
181
180
  No other identifiers will be considered public.
182
- - If `__all__` is not defined, then pdoc will consider all members public that
183
- 1. do not start with an underscore,
184
- 2. don't have `@private` in their docstring,
185
- 2. and are defined in the current module (i.e. they are not imported).
181
+ - If `__all__` is not defined, then pdoc will consider all items public that do not start with an
182
+ underscore and that are defined in the current module (i.e. they are not imported).
183
+
184
+ If you want to override the default behavior for a particular item,
185
+ you can do so by including an annotation in its docstring:
186
+
187
+ - `@private` hides an item unconditionally.
188
+ - <code>&#64;public</code> shows an item unconditionally.
186
189
 
187
- In general, we recommend keeping these conventions:
190
+ In general, we recommend keeping the following conventions:
188
191
 
189
192
  - If you want to document a private member, consider making it public.
190
- - If you want to hide a public member, consider making it private or add `@private` to their docstring,
193
+ - If you want to hide a public member, consider making it private.
191
194
  - If you want to document a special `__dunder__` method, the recommended way to do so is
192
195
  to not document the dunder method specifically, but to add some usage examples in the class documentation.
193
196
 
@@ -280,7 +283,16 @@ You can include external Markdown files in your documentation by using reStructu
280
283
  """
281
284
  ```
282
285
 
283
- Since version 11, pdoc processes such reStructuredText elements by default.
286
+ You can also include only parts of a file with the
287
+ [`start-line`, `end-line`, `start-after`, and `end-after` options](https://docutils.sourceforge.io/docs/ref/rst/directives.html#including-an-external-document-fragment):
288
+
289
+ ```python
290
+ """
291
+ .. include:: ../README.md
292
+ :start-line: 1
293
+ :end-before: Changelog
294
+ """
295
+ ```
284
296
 
285
297
 
286
298
  ## ...add a title page?
@@ -459,10 +471,11 @@ to your Python code before pdoc is used.
459
471
  It is also possible to create `pdoc.doc.Module` objects directly and modify them before rendering.
460
472
  You can find an example in [`examples/library-usage`](https://github.com/mitmproxy/pdoc/tree/main/examples/library-usage).
461
473
  '''
474
+
462
475
  from __future__ import annotations
463
476
 
464
477
  __docformat__ = "markdown" # explicitly disable rST processing in the examples above.
465
- __version__ = "14.3.0" # this is read from setup.py
478
+ __version__ = "14.5.0" # this is read from setup.py
466
479
 
467
480
  from pathlib import Path
468
481
  from typing import overload
@@ -15,6 +15,7 @@ All documentation types make heavy use of `@functools.cached_property` decorator
15
15
  This means they have a large set of attributes that are lazily computed on first access.
16
16
  By convention, all attributes are read-only, although this is not enforced at runtime.
17
17
  """
18
+
18
19
  from __future__ import annotations
19
20
 
20
21
  from abc import ABCMeta
@@ -887,6 +888,8 @@ class Function(Doc[types.FunctionType]):
887
888
  unwrapped = func.__func__ # type: ignore
888
889
  elif isinstance(func, singledispatchmethod):
889
890
  unwrapped = func.func # type: ignore
891
+ elif hasattr(func, "__wrapped__"):
892
+ unwrapped = func.__wrapped__
890
893
  else:
891
894
  unwrapped = func
892
895
  super().__init__(modulename, qualname, unwrapped, taken_from)
@@ -1028,7 +1031,9 @@ class Variable(Doc[None]):
1028
1031
 
1029
1032
  kind = "variable"
1030
1033
 
1031
- default_value: Any | empty # technically Any includes empty, but this conveys intent.
1034
+ default_value: (
1035
+ Any | empty
1036
+ ) # technically Any includes empty, but this conveys intent.
1032
1037
  """
1033
1038
  The variable's default value.
1034
1039
 
@@ -1139,7 +1144,7 @@ class Variable(Doc[None]):
1139
1144
  warnings.warn(f"repr({self.fullname}) raised an exception ({e!r})")
1140
1145
  return ""
1141
1146
 
1142
- pretty = re.sub(r" at 0x[0-9a-fA-F]+(?=>)", "", pretty)
1147
+ pretty = _remove_memory_addresses(pretty)
1143
1148
  return pretty
1144
1149
 
1145
1150
  @cached_property
@@ -1180,7 +1185,8 @@ class _PrettySignature(inspect.Signature):
1180
1185
  render_pos_only_separator = False
1181
1186
  render_kw_only_separator = True
1182
1187
  for param in self.parameters.values():
1183
- formatted = re.sub(r" at 0x[0-9a-fA-F]+(?=>$)", "", str(param))
1188
+ formatted = str(param)
1189
+ formatted = _remove_memory_addresses(formatted)
1184
1190
 
1185
1191
  kind = param.kind
1186
1192
 
@@ -1298,3 +1304,8 @@ def _safe_getdoc(obj: Any) -> str:
1298
1304
  return ""
1299
1305
  else:
1300
1306
  return doc.strip()
1307
+
1308
+
1309
+ def _remove_memory_addresses(x: str) -> str:
1310
+ """Remove memory addresses from repr() output"""
1311
+ return re.sub(r" at 0x[0-9a-fA-F]+(?=>)", "", x)
@@ -3,6 +3,7 @@ This module handles all interpretation of the *Abstract Syntax Tree (AST)* in pd
3
3
 
4
4
  Parsing the AST is done to extract docstrings, type annotations, and variable declarations from `__init__`.
5
5
  """
6
+
6
7
  from __future__ import annotations
7
8
 
8
9
  import ast
@@ -32,7 +33,6 @@ if TYPE_CHECKING:
32
33
  def get_source(obj: Any) -> str:
33
34
  """
34
35
  Returns the source code of the Python object `obj` as a str.
35
- This tries to first unwrap the method if it is wrapped and then calls `inspect.getsource`.
36
36
 
37
37
  If this fails, an empty string is returned.
38
38
  """
@@ -52,18 +52,15 @@ def _get_source(obj: Any) -> str:
52
52
 
53
53
 
54
54
  @overload
55
- def parse(obj: types.ModuleType) -> ast.Module:
56
- ...
55
+ def parse(obj: types.ModuleType) -> ast.Module: ...
57
56
 
58
57
 
59
58
  @overload
60
- def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef:
61
- ...
59
+ def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef: ...
62
60
 
63
61
 
64
62
  @overload
65
- def parse(obj: type) -> ast.ClassDef:
66
- ...
63
+ def parse(obj: type) -> ast.ClassDef: ...
67
64
 
68
65
 
69
66
  def parse(obj):
@@ -3,6 +3,7 @@ This module is responsible for patching `pdoc.doc.Doc` objects with type annotat
3
3
  in `.pyi` type stub files ([PEP 561](https://peps.python.org/pep-0561/)).
4
4
  This makes it possible to add type hints for native modules such as modules written using [PyO3](https://pyo3.rs/).
5
5
  """
6
+
6
7
  from __future__ import annotations
7
8
 
8
9
  from pathlib import Path
@@ -25,10 +26,17 @@ def find_stub_file(module_name: str) -> Path | None:
25
26
  """Try to find a .pyi file with type stubs for the given module name."""
26
27
  module_path = module_name.replace(".", "/")
27
28
 
28
- for dir in sys.path:
29
+ # Find .pyi-file in a PEP 0561 compatible stub-package
30
+ module_part_name = module_name.split(".")
31
+ module_part_name[0] = f"{module_part_name[0]}-stubs"
32
+ module_stub_path = "/".join(module_part_name)
33
+
34
+ for search_dir in sys.path:
29
35
  file_candidates = [
30
- Path(dir) / (module_path + ".pyi"),
31
- Path(dir) / (module_path + "/__init__.pyi"),
36
+ Path(search_dir) / (module_path + ".pyi"),
37
+ Path(search_dir) / (module_path + "/__init__.pyi"),
38
+ Path(search_dir) / (module_stub_path + ".pyi"),
39
+ Path(search_dir) / (module_stub_path + "/__init__.pyi"),
32
40
  ]
33
41
  for f in file_candidates:
34
42
  if f.exists():
@@ -5,6 +5,7 @@ In particular, it provides functionality to resolve
5
5
  [typing.ForwardRef](https://docs.python.org/3/library/typing.html#typing.ForwardRef) objects without raising an
6
6
  exception.
7
7
  """
8
+
8
9
  from __future__ import annotations
9
10
 
10
11
  import functools
@@ -10,6 +10,7 @@ If you miss a particular feature for your favorite flavor, contributions are wel
10
10
  That being said, please keep the complexity low and make sure that changes are
11
11
  accompanied by matching snapshot tests in `test/testdata/`.
12
12
  """
13
+
13
14
  from __future__ import annotations
14
15
 
15
16
  import base64
@@ -359,6 +360,38 @@ def _rst_links(contents: str) -> str:
359
360
  return contents
360
361
 
361
362
 
363
+ def _rst_extract_options(contents: str) -> tuple[str, dict[str, str]]:
364
+ """
365
+ Extract options from the beginning of reStructuredText directives.
366
+
367
+ Return the trimmed content and a dict of options.
368
+ """
369
+ options = {}
370
+ while match := re.match(r"^\s*:(.+?):(.*)([\s\S]*)", contents):
371
+ key, value, contents = match.groups()
372
+ options[key] = value.strip()
373
+
374
+ return contents, options
375
+
376
+
377
+ def _rst_include_trim(contents: str, options: dict[str, str]) -> str:
378
+ """
379
+ <https://docutils.sourceforge.io/docs/ref/rst/directives.html#include-options>
380
+ """
381
+ if "end-line" in options or "start-line" in options:
382
+ lines = contents.splitlines()
383
+ if i := options.get("end-line"):
384
+ lines = lines[: int(i)]
385
+ if i := options.get("start-line"):
386
+ lines = lines[int(i) :]
387
+ contents = "\n".join(lines)
388
+ if x := options.get("end-before"):
389
+ contents = contents[: contents.index(x)]
390
+ if x := options.get("start-after"):
391
+ contents = contents[contents.index(x) + len(x) :]
392
+ return contents
393
+
394
+
362
395
  def _rst_admonitions(contents: str, source_file: Path | None) -> str:
363
396
  """
364
397
  Convert reStructuredText admonitions - a bit tricky because they may already be indented themselves.
@@ -370,6 +403,7 @@ def _rst_admonitions(contents: str, source_file: Path | None) -> str:
370
403
  type = m.group("type")
371
404
  val = m.group("val").strip()
372
405
  contents = dedent(m.group("contents")).strip()
406
+ contents, options = _rst_extract_options(contents)
373
407
 
374
408
  if type == "include":
375
409
  loc = source_file or Path(".")
@@ -378,7 +412,12 @@ def _rst_admonitions(contents: str, source_file: Path | None) -> str:
378
412
  except OSError as e:
379
413
  warnings.warn(f"Cannot include {val!r}: {e}")
380
414
  included = "\n"
415
+ try:
416
+ included = _rst_include_trim(included, options) + "\n"
417
+ except ValueError as e:
418
+ warnings.warn(f"Failed to process include options for {val!r}: {e}")
381
419
  included = _rst_admonitions(included, loc.parent / val)
420
+ included = embed_images(included, loc.parent / val)
382
421
  return indent(included, ind)
383
422
  if type == "math":
384
423
  return f"{ind}$${val}{contents}$$\n"
@@ -3,6 +3,7 @@ This module handles the interaction with Python's module system,
3
3
  that is it loads the correct module based on whatever the user specified,
4
4
  and provides the rest of pdoc with some additional module metadata.
5
5
  """
6
+
6
7
  from __future__ import annotations
7
8
 
8
9
  from collections.abc import Iterable
@@ -41,6 +41,7 @@ to 27kB.
41
41
 
42
42
  If you wish to disable the search functionality, you can pass `--no-search` when invoking pdoc.
43
43
  """
44
+
44
45
  from __future__ import annotations
45
46
 
46
47
  from collections.abc import Callable
@@ -209,7 +209,7 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an
209
209
  {% enddefaultmacro %}
210
210
  {% defaultmacro docstring(var) %}
211
211
  {% if var.docstring %}
212
- <div class="docstring">{{ var.docstring | to_markdown | to_html | linkify(namespace=var.qualname) }}</div>
212
+ <div class="docstring">{{ var.docstring | replace("@public", "") | to_markdown | to_html | linkify(namespace=var.qualname) }}</div>
213
213
  {% endif %}
214
214
  {% enddefaultmacro %}
215
215
  {% defaultmacro nav_members(members) %}
@@ -239,10 +239,13 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an
239
239
  Implementing this as a macro makes it very easy to override with a custom template, see
240
240
  https://github.com/mitmproxy/pdoc/tree/main/examples/custom-template.
241
241
  #}
242
- {% if not include_undocumented and not doc.docstring %}
243
- {# hide members that are undocumented if include_undocumented has been toggled off. #}
244
- {% elif doc.docstring and "@private" in doc.docstring %}
242
+ {% if "@private" in doc.docstring %}
245
243
  {# hide members explicitly marked as @private #}
244
+ {% elif "@public" in doc.docstring %}
245
+ {# show members explicitly marked as @public #}
246
+ true
247
+ {% elif not include_undocumented and not doc.docstring %}
248
+ {# hide members that are undocumented if include_undocumented has been toggled off. #}
246
249
  {% elif doc.name == "__init__" and (doc.docstring or (doc.kind == "function" and doc.signature_without_self.parameters)) %}
247
250
  {# show constructors that have a docstring or at least one extra argument #}
248
251
  true
@@ -24,5 +24,6 @@
24
24
  <style>
25
25
  mjx-container {
26
26
  overflow-x: auto;
27
+ overflow-y: hidden;
27
28
  }
28
29
  </style>
@@ -5,6 +5,7 @@ We want to keep the number of dependencies as small as possible,
5
5
  so we are content with the builtin `http.server` module.
6
6
  It is a bit unergonomic compared to let's say flask, but good enough for our purposes.
7
7
  """
8
+
8
9
  from __future__ import annotations
9
10
 
10
11
  from collections.abc import Iterable
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pdoc
3
- Version: 14.3.0
3
+ Version: 14.5.0
4
4
  Summary: API Documentation for Python Projects
5
5
  Author-email: Maximilian Hils <pdoc@maximilianhils.com>
6
6
  License: Unlicense
@@ -24,8 +24,22 @@ Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Typing :: Typed
25
25
  Requires-Python: >=3.8
26
26
  Description-Content-Type: text/markdown
27
- Provides-Extra: dev
28
27
  License-File: LICENSE
28
+ Requires-Dist: Jinja2>=2.11.0
29
+ Requires-Dist: pygments>=2.12.0
30
+ Requires-Dist: MarkupSafe
31
+ Requires-Dist: astunparse; python_version < "3.9"
32
+ Provides-Extra: dev
33
+ Requires-Dist: tox; extra == "dev"
34
+ Requires-Dist: ruff; extra == "dev"
35
+ Requires-Dist: mypy; extra == "dev"
36
+ Requires-Dist: types-pygments; extra == "dev"
37
+ Requires-Dist: pytest; extra == "dev"
38
+ Requires-Dist: pytest-cov; extra == "dev"
39
+ Requires-Dist: pytest-timeout; extra == "dev"
40
+ Requires-Dist: hypothesis; extra == "dev"
41
+ Requires-Dist: pygments>=2.14.0; extra == "dev"
42
+ Requires-Dist: pdoc-pyo3-sample-library==1.0.11; extra == "dev"
29
43
 
30
44
  <p align="center">
31
45
  <a href="https://pdoc.dev/"><img alt="pdoc" src="https://pdoc.dev/logo.svg" width="200" height="100" /></a>
@@ -95,10 +109,6 @@ As an open source project, pdoc welcomes contributions of all forms.
95
109
 
96
110
  [![Dev Guide](https://shields.mitmproxy.org/badge/dev_docs-CONTRIBUTING.md-blue)](https://github.com/mitmproxy/pdoc/blob/main/CONTRIBUTING.md)
97
111
 
98
- Also, please feel free to join our developer Slack!
99
-
100
- [![Slack Developer Chat](https://shields.mitmproxy.org/badge/slack-mitmproxy-E01563.svg)](http://slack.mitmproxy.org/)
101
-
102
112
 
103
113
  ## pdoc vs. pdoc3
104
114
 
@@ -175,3 +175,13 @@ def test_default_value_masks_env_vars(monkeypatch):
175
175
  assert v2.default_value_str == "'42.0.1'"
176
176
  finally:
177
177
  _environ_lookup.cache_clear()
178
+
179
+
180
+ def test_source_file_method():
181
+ mod = extract.load_module(extract.parse_spec(here / "testdata" / "demo_long.py"))
182
+
183
+ m = Module(mod)
184
+
185
+ assert m.members["Foo"].members["a_cached_function"].source_file == (
186
+ here / "testdata" / "demo_long.py"
187
+ )
@@ -0,0 +1,89 @@
1
+ from pathlib import Path
2
+
3
+ from hypothesis import given
4
+ from hypothesis.strategies import text
5
+ import pytest
6
+
7
+ from pdoc import docstrings
8
+
9
+ # The important tests are in test_snapshot.py (and, by extension, testdata/)
10
+ # mostly some fuzzing here.
11
+
12
+
13
+ here = Path(__file__).parent.absolute()
14
+
15
+
16
+ @given(text())
17
+ def test_google(s):
18
+ ret = docstrings.google(s)
19
+ assert not s or ret
20
+
21
+
22
+ @given(text())
23
+ def test_numpy(s):
24
+ ret = docstrings.numpy(s)
25
+ assert not s or ret
26
+
27
+
28
+ @given(text())
29
+ def test_rst(s):
30
+ ret = docstrings.rst(s, None)
31
+ assert not s or ret
32
+
33
+
34
+ @given(text())
35
+ def test_rst_extract_options_fuzz(s):
36
+ content, options = docstrings._rst_extract_options(s)
37
+ assert not s or content or options
38
+
39
+
40
+ def test_rst_extract_options():
41
+ content = (
42
+ ":alpha: beta\n"
43
+ ":charlie:delta:foxtrot\n"
44
+ "rest of content\n"
45
+ ":option ignored: as follows content\n"
46
+ )
47
+ content, options = docstrings._rst_extract_options(content)
48
+ assert options == {
49
+ "alpha": "beta",
50
+ "charlie": "delta:foxtrot",
51
+ }
52
+ assert content == ("\nrest of content\n" ":option ignored: as follows content\n")
53
+
54
+
55
+ def test_rst_include_trim_lines():
56
+ content = "alpha\nbeta\ncharlie\ndelta\necho"
57
+ trimmed = docstrings._rst_include_trim(
58
+ content, {"start-line": "2", "end-line": "4"}
59
+ )
60
+ assert trimmed == "charlie\ndelta"
61
+
62
+
63
+ def test_rst_include_trim_pattern():
64
+ content = "alpha\nbeta\ncharlie\ndelta\necho"
65
+ trimmed = docstrings._rst_include_trim(
66
+ content, {"start-after": "beta", "end-before": "echo"}
67
+ )
68
+ assert trimmed == "\ncharlie\ndelta\n"
69
+
70
+
71
+ def test_rst_include_trim_mixture():
72
+ content = "alpha\nbeta\ncharlie\ndelta\necho"
73
+ trimmed = docstrings._rst_include_trim(
74
+ content, {"start-after": "beta", "end-line": "4"}
75
+ )
76
+ assert trimmed == "\ncharlie\ndelta"
77
+
78
+
79
+ def test_rst_include_nonexistent():
80
+ with pytest.warns(UserWarning, match="Cannot include 'nonexistent.txt'"):
81
+ docstrings.rst(".. include:: nonexistent.txt", None)
82
+
83
+
84
+ def test_rst_include_invalid_options():
85
+ with pytest.warns(UserWarning, match="Failed to process include options"):
86
+ docstrings.rst(
87
+ ".. include:: ../README.md\n :start-line: invalid",
88
+ here / "test_docstrings.py",
89
+ )
@@ -1,31 +0,0 @@
1
- from hypothesis import given
2
- from hypothesis.strategies import text
3
- import pytest
4
-
5
- from pdoc import docstrings
6
-
7
- # The important tests are in test_snapshot.py (and, by extension, testdata/)
8
- # only some fuzzing here.
9
-
10
-
11
- @given(text())
12
- def test_google(s):
13
- ret = docstrings.google(s)
14
- assert not s or ret
15
-
16
-
17
- @given(text())
18
- def test_numpy(s):
19
- ret = docstrings.numpy(s)
20
- assert not s or ret
21
-
22
-
23
- @given(text())
24
- def test_rst(s):
25
- ret = docstrings.rst(s, None)
26
- assert not s or ret
27
-
28
-
29
- def test_rst_include_nonexistent():
30
- with pytest.warns(UserWarning, match="Cannot include 'nonexistent.txt'"):
31
- docstrings.rst(".. include:: nonexistent.txt", None)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes