Custom variable in conf.py

17 views
Skip to first unread message

Andy Cheesman

unread,
Nov 22, 2019, 8:54:56 AM11/22/19
to sphinx-users
Hi everyone,

I would like to pass a custom variable to the conf.py so I can apply some logic rules within the conf.
(this is a simple example, I know I can do this with other option but i can expand this to do more beyond the scope of the question) 

if branch_name == "master":
    todo_include_todos = False
else:
    todo_include_todos = True
    tags.add("internal")

However, when I try to build, it fails with the error below.
The -D option (-D branch_name=develop) results in the same issue.

NameError: name 'branch_name' is not defined.

If I define the variable in the conf, there is no error but  it isn't overwritten by the -D command

Anyone got any suggestions what I should do?

Thanks

Andy

Komiya Takeshi

unread,
Nov 22, 2019, 9:14:08 AM11/22/19
to sphinx...@googlegroups.com
Hi Andy,

You can use a pair of ``tags`` object and ``-t`` option of
sphinx-build command for that purpose.
```
# in conf.py

if tags.has('master'):
# when `-t master` given for sphinx-build
...
else:
# otherwise
...
```

Thanks,
Takeshi KOMIYA

2019年11月22日(金) 22:55 Andy Cheesman <vanc...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/1ffb4ae7-073b-4632-b7d3-5ee802f62960%40googlegroups.com.

Libor Jelinek

unread,
Nov 22, 2019, 3:43:37 PM11/22/19
to sphinx...@googlegroups.com
It's because -D parameter is to override some of builtin config options like language or html_theme. It can't introduce new value.

As Takeshi pointed out, for these purposes are tags (-t parameter) good for.

Libor

Dne pá 22. 11. 2019 14:54 uživatel Andy Cheesman <vanc...@gmail.com> napsal:
Reply all
Reply to author
Forward
0 new messages