mkdocstrings-python 2.0.6__py3-none-any.whl → 2.0.7__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.
@@ -31,6 +31,7 @@ from mkdocstrings_handlers.python._internal.rendering import (
31
31
  do_format_type_alias,
32
32
  do_get_template,
33
33
  do_order_members,
34
+ do_source_location,
34
35
  do_split_path,
35
36
  do_stash_crossref,
36
37
  )
@@ -64,6 +65,7 @@ __all__ = [
64
65
  "do_format_type_alias",
65
66
  "do_get_template",
66
67
  "do_order_members",
68
+ "do_source_location",
67
69
  "do_split_path",
68
70
  "do_stash_crossref",
69
71
  "get_handler",
@@ -345,6 +345,7 @@ class PythonHandler(BaseHandler):
345
345
  self.env.filters["filter_objects"] = rendering.do_filter_objects
346
346
  self.env.filters["stash_crossref"] = rendering.do_stash_crossref
347
347
  self.env.filters["get_template"] = rendering.do_get_template
348
+ self.env.filters["source_location"] = rendering.do_source_location
348
349
  self.env.filters["as_attributes_section"] = rendering.do_as_attributes_section
349
350
  self.env.filters["as_functions_section"] = rendering.do_as_functions_section
350
351
  self.env.filters["as_classes_section"] = rendering.do_as_classes_section
@@ -11,6 +11,7 @@ from collections import defaultdict
11
11
  from contextlib import suppress
12
12
  from dataclasses import replace
13
13
  from functools import lru_cache
14
+ from pathlib import Path
14
15
  from re import Pattern
15
16
  from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal, TypeVar
16
17
 
@@ -590,6 +591,30 @@ def do_get_template(obj: Object | Alias) -> str:
590
591
  return f"{name}.html.jinja"
591
592
 
592
593
 
594
+ def do_source_location(obj: Object | Alias) -> Path:
595
+ """Get the file path displayed in an object's source block label.
596
+
597
+ Environment paths are never displayed: when the object's file lives in
598
+ a `site-packages` directory (for example a virtual environment inside
599
+ the current working directory), the path below `site-packages` is
600
+ returned instead.
601
+
602
+ Parameters:
603
+ obj: A Griffe object.
604
+
605
+ Returns:
606
+ The file path to display.
607
+ """
608
+ relative_filepath = obj.relative_filepath
609
+ parts = relative_filepath.parts
610
+ if "site-packages" in parts:
611
+ anchor = len(parts) - 1 - parts[::-1].index("site-packages")
612
+ return Path(*parts[anchor + 1 :])
613
+ if relative_filepath.is_absolute():
614
+ return obj.relative_package_filepath
615
+ return relative_filepath
616
+
617
+
593
618
  @pass_context
594
619
  def do_as_attributes_section(
595
620
  context: Context, # noqa: ARG001
@@ -249,26 +249,14 @@ Context:
249
249
  {% if "__init__" in all_members and all_members["__init__"].source %}
250
250
  {% with init = all_members["__init__"] %}
251
251
  <details class="mkdocstrings-source">
252
- <summary>{{ lang.t("Source code in") }} <code>
253
- {%- if init.relative_filepath.is_absolute() -%}
254
- {{ init.relative_package_filepath }}
255
- {%- else -%}
256
- {{ init.relative_filepath }}
257
- {%- endif -%}
258
- </code></summary>
252
+ <summary>{{ lang.t("Source code in") }} <code>{{ init|source_location }}</code></summary>
259
253
  {{ init.source|highlight(language="python", linestart=init.lineno or 0, linenums=True) }}
260
254
  </details>
261
255
  {% endwith %}
262
256
  {% endif %}
263
257
  {% elif class.source %}
264
258
  <details class="mkdocstrings-source">
265
- <summary>{{ lang.t("Source code in") }} <code>
266
- {%- if class.relative_filepath.is_absolute() -%}
267
- {{ class.relative_package_filepath }}
268
- {%- else -%}
269
- {{ class.relative_filepath }}
270
- {%- endif -%}
271
- </code></summary>
259
+ <summary>{{ lang.t("Source code in") }} <code>{{ class|source_location }}</code></summary>
272
260
  {{ class.source|highlight(language="python", linestart=class.lineno or 0, linenums=True) }}
273
261
  </details>
274
262
  {% endif %}
@@ -146,13 +146,7 @@ Context:
146
146
  -#}
147
147
  {% if config.show_source and function.source %}
148
148
  <details class="mkdocstrings-source">
149
- <summary>{{ lang.t("Source code in") }} <code>
150
- {%- if function.relative_filepath.is_absolute() -%}
151
- {{ function.relative_package_filepath }}
152
- {%- else -%}
153
- {{ function.relative_filepath }}
154
- {%- endif -%}
155
- </code></summary>
149
+ <summary>{{ lang.t("Source code in") }} <code>{{ function|source_location }}</code></summary>
156
150
  {{ function.source|highlight(language="python", linestart=function.lineno or 0, linenums=True) }}
157
151
  </details>
158
152
  {% endif %}
@@ -208,26 +208,14 @@ Context:
208
208
  {% if "__init__" in class.all_members and class.all_members["__init__"].source %}
209
209
  {% with init = class.all_members["__init__"] %}
210
210
  <details class="quote">
211
- <summary>Source code in <code>
212
- {%- if init.relative_filepath.is_absolute() -%}
213
- {{ init.relative_package_filepath }}
214
- {%- else -%}
215
- {{ init.relative_filepath }}
216
- {%- endif -%}
217
- </code></summary>
211
+ <summary>Source code in <code>{{ init|source_location }}</code></summary>
218
212
  {{ init.source|highlight(language="python", linestart=init.lineno or 0, linenums=True) }}
219
213
  </details>
220
214
  {% endwith %}
221
215
  {% endif %}
222
216
  {% elif class.source %}
223
217
  <details class="quote">
224
- <summary>Source code in <code>
225
- {%- if class.relative_filepath.is_absolute() -%}
226
- {{ class.relative_package_filepath }}
227
- {%- else -%}
228
- {{ class.relative_filepath }}
229
- {%- endif -%}
230
- </code></summary>
218
+ <summary>Source code in <code>{{ class|source_location }}</code></summary>
231
219
  {{ class.source|highlight(language="python", linestart=class.lineno or 0, linenums=True) }}
232
220
  </details>
233
221
  {% endif %}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocstrings-python
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: A Python handler for mkdocstrings.
5
5
  Author-Email: =?utf-8?q?Timoth=C3=A9e_Mazzucotelli?= <dev@pawamoy.fr>
6
6
  License-Expression: ISC
@@ -1,14 +1,14 @@
1
- mkdocstrings_handlers/python/__init__.py,sha256=Kxy1zA4JJy0aWxUa2_xl5PfYV2-mrBKJ9Re56dq3s94,1650
1
+ mkdocstrings_handlers/python/__init__.py,sha256=nMq6EQFwlnoSHY5FZAS0Fpa-fnb_piBv0yGIW1x13EE,1700
2
2
  mkdocstrings_handlers/python/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  mkdocstrings_handlers/python/_internal/config.py,sha256=iSnsL-DXqWSm_0YKv-2giDxTdljxZWvDgTGkCo9GBPg,35261
4
4
  mkdocstrings_handlers/python/_internal/debug.py,sha256=A6B3w6LWN22kYtvvbmz7vnh8Pr5hzvtrHhM3-Es8Isg,2882
5
- mkdocstrings_handlers/python/_internal/handler.py,sha256=Wn_0S4pw511tfC0m24sfbSNiUDlScDiJqEMFgrITdS8,16972
6
- mkdocstrings_handlers/python/_internal/rendering.py,sha256=Nrkoi1FeRrsEGOUmiBuu13mm0LJXktQr3Zt2iTb3mQE,28564
5
+ mkdocstrings_handlers/python/_internal/handler.py,sha256=iYVzWehbTd3vM6K0sJJ-Oqklezv6xsyv0S6SWdGklXo,17047
6
+ mkdocstrings_handlers/python/_internal/rendering.py,sha256=3JnVhlZob-Py5aWu-wDN6nsgAMBtOhyvTSa989J_6rA,29399
7
7
  mkdocstrings_handlers/python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  mkdocstrings_handlers/python/templates/material/_base/attribute.html.jinja,sha256=ajtKaGxs9-VJzPNiXbQTYTO6ADq8Ck9M9x2BfXakG0g,4838
9
9
  mkdocstrings_handlers/python/templates/material/_base/backlinks.html.jinja,sha256=k8eX0lyQmmooaEotjYngdXO8RJldjixvZW30S5jGXOA,2109
10
10
  mkdocstrings_handlers/python/templates/material/_base/children.html.jinja,sha256=1q7RS0i6SkNriRtGX8BC2wzKhp3pPcLVSJWBEUmZOSg,8153
11
- mkdocstrings_handlers/python/templates/material/_base/class.html.jinja,sha256=Wo_g0ag5P7d3rolVRYxtJMIT2U1KC9h7rh8yQFcuprQ,12153
11
+ mkdocstrings_handlers/python/templates/material/_base/class.html.jinja,sha256=ZSDeKPYttMyTbZ9udURpJ4tGm2Nl7HOMaCJlVoG2wzs,11675
12
12
  mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja,sha256=iKi-31JKoHwG7-w3S88A9YTu9kuV6-c9gwKb8bUtXuw,3440
13
13
  mkdocstrings_handlers/python/templates/material/_base/docstring/admonition.html.jinja,sha256=VFwImgb1toxkjWqyhTNFQbyYE3d11yXI___3vpIu2u0,687
14
14
  mkdocstrings_handlers/python/templates/material/_base/docstring/attributes.html.jinja,sha256=WVy3pU1KGIhk1rFdADmWydj-KUXZW7STC_OWAl0yFyk,4349
@@ -26,7 +26,7 @@ mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.
26
26
  mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html.jinja,sha256=evSdVXZwKpHIJ7dnCP3njB0DD7rcJPgTPgeG54jRIUE,3612
27
27
  mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html.jinja,sha256=bo1Fjfw21VZRdf8MPzReIr8sCFPDoBBWQloXJ42IObQ,4699
28
28
  mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja,sha256=zjjO_q9oCQCpVx6iR0adfog_lhQ85uM4oHZDJO_sKqU,6592
29
- mkdocstrings_handlers/python/templates/material/_base/function.html.jinja,sha256=AljcQjr1e6laOEpp4LRPKjnQNkN99zcPISxbXeEqPf4,6239
29
+ mkdocstrings_handlers/python/templates/material/_base/function.html.jinja,sha256=rW-47bNjme32xUWXGmMm6e-eQRsqtjc3BxEQvFxwyL4,6017
30
30
  mkdocstrings_handlers/python/templates/material/_base/labels.html.jinja,sha256=mue5CMl2WQpagj3aYqbUiAQX0P72aLCgY3MX_zEpE8s,786
31
31
  mkdocstrings_handlers/python/templates/material/_base/language.html.jinja,sha256=7gyknTiapqCM8TjUHdXkQgZMmYwcuy6Ze0pkntE7g8s,617
32
32
  mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja,sha256=tzS9C3l1c5liALvpYl7dHOGhtoFpRQwMgm_gAVKcv_Y,1731
@@ -86,7 +86,7 @@ mkdocstrings_handlers/python/templates/material/type_alias.html.jinja,sha256=wQw
86
86
  mkdocstrings_handlers/python/templates/material/type_parameters.html,sha256=-YLk-DbKYz8wQqar6-KAvzyQHlb7jDtykpWqqqRRa88,49
87
87
  mkdocstrings_handlers/python/templates/material/type_parameters.html.jinja,sha256=-YLk-DbKYz8wQqar6-KAvzyQHlb7jDtykpWqqqRRa88,49
88
88
  mkdocstrings_handlers/python/templates/readthedocs/_base/class.html,sha256=x0M8Wjk7TC9cgnstMoukLVQvxZUEMFjQA0VJQPEAC9Y,415
89
- mkdocstrings_handlers/python/templates/readthedocs/_base/class.html.jinja,sha256=dWVevPMZKXJNY81VlQvO-g0jMh_CAbutloIjLikBpkI,9613
89
+ mkdocstrings_handlers/python/templates/readthedocs/_base/class.html.jinja,sha256=XBJuYmH65zHBIL4SzylZ8jQKGgSzBXUfvdc3ySy2SHA,9135
90
90
  mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/attributes.html.jinja,sha256=Bq7zsZqREC_VkZpbxS0gJlNG46FPyvaYZAJYAVUijPU,1535
91
91
  mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/other_parameters.html.jinja,sha256=t6hWw_CvWQHfLO0EIggXImg4YBarC97HgXBGOLwdjc0,1580
92
92
  mkdocstrings_handlers/python/templates/readthedocs/_base/docstring/parameters.html.jinja,sha256=eQFg4aSUNpl8m7Cp_gQHbgsir2aV9nCDUroZWZ4seFQ,1873
@@ -114,8 +114,8 @@ mkdocstrings_handlers/python/templates/readthedocs/languages/en.html.jinja,sha25
114
114
  mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html.jinja,sha256=e_DPZvMvaaJm0QyjTxW8SkBEbhMXBgBiMrLJ1osAwZc,46
115
115
  mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html.jinja,sha256=OuvrkorxuL0gKZNYneann1bwd1Z2i5bBY7SbC496HDw,46
116
116
  mkdocstrings_handlers/python/templates/readthedocs/style.css,sha256=Ds8vF1rSxc2B0c4P10osx4cqXHWMntcSCxmRfX-nfzw,971
117
- mkdocstrings_python-2.0.6.dist-info/METADATA,sha256=JtU8hPL0qhB5_sEDYrWIiEZRGEABbc0NwWA3gGG65a8,12384
118
- mkdocstrings_python-2.0.6.dist-info/WHEEL,sha256=VP-D4TPS230sME9Z3vb3INXvo1yt0924YRm5AOsk_dE,90
119
- mkdocstrings_python-2.0.6.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
120
- mkdocstrings_python-2.0.6.dist-info/licenses/LICENSE,sha256=JGb4pdPEM8TTjjhr-uNCO7oXkiVrwG5Pz0JamcjNF_s,754
121
- mkdocstrings_python-2.0.6.dist-info/RECORD,,
117
+ mkdocstrings_python-2.0.7.dist-info/METADATA,sha256=x-BFx6xsNyyDXiBczY9WGADLEQF60QaOjKCkWT1ggwk,12384
118
+ mkdocstrings_python-2.0.7.dist-info/WHEEL,sha256=VP-D4TPS230sME9Z3vb3INXvo1yt0924YRm5AOsk_dE,90
119
+ mkdocstrings_python-2.0.7.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
120
+ mkdocstrings_python-2.0.7.dist-info/licenses/LICENSE,sha256=JGb4pdPEM8TTjjhr-uNCO7oXkiVrwG5Pz0JamcjNF_s,754
121
+ mkdocstrings_python-2.0.7.dist-info/RECORD,,