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').\
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'])
srcdir = d['sep'] and path.join(d['path'], 'source') or d['path']

View File

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