Skip to content
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

use of substitutions doesn't appear to be supported? #137

Open
jrouly opened this issue Jul 30, 2024 · 4 comments
Open

use of substitutions doesn't appear to be supported? #137

jrouly opened this issue Jul 30, 2024 · 4 comments

Comments

@jrouly
Copy link

jrouly commented Jul 30, 2024

I have the following substitutions defined in my rst_prolog in conf.py:

rst_prolog = f"""
.. |repo_link| replace:: {repo_link}
"""

where the repo_link is set from an environment variable. I want to use this in my index.rst as below:

Changelog
---------

.. changelog::
    :github: |repo_link|/releases/

but it seems like the literal string |repo_link| is what's getting processed by the sphinx-github-changelog extension, rather than the substituted value coming in from rst_prolog/rst_epilog.

I'm a pretty new sphinx/rst user, so not really sure where to go from here.

@ewjoachim
Copy link
Owner

ewjoachim commented Jul 31, 2024

Hm, I've never used the substitution, and I don't have a large experience in sphinx, so it's hard to say. I don't know if it's a good idea to make it work that way: the idea of requesting the user to put the link this way is so that if we display this page on GitHub (where it won't be processed by Sphinx), there's at least a usable link to the changelog source.

An alternative would be to allow removing the link altogether and set the default value for all changelog elements in conf.py. This way, you wouldn't have to use your substitution.

This would require a PR to the project.

@jrouly
Copy link
Author

jrouly commented Jul 31, 2024

@ewjoachim I ended up coming to a similar conclusion. My implementation (which ended up working) is to specialize the directive provided by this plugin to allow for programmatic specification of the changelog elements (specifically the GitHub URL).

from sphinx_github_changelog.changelog import ChangelogDirective

# Set the GitHub Token from the environment so the extension can pull the latest releases.
repo_link = os.environ.get("WHATEVER", "no-repo-link")

# Customize the extension directive so the repo link can be pulled from the environment, rather than from static RST.
class CustomChangelogDirective(ChangelogDirective):
    def run(self):
        self.options["github"] = f"{repo_link}/releases"
        return super().run()

def setup(app):
    # Override the Sphinx GitHub Changelog directive with our customized directive.
    app.add_directive("changelog", CustomChangelogDirective)
Changelog
---------

.. changelog::

@jrouly
Copy link
Author

jrouly commented Jul 31, 2024

I agree a PR could be contributed to this project to allow the directive to read options programmatically or via RST out of the box, without requiring downstream specialization.

@ewjoachim
Copy link
Owner

I agree a PR could be contributed to this project

Would you be interested in crafting such a PR ? :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants