Merge pull request #5881 from tk0miya/refactor_conf_py

refactor: Use repr() to make escaped string in template for conf.py
This commit is contained in:
Takeshi KOMIYA 2019-01-08 00:11:32 +09:00 committed by GitHub
commit 064c80336f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 18 deletions

View File

@ -395,13 +395,6 @@ def generate(d, overwrite=True, silent=False, templatedir=None):
d['project_doc_texescaped'] = (d['project'] + ' Documentation').\ d['project_doc_texescaped'] = (d['project'] + ' Documentation').\
translate(texescape.tex_escape_map) translate(texescape.tex_escape_map)
# escape backslashes and single quotes in strings that are put into
# a Python string literal
for key in ('project', 'project_doc', 'project_doc_texescaped',
'author', 'author_texescaped', 'copyright',
'version', 'release', 'master'):
d[key + '_str'] = d[key].replace('\\', '\\\\').replace("'", "\\'")
ensuredir(d['path']) ensuredir(d['path'])
srcdir = d['sep'] and path.join(d['path'], 'source') or d['path'] srcdir = d['sep'] and path.join(d['path'], 'source') or d['path']

View File

@ -13,12 +13,12 @@
{% if append_syspath -%} {% if append_syspath -%}
import os import os
import sys import sys
sys.path.insert(0, '{{ module_path }}') sys.path.insert(0, {{ module_path | repr }})
{% else -%} {% else -%}
# import os # import os
# import sys # import sys
{% if module_path -%} {% if module_path -%}
# sys.path.insert(0, '{{ module_path }}') # sys.path.insert(0, {{ module_path | repr }})
{% else -%} {% else -%}
# sys.path.insert(0, os.path.abspath('.')) # sys.path.insert(0, os.path.abspath('.'))
{% endif -%} {% endif -%}
@ -26,14 +26,14 @@ sys.path.insert(0, '{{ module_path }}')
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = '{{ project_str }}' project = {{ project | repr }}
copyright = '{{ copyright_str }}' copyright = {{ copyright | repr }}
author = '{{ author_str }}' author = {{ author | repr }}
# The short X.Y version # The short X.Y version
version = '{{ version_str }}' version = {{ version | repr }}
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '{{ release_str }}' release = {{ release | repr }}
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
@ -54,11 +54,11 @@ templates_path = ['{{ dot }}templates']
# You can specify multiple suffix as a list of string: # You can specify multiple suffix as a list of string:
# #
# source_suffix = ['.rst', '.md'] # source_suffix = ['.rst', '.md']
source_suffix = '{{ suffix }}' source_suffix = {{ suffix | repr }}
{% if master_doc != 'index' -%} {% if master_doc != 'index' -%}
# The master toctree document. # The master toctree document.
master_doc = '{{ master_str }}' master_doc = {{ master | repr }}
{% endif -%} {% endif -%}
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
@ -127,8 +127,8 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, '{{ project_fn }}.tex', '{{ project_doc_texescaped_str }}', (master_doc, '{{ project_fn }}.tex', {{ project_doc_texescaped | repr }},
'{{ author_texescaped_str }}', 'manual'), {{ author_texescaped | repr }}, 'manual'),
] ]