-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple versions of a package #470
Comments
I absolutely agree that this is a useful feature, but I'm don't necessarily think it's something that should be natively supported by pdoc. Here's what I would do instead:
It'd be awesome to have a custom template in |
Hello 👋 (TL;DR below) While I agree that this functionality is not necessarily in the scope of pdoc, I'm afraid there's a bit more to it than meets the eye. The problem with your suggestion is that I'd never be able to change the design and layout of the docs. I am actually already publishing docs for multiple versions of https://gitlab.com/dAnjou/fs-code here: https://danjou.gitlab.io/fs-code (well, just two versions for now). Much like you're describing, I have a CI job triggering the whole thing via a Python script and I have a bit of JavaScript in a customized pdoc template, all the code is here: https://gitlab.com/dAnjou/fs-code/-/blob/main/docs/. What I do is iterating over the version tags, checking them out, and regenerating the docs each time, so that the pages keep looking the same. It works okay so far, but there's a rather unpleasant hack in there 😞 In the Python script that's generating the docs, I happen to use my very same library for which I'm generating the docs, which means it needs to be installed. Now it seems that the installed module always takes precedence over a local package directory. When I say
And when I then say
So, to hack myself around this, I'm currently doing a (Don't mind the subprocess stuff. That's still from when I was using pdoc 9 and using it as a library had some rough edges, which are all fixed now, so I'm in the process of migrating - also why I'm writing this comment here now.) TL;DRSo, from what I can see, the core issue is that you basically cannot use pdoc as a library in a Python script that's supposed to generate docs for multiple versions of your code, if that code is also "imported in pdoc's Python process". Imagine someone wanted to write a Python library that does exactly what OP is asking, as a pdoc add-on, for example. Ironically, you could not use pdoc to document multiple versions for this library, because it would always prefer the installed module. |
@dAnjou: For your specific use case, it's probably easier to do the "check out another version" part in a bash script and then invoke your |
I don't think it matters whether I check out the version in a bash script or in the Python script.
Yes, that's the core problem, and I acknowledge that my situation might be an edge case, because I happen to use my library for checking out the version. But any situation where you want to use the latest version of your own code in the docs script would fail. And it still makes me wonder whether there's a way for pdoc to extract code structure and doc strings without importing the module 🤔 |
Well the idea would be that you have a fresh Python interpreter for each version.
pdoc heavily relies on dynamic analysis (as opposed to static analysis), so the answer is a resounding no unfortunately. FWIW |
I can still do it in a Python script if I don't run it in an env that has my library installed, which I also cannot use then of course, but I can use Dulwich directly, for example.
Totally understand that 👍
That's not an option for me. I want to be able to change the design and layout, and it should be applied to all versions already published. |
After some messing around with Bash scripting, I managed to get multiple versions to work by using the using following steps, which I'm writing down in case it helps anyone:
{% set versions = env.get("VERSIONS", "").strip().split(" ") %}
{% set package = env.get("PACKAGE", "test") %}
{% block nav_footer %}
<footer>
<label for="page-select">Version:</label>
<select id="page-select" onchange="redirectToPage()">
<option value="">Select an option</option>
{% for item in versions %}
<option value="{{ item }}">{{ item }}</option>
{% endfor %}
</select>
<script>
function redirectToPage() {
var select = document.getElementById("page-select");
var selectedOption = select.options[select.selectedIndex].value;
if (selectedOption !== "") {
var redirectURL = "/{{ package }}/" + selectedOption + "/index.html";
window.location.href = redirectURL;
}
}
// Set the default value of the dropdown to the selected option
window.onload = function() {
var select = document.getElementById("page-select");
var currentURL = window.location.pathname;
var match = currentURL.match(/^\/{{ package }}\/([^/]+)\/.+$/);
if (match && match[1]) {
select.value = match[1];
}
};
</script>
{% endblock %}
- uses: actions/checkout@v2
with:
fetch-depth: 0 |
@JCGoran Thanks for the informative write-up on how to achieve this. Can you clarify what the directory structure needs to look like when building for multiple versions? I'm a bit unclear about what the output directory should be for pdoc after I checkout a particular tag in the CI script. |
Unfortunately I haven't touched the project using this particular setup in a while, but the general setup is described in this file, which I just run as The rough idea is as follows:
You can see the final result here (the most notable difference w.r.t. the default pdoc template is the "Version" drop-down on the bottom of the left sidebar, which is clickable and redirects to the right version properly). pdoc's handling of images was (is?) a bit cumbersome, and as a result the |
Problem Description
Currently,
pdoc
only supports one version of a given Python package.Proposal
I would like to see (optional) support for multiple versions of a package in
pdoc
. It's possible that some users of a package do not use the version whose current documentation is available, and having the option to switch versions would greatly aid in usability, especially if some objects were removed/renamed between different package versions.Alternatives
I think Sphinx has support for this feature, but I have not tested it.
Additional context
None.
The text was updated successfully, but these errors were encountered: