mkdocstrings · GitHub

I am using the sample gen_ref_pages.py script in the documentation. Everything looks great locally, but when I deploy my documentation via GitHub, I get the following:

image

Here is my specific gen_ref_pages.py script, and here is a page highlighting the above image.

Do you have any recommendations about how to get the source code path to be only the path starting at my package name?

You could try overriding templates to use relative_package_filepath instead of relative_filepath which depends on the current working directory.

For example in templates/python/material/function.html:

{% extends "_base/function.html" %}
{% block source scoped %}
  {% if config.show_source and function.source %}
    <details class="quote">
      <summary>{{ lang.t("Source code in") }} <code>{{ function.relative_package_filepath }}</code></summary>
      {{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
    </details>
  {% endif %}
{% endblock source %}

I'm considering adding some logic to the templates to use the relative filepath if its not absol…

View full answer

You could try overriding templates to use relative_package_filepath instead of relative_filepath which depends on the current working directory.

For example in templates/python/material/function.html:

{% extends "_base/function.html" %}
{% block source scoped %}
  {% if config.show_source and function.source %}
    <details class="quote">
      <summary>{{ lang.t("Source code in") }} <code>{{ function.relative_package_filepath }}</code></summary>
      {{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
    </details>
  {% endif %}
{% endblock source %}

I'm considering adding some logic to the templates to use the relative filepath if its not absolute, and fallback to the relative package filepath.

2 replies

@pawamoy

Will be available in next release.

@Andrew-S-Rosen

Fantastic to hear. Thank you!!

Read the original on github.com ↗