pdoc 14.4.0__tar.gz → 14.5.1__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.4.0 → pdoc-14.5.1}/CHANGELOG.md +15 -0
  2. {pdoc-14.4.0/pdoc.egg-info → pdoc-14.5.1}/PKG-INFO +16 -6
  3. {pdoc-14.4.0 → pdoc-14.5.1}/README.md +0 -4
  4. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/__init__.py +12 -2
  5. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/doc.py +4 -1
  6. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/doc_ast.py +4 -6
  7. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/doc_pyi.py +11 -3
  8. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/doc_types.py +1 -0
  9. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/docstrings.py +39 -0
  10. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/extract.py +1 -0
  11. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/search.py +1 -0
  12. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/math.html.jinja2 +1 -1
  13. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/web.py +1 -0
  14. {pdoc-14.4.0 → pdoc-14.5.1/pdoc.egg-info}/PKG-INFO +16 -6
  15. pdoc-14.5.1/test/test_docstrings.py +89 -0
  16. pdoc-14.4.0/test/test_docstrings.py +0 -31
  17. {pdoc-14.4.0 → pdoc-14.5.1}/LICENSE +0 -0
  18. {pdoc-14.4.0 → pdoc-14.5.1}/MANIFEST.in +0 -0
  19. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/__main__.py +0 -0
  20. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/_compat.py +0 -0
  21. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/markdown2/LICENSE +0 -0
  22. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/markdown2/README.md +0 -0
  23. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/markdown2/__init__.py +0 -0
  24. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/py.typed +0 -0
  25. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/render.py +0 -0
  26. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/render_helpers.py +0 -0
  27. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/README.md +0 -0
  28. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/build-search-index.js +0 -0
  29. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/content.css +0 -0
  30. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/custom.css +0 -0
  31. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/default/error.html.jinja2 +0 -0
  32. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/default/frame.html.jinja2 +0 -0
  33. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/default/index.html.jinja2 +0 -0
  34. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/default/module.html.jinja2 +0 -0
  35. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/README.md +0 -0
  36. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/bootstrap-reboot.min.css +0 -0
  37. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/box-arrow-in-left.svg +0 -0
  38. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/elasticlunr.min.js +0 -0
  39. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/favicon.svg +0 -0
  40. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/navtoggle.svg +0 -0
  41. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/pdoc-logo.svg +0 -0
  42. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/deprecated/resources/favicon.svg +0 -0
  43. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/layout.css +0 -0
  44. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/livereload.html.jinja2 +0 -0
  45. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/mermaid.html.jinja2 +0 -0
  46. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/bootstrap-reboot.min.css +0 -0
  47. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/box-arrow-in-left.svg +0 -0
  48. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/elasticlunr.min.js +0 -0
  49. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/exclamation-triangle-fill.svg +0 -0
  50. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/info-circle-fill.svg +0 -0
  51. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/lightning-fill.svg +0 -0
  52. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/navtoggle.svg +0 -0
  53. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/resources/pdoc-logo.svg +0 -0
  54. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/search.html.jinja2 +0 -0
  55. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/search.js.jinja2 +0 -0
  56. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/syntax-highlighting.css +0 -0
  57. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc/templates/theme.css +0 -0
  58. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc.egg-info/SOURCES.txt +0 -0
  59. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc.egg-info/dependency_links.txt +0 -0
  60. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc.egg-info/entry_points.txt +0 -0
  61. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc.egg-info/requires.txt +0 -0
  62. {pdoc-14.4.0 → pdoc-14.5.1}/pdoc.egg-info/top_level.txt +0 -0
  63. {pdoc-14.4.0 → pdoc-14.5.1}/pyproject.toml +0 -0
  64. {pdoc-14.4.0 → pdoc-14.5.1}/setup.cfg +0 -0
  65. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_doc.py +0 -0
  66. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_doc_ast.py +0 -0
  67. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_doc_pyi.py +0 -0
  68. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_doc_types.py +0 -0
  69. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_extract.py +0 -0
  70. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_main.py +0 -0
  71. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_render_helpers.py +0 -0
  72. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_search.py +0 -0
  73. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_smoke.py +0 -0
  74. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_snapshot.py +0 -0
  75. {pdoc-14.4.0 → pdoc-14.5.1}/test/test_web.py +0 -0
@@ -4,6 +4,21 @@
4
4
 
5
5
  ## Unreleased: pdoc next
6
6
 
7
+ - **Security:** Documentation generated with math mode (`pdoc --math`) does not include scripts
8
+ from polyfill.io anymore. See https://sansec.io/research/polyfill-supply-chain-attack for details.
9
+ Users who produce documentation with math mode should update immediately. All other users are unaffected.
10
+ ([#703](https://github.com/mitmproxy/pdoc/pull/703), @adhintz)
11
+
12
+ ## 2024-05-16: pdoc 14.5.0
13
+
14
+ - The `.. include:` rST directive now supports start-line, end-line, start-after, end-before options.
15
+ ([#684](https://github.com/mitmproxy/pdoc/pull/684), @frankharkins)
16
+ - Fix image embedding in included rST files.
17
+ ([#692](https://github.com/mitmproxy/pdoc/pull/692), @meghprkh)
18
+ - Support type-hints from stub-only packages. E.g: `scipy-stubs`
19
+ ([#671](https://github.com/mitmproxy/pdoc/pull/671), @erikdesmedt)
20
+ - Modify css styles for MathJax to remove unnessesary scroll bars
21
+ ([#675](https://github.com/mitmproxy/pdoc/pull/675), @thehappycheese)
7
22
 
8
23
  ## 2024-01-18: pdoc 14.4.0
9
24
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pdoc
3
- Version: 14.4.0
3
+ Version: 14.5.1
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
 
@@ -283,7 +283,16 @@ You can include external Markdown files in your documentation by using reStructu
283
283
  """
284
284
  ```
285
285
 
286
- 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
+ ```
287
296
 
288
297
 
289
298
  ## ...add a title page?
@@ -462,10 +471,11 @@ to your Python code before pdoc is used.
462
471
  It is also possible to create `pdoc.doc.Module` objects directly and modify them before rendering.
463
472
  You can find an example in [`examples/library-usage`](https://github.com/mitmproxy/pdoc/tree/main/examples/library-usage).
464
473
  '''
474
+
465
475
  from __future__ import annotations
466
476
 
467
477
  __docformat__ = "markdown" # explicitly disable rST processing in the examples above.
468
- __version__ = "14.4.0" # this is read from setup.py
478
+ __version__ = "14.5.1" # this is read from setup.py
469
479
 
470
480
  from pathlib import Path
471
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
@@ -1030,7 +1031,9 @@ class Variable(Doc[None]):
1030
1031
 
1031
1032
  kind = "variable"
1032
1033
 
1033
- 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.
1034
1037
  """
1035
1038
  The variable's default value.
1036
1039
 
@@ -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
@@ -51,18 +52,15 @@ def _get_source(obj: Any) -> str:
51
52
 
52
53
 
53
54
  @overload
54
- def parse(obj: types.ModuleType) -> ast.Module:
55
- ...
55
+ def parse(obj: types.ModuleType) -> ast.Module: ...
56
56
 
57
57
 
58
58
  @overload
59
- def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef:
60
- ...
59
+ def parse(obj: types.FunctionType) -> ast.FunctionDef | ast.AsyncFunctionDef: ...
61
60
 
62
61
 
63
62
  @overload
64
- def parse(obj: type) -> ast.ClassDef:
65
- ...
63
+ def parse(obj: type) -> ast.ClassDef: ...
66
64
 
67
65
 
68
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
@@ -10,7 +10,6 @@
10
10
  }
11
11
  };
12
12
  </script>
13
- <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
14
13
  <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
15
14
  <script>
16
15
  /* Re-invoke MathJax when DOM content changes, for example during search. */
@@ -24,5 +23,6 @@
24
23
  <style>
25
24
  mjx-container {
26
25
  overflow-x: auto;
26
+ overflow-y: hidden;
27
27
  }
28
28
  </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.4.0
3
+ Version: 14.5.1
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
 
@@ -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
File without changes