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

Add docs on sphinx tags #4603

Open
agjohnson opened this issue Sep 4, 2018 · 29 comments
Open

Add docs on sphinx tags #4603

agjohnson opened this issue Sep 4, 2018 · 29 comments
Labels
Accepted Accepted issue on our roadmap Good First Issue Good for new contributors Needed: documentation Documentation is required

Comments

@agjohnson
Copy link
Contributor

agjohnson commented Sep 4, 2018

Another Sphinx feature that would be helpful would be addition of Sphinx tags:
http://www.sphinx-doc.org/en/stable/markup/misc.html#including-content-based-on-tags

It allows for having content like:

.. only:: footag

    Only in the Foo docs!

.. only:: bartag

    Only in the Bar docs!

The tags config option is already exposed in conf.py

@agjohnson agjohnson added Feature New feature Needed: design decision A core team decision is required labels Sep 4, 2018
@agjohnson agjohnson added this to the 2.8 milestone Sep 4, 2018
@stsewd
Copy link
Member

stsewd commented Sep 4, 2018

Seems very useful, I wonder how many people are aware of this functionality, maybe Sphinx heavy users, or maybe I was the only one that didn't know about this 😁

@humitos
Copy link
Member

humitos commented Sep 4, 2018

Does it worth to implement this as a YAML option, add validation, modify the command, etc instead of just using the conf.py for this?

I mean, we need to do some extra work and I don't think we are adding any value by using the YAML file here. Instead, by using the conf.py we get the same benefits and the user just need to add:

# conf.py
tags.add('footag')

@stsewd
Copy link
Member

stsewd commented Sep 4, 2018

There is only one downside of only using the conf.py file

Only tags set via the -t command-line option or via tags.add('tag') can be queried using tags.has('tag').

But not sure if that worth it

@stsewd
Copy link
Member

stsewd commented Sep 4, 2018

Also, some useful tags are already provided

The format and the name of the current builder (html, latex or text) are always set as a tag [1]. To make the distinction between format and name explicit, they are also added with the prefix format_ and builder_, e.g. the epub builder defines the tags html, epub, format_html and builder_epub.

@humitos
Copy link
Member

humitos commented Sep 4, 2018

I'm not following you about the downside that you are mentioning here. Can you expand?

@stsewd
Copy link
Member

stsewd commented Sep 4, 2018

@humitos I think this would be a downside if we pass tags per builder, so they are exposed on the config.py file or people only want some tags on rtd.

@humitos
Copy link
Member

humitos commented Sep 5, 2018

would be a downside if we pass tags per builder, so they are exposed on the config.py file

I don't understand this 😕

or people only want some tags on rtd.

This is still possible and simpler:

# conf.py
if READTHEDOCS == 'True':
    tags.add('footag')
else:
    tags.add('bartag')

@stsewd
Copy link
Member

stsewd commented Sep 5, 2018

Nevermind, I don't think that case is worth it p: But we could expose "something" to the rst files with a tag like -tag readthedocs and used it as

.. only:: readthedocs

@humitos
Copy link
Member

humitos commented Sep 5, 2018

That could be. It's another feature/issue, though. And it doesn't require to implement anything from our side. Just change the command on the builders to add that option.

Although, I don't think it's really useful.

@agjohnson
Copy link
Contributor Author

I didn't realize sphinx exposed a tag element in the conf.py, that is a better ux. We should document this usage

@agjohnson agjohnson changed the title Support Sphinx tags in our config file Add docs on sphinx tags Sep 6, 2018
@agjohnson agjohnson added Needed: documentation Documentation is required and removed Feature New feature Needed: design decision A core team decision is required labels Sep 6, 2018
@stsewd
Copy link
Member

stsewd commented Sep 6, 2018

@agjohnson but you can't see the builder tags in the conf.py file

Only tags set via the -t command-line option or via tags.add('tag') can be queried using tags.has('tag').

@stsewd
Copy link
Member

stsewd commented Sep 14, 2018

Just linking to the new docs http://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#including-content-based-on-tags

Also:

These standard tags are set after the configuration file is read, so they are not available there.

Not sure what we want to document here.

@agjohnson
Copy link
Contributor Author

@stsewd what is the need to be able to see the tags? I don't think we need read access to them, just need to guide users to add them and use them.

I think what we want to document is "How to have conditional content in your documentation", which describes:

  • Adding tags.add('foo') to your config
  • Using only directive to make conditional content

I just tested this out, and it does work as I'd expect.

Thinking about this more however, I thought of an additional use case. Asking users to add a if READTHEDOCS block to their config is a) a bit hacky, or at least isn't a product-y feature and b) isn't version-dependent, it's only boolean whether or not we're on RTD. I could see some use cases for config dependent tags, like a tag for is_lts or something.

Another feature we could add is dropping our own tags into conf.py automatically. Assume we added tags like:

  • is_stable
  • is_latest
  • is_on_readthedocs

Authors could use these to make version-dependent docs:

.. only:: is_stable

    This version is the most stable version

Mostly just brainstorming here, perhaps there are more tags we could add automatically? Also, these are mostly features to make docs more version specific. Perhaps it would be better served by an extension that inspects version from conf.py instead (something we could populate with a branch name? I'm not necessarily convinced we need version-specific tags, but perhaps it's a good idea?

@stsewd
Copy link
Member

stsewd commented Sep 18, 2018

How to have conditional content in your documentation

Got it, that should be in our guides section https://docs.readthedocs.io/en/latest/guides/index.html.

I'm not sure if there is a need to add tags from the rtd side, users already have access to the version from the conf.py file, maybe we can add that to the guide?

Not sure about is_on_rtd tag, I can't think of a use case for that, people mostly want to see the same docs locally as in rtd p: And this tag can be added to the conf.py by the user using the env variable that we already expose.

@stsewd stsewd added the Good First Issue Good for new contributors label Sep 18, 2018
@agjohnson
Copy link
Contributor Author

Yup +1 on a guide for this.

They have access to the version, but most folks don't automate this or keep it up to date. I feel like we could be updating the version in conf.py for them. Hard to determine what is default and what is an intended value for version though, so we might not be able to automate this.

@stsewd
Copy link
Member

stsewd commented Nov 15, 2018

Just pointing that we already set up a readthedocs tag, because we have a custom builder, see #4765 (comment)

@stale
Copy link

stale bot commented Jan 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Jan 10, 2019
@stsewd stsewd added Accepted Accepted issue on our roadmap and removed Status: stale Issue will be considered inactive soon labels Jan 10, 2019
@agarwalrounak
Copy link
Contributor

I will work on it.

I am new to Sphinx, so I might need a little guidance along the way:sweat_smile:

@ghost
Copy link

ghost commented Jun 20, 2019

Is anyone still working on this? If I understand correctly, we need documentation on how to add tags in RTD using Sphinx? I can take this issue :)

@stsewd
Copy link
Member

stsewd commented Jun 20, 2019

@potterwrit yes, you can submit a PR!

@akien-mga
Copy link
Contributor

I'm confused by this issue. The RTD config exposes Tags in the admin section:
Screenshot_20190715_143933

But they don't seem to be passed to Sphinx with the -t switch, so what's their use case? I just realized after a year that my i18n instances did not use the .. only:: i18n content I set for them due to this.

How can we pass tags via RTD without changing conf.py manually? (In my use case I have the original English docs and the localized instances all use the same conf.py, so the tag should be passed by RTD.)

@stsewd
Copy link
Member

stsewd commented Jul 15, 2019

@akien-mga sorry for the confusion, these tags, are to clasify the version, they are not sphinx tags.

Also, we are removing those tags in the next release #5864

Maybe you could use env variables to have this? https://docs.readthedocs.io/en/stable/guides/environment-variables.html

@akien-mga
Copy link
Contributor

@stsewd Thanks, environment variables + some logic to parse them and append the Sphinx tags object should do the trick indeed for my use case.

@Lokesh2703
Copy link

Lokesh2703 commented Dec 23, 2019

By just adding sphinx-tabs==1.1.13, I was able to get sphinx-tabs in my docs, Can I add this in doc
that the user had to add sphinx-tabs==1.1.13 to the requirements.txt file in their repository to use sphinx-tabs in their RTD

@stsewd
Copy link
Member

stsewd commented Jan 6, 2020

@astrojuanlu
Copy link
Contributor

Should we try to contribute this upstream instead?

@stsewd
Copy link
Member

stsewd commented Sep 2, 2021

Should we try to contribute this upstream instead?

If there are any improvements to the existing docs yeah, but we still need to document or put an example of how to use/expose tags specific to rtd, like #4603 (comment) and adding tags for if we are building the latest version like #4603 (comment)

@Sachin-Suresh
Copy link

I am trying to add something like the below in conf.py, but I get syntax highlighted as - "tags is not defined".

exclude_patterns = ['**/*admin*']
if tags.has('adminmode'):
    exclude_patterns = []

Where do we declare or configure tags in conf?

@felixvd
Copy link

felixvd commented Feb 1, 2023

That's a Sphinx issue. tags is injected into the namespace in eval_config_file. This also affects conf files that import other conf files - the undefined tags object will raise NameError: name 'tags' is not defined.

This should be raised as an issue on Sphinx, but I'm commenting here because it comes up on Google. This workaround will silence the syntax highlights and allow imports from other conf files (e.g. when you want to build sub-trees of your doc as a PDF):

# Workaround to allow importing this file from other confs and remove 
if 'tags' not in locals():
    class Tags(dict):
        def has(self, tag):
            return tag in self
    tags = Tags()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Good First Issue Good for new contributors Needed: documentation Documentation is required
Projects
None yet
Development

No branches or pull requests

9 participants