Skip to content

Commit

Permalink
refactor: Use package relative filepath if filepath is not relative
Browse files Browse the repository at this point in the history
Discussion mkdocstrings#622: mkdocstrings/mkdocstrings#622
  • Loading branch information
pawamoy committed Oct 5, 2023
1 parent 67df10c commit aa5a3f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,28 @@
{% if config.show_source %}
{% if config.merge_init_into_class %}
{% if "__init__" in class.all_members and class.all_members["__init__"].source %}
<details class="quote">
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
{{ class.all_members["__init__"].source|highlight(language="python", linestart=class.all_members["__init__"].lineno, linenums=True) }}
</details>
{% with init = class.all_members["__init__"] %}
<details class="quote">
<summary>Source code in <code>
{%- if init.relative_filepath.is_absolute() -%}
{{ init.relative_package_filepath }}
{%- else -%}
{{ init.relative_filepath }}
{%- endif -%}
</code></summary>
{{ init.source|highlight(language="python", linestart=init.lineno, linenums=True) }}
</details>
{% endwith %}
{% endif %}
{% elif class.source %}
<details class="quote">
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
<summary>Source code in <code>
{%- if class.relative_filepath.is_absolute() -%}
{{ class.relative_package_filepath }}
{%- else -%}
{{ class.relative_filepath }}
{%- endif -%}
</code></summary>
{{ class.source|highlight(language="python", linestart=class.lineno, linenums=True) }}
</details>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@
{% block source scoped %}
{% if config.show_source and function.source %}
<details class="quote">
<summary>{{ lang.t("Source code in") }} <code>{{ function.relative_filepath }}</code></summary>
<summary>{{ lang.t("Source code in") }} <code>
{%- if function.relative_filepath.is_absolute() -%}
{{ function.relative_package_filepath }}
{%- else -%}
{{ function.relative_filepath }}
{%- endif -%}
</code></summary>
{{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
</details>
{% endif %}
Expand Down

0 comments on commit aa5a3f7

Please sign in to comment.