mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3417 from tk0miya/reduce_DeprecationWarning_for_regexp
Reduce DeprecationWarnings for regexp
This commit is contained in:
commit
a937bf6e9d
2
Makefile
2
Makefile
@ -33,7 +33,7 @@ DONT_CHECK = -i build -i dist -i sphinx/style/jquery.js \
|
||||
all: clean-pyc clean-backupfiles style-check type-check test
|
||||
|
||||
style-check:
|
||||
@$(PYTHON) utils/check_sources.py $(DONT_CHECK) .
|
||||
@PYTHONWARNINGS=all $(PYTHON) utils/check_sources.py $(DONT_CHECK) .
|
||||
|
||||
type-check:
|
||||
mypy sphinx/
|
||||
|
@ -171,7 +171,8 @@ class Config(object):
|
||||
if getenv('SOURCE_DATE_EPOCH') is not None:
|
||||
for k in ('copyright', 'epub_copyright'):
|
||||
if k in config:
|
||||
config[k] = copyright_year_re.sub('\g<1>%s' % format_date('%Y'), config[k])
|
||||
config[k] = copyright_year_re.sub(r'\g<1>%s' % format_date('%Y'),
|
||||
config[k])
|
||||
|
||||
def check_types(self):
|
||||
# type: () -> None
|
||||
|
@ -116,7 +116,7 @@ class PyXrefMixin(object):
|
||||
def make_xrefs(self, rolename, domain, target, innernode=nodes.emphasis,
|
||||
contnode=None):
|
||||
# type: (unicode, unicode, unicode, nodes.Node, nodes.Node) -> List[nodes.Node]
|
||||
delims = '(\s*[\[\]\(\),](?:\s*or\s)?\s*|\s+or\s+)'
|
||||
delims = r'(\s*[\[\]\(\),](?:\s*or\s)?\s*|\s+or\s+)'
|
||||
delims_re = re.compile(delims)
|
||||
sub_targets = re.split(delims, target)
|
||||
|
||||
|
@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
|
||||
# RE for option descriptions
|
||||
option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=]+)(=?\s*.*)')
|
||||
# RE for grammar tokens
|
||||
token_re = re.compile('`(\w+)`', re.U)
|
||||
token_re = re.compile(r'`(\w+)`', re.U)
|
||||
|
||||
|
||||
class GenericObject(ObjectDescription):
|
||||
|
@ -357,7 +357,7 @@ class Autosummary(Directive):
|
||||
*items* is a list produced by :meth:`get_items`.
|
||||
"""
|
||||
table_spec = addnodes.tabular_col_spec()
|
||||
table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}'
|
||||
table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}'
|
||||
|
||||
table = autosummary_table('')
|
||||
real_table = nodes.table('', classes=['longtable'])
|
||||
@ -388,7 +388,7 @@ class Autosummary(Directive):
|
||||
for name, sig, summary, real_name in items:
|
||||
qualifier = 'obj'
|
||||
if 'nosignatures' not in self.options:
|
||||
col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA
|
||||
col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA
|
||||
else:
|
||||
col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
|
||||
col2 = summary
|
||||
|
@ -52,7 +52,7 @@ number2name.update(token.tok_name)
|
||||
|
||||
_eq = nodes.Leaf(token.EQUAL, '=')
|
||||
|
||||
emptyline_re = re.compile('^\s*(#.*)?$')
|
||||
emptyline_re = re.compile(r'^\s*(#.*)?$')
|
||||
|
||||
|
||||
class AttrDocVisitor(nodes.NodeVisitor):
|
||||
|
@ -293,7 +293,7 @@ def emph_literal_role(typ, rawtext, text, lineno, inliner,
|
||||
return [retnode], []
|
||||
|
||||
|
||||
_abbr_re = re.compile('\((.*)\)$', re.S)
|
||||
_abbr_re = re.compile(r'\((.*)\)$', re.S)
|
||||
|
||||
|
||||
def abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
|
@ -556,7 +556,7 @@ def encode_uri(uri):
|
||||
|
||||
def split_docinfo(text):
|
||||
# type: (unicode) -> Sequence[unicode]
|
||||
docinfo_re = re.compile('\A((?:\s*:\w+:.*?\n(?:[ \t]+.*?\n)*)+)', re.M)
|
||||
docinfo_re = re.compile('\\A((?:\\s*:\\w+:.*?\n(?:[ \\t]+.*?\n)*)+)', re.M)
|
||||
result = docinfo_re.split(text, 1) # type: ignore
|
||||
if len(result) == 1:
|
||||
return '', result[0]
|
||||
|
@ -21,7 +21,8 @@ from docutils.parsers.rst import directives, roles
|
||||
from sphinx.util import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
report_re = re.compile('^(.+?:\d+): \((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\d+)?\) (.+?)\n?$')
|
||||
report_re = re.compile('^(.+?:\\d+): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\\d+)?\\) '
|
||||
'(.+?)\n?$')
|
||||
|
||||
|
||||
if False:
|
||||
|
@ -65,8 +65,8 @@ def apply_source_workaround(node):
|
||||
if isinstance(node, nodes.term):
|
||||
# strip classifier from rawsource of term
|
||||
for classifier in reversed(node.parent.traverse(nodes.classifier)):
|
||||
node.rawsource = re.sub(
|
||||
'\s*:\s*%s' % re.escape(classifier.astext()), '', node.rawsource)
|
||||
node.rawsource = re.sub(r'\s*:\s*%s' % re.escape(classifier.astext()),
|
||||
'', node.rawsource)
|
||||
|
||||
# workaround: recommonmark-0.2.0 doesn't set rawsource attribute
|
||||
if not node.rawsource:
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
import re
|
||||
|
||||
symbols_re = re.compile('([!-/:-@\[-`{-~])')
|
||||
symbols_re = re.compile(r'([!-/:-@\[-`{-~])')
|
||||
|
||||
|
||||
def escape(text):
|
||||
|
@ -371,7 +371,7 @@ class Table(object):
|
||||
|
||||
This is what LaTeX calls the 'preamble argument' of the used table environment.
|
||||
|
||||
.. note:: the ``\X`` column type specifier is defined in ``sphinx.sty``.
|
||||
.. note:: the ``\\X`` column type specifier is defined in ``sphinx.sty``.
|
||||
"""
|
||||
if self.colspec:
|
||||
return self.colspec
|
||||
@ -456,13 +456,13 @@ class TableCell(object):
|
||||
def escape_abbr(text):
|
||||
# type: (unicode) -> unicode
|
||||
"""Adjust spacing after abbreviations."""
|
||||
return re.sub('\.(?=\s|$)', '.\\@', text)
|
||||
return re.sub(r'\.(?=\s|$)', r'.\@', text)
|
||||
|
||||
|
||||
def rstdim_to_latexdim(width_str):
|
||||
# type: (unicode) -> unicode
|
||||
"""Convert `width_str` with rst length to LaTeX length."""
|
||||
match = re.match('^(\d*\.?\d*)\s*(\S*)$', width_str)
|
||||
match = re.match(r'^(\d*\.?\d*)\s*(\S*)$', width_str)
|
||||
if not match:
|
||||
raise ValueError
|
||||
res = width_str
|
||||
@ -2244,7 +2244,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
|
||||
def visit_line(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.body.append('\item[] ')
|
||||
self.body.append(r'\item[] ')
|
||||
|
||||
def depart_line(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
|
@ -129,7 +129,7 @@ class ManualPageTranslator(BaseTranslator):
|
||||
tmpl = (".TH \"%(title_upper)s\" \"%(manual_section)s\""
|
||||
" \"%(date)s\" \"%(version)s\" \"%(manual_group)s\"\n"
|
||||
".SH NAME\n"
|
||||
"%(title)s \- %(subtitle)s\n")
|
||||
"%(title)s \\- %(subtitle)s\n")
|
||||
return tmpl % self._docinfo
|
||||
|
||||
def visit_start_of_file(self, node):
|
||||
|
@ -469,7 +469,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
||||
|
||||
def tex_image_length(self, width_str):
|
||||
# type: (unicode) -> unicode
|
||||
match = re.match('(\d*\.?\d*)\s*(\S*)', width_str)
|
||||
match = re.match(r'(\d*\.?\d*)\s*(\S*)', width_str)
|
||||
if not match:
|
||||
# fallback
|
||||
return width_str
|
||||
|
@ -52,15 +52,15 @@
|
||||
import re
|
||||
|
||||
xpath_tokenizer = re.compile(
|
||||
"("
|
||||
"'[^']*'|\"[^\"]*\"|"
|
||||
"::|"
|
||||
"//?|"
|
||||
"\.\.|"
|
||||
"\(\)|"
|
||||
"[/.*:\[\]\(\)@=])|"
|
||||
"((?:\{[^}]+\})?[^/:\[\]\(\)@=\s]+)|"
|
||||
"\s+"
|
||||
r"("
|
||||
r"'[^']*'|\"[^\"]*\"|"
|
||||
r"::|"
|
||||
r"//?|"
|
||||
r"\.\.|"
|
||||
r"\(\)|"
|
||||
r"[/.*:\[\]\(\)@=])|"
|
||||
r"((?:\{[^}]+\})?[^/:\[\]\(\)@=\s]+)|"
|
||||
r"\s+"
|
||||
).findall
|
||||
|
||||
def prepare_tag(next, token):
|
||||
|
@ -976,7 +976,7 @@ def _serialize_text(write, elem, encoding):
|
||||
# invalid.
|
||||
|
||||
def register_namespace(prefix, uri):
|
||||
if re.match("ns\d+$", prefix):
|
||||
if re.match(r"ns\d+$", prefix):
|
||||
raise ValueError("Prefix format reserved for internal use")
|
||||
for k, v in _namespace_map.items():
|
||||
if k == uri or v == prefix:
|
||||
|
@ -24,6 +24,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir)))
|
||||
# filter warnings of test dependencies
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning, module='site') # virtualenv
|
||||
warnings.filterwarnings('ignore', category=ImportWarning, module='backports')
|
||||
warnings.filterwarnings('ignore', category=ImportWarning, module='pytest_cov')
|
||||
warnings.filterwarnings('ignore', category=PendingDeprecationWarning, module=r'_pytest\..*')
|
||||
|
||||
# check dependencies before testing
|
||||
|
@ -346,7 +346,7 @@ def test_static_output(app):
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
|
||||
'perl'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
|
||||
'\+p'),
|
||||
'\\+p'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-objc']/code/span",
|
||||
'--ObjC\\+\\+'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-plugin-option']/code/span",
|
||||
|
@ -482,9 +482,9 @@ def test_footnote(app, status, warning):
|
||||
assert '\\caption{Table caption \\sphinxfootnotemark[4]' in result
|
||||
assert 'name \\sphinxfootnotemark[5]' in result
|
||||
assert ('\\end{threeparttable}\n\\par\n\\endgroup\n%\n'
|
||||
'\\begin{footnotetext}[4]\sphinxAtStartFootnote\n'
|
||||
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n'
|
||||
'footnotes in table caption\n%\n\\end{footnotetext}%\n'
|
||||
'\\begin{footnotetext}[5]\sphinxAtStartFootnote\n'
|
||||
'\\begin{footnotetext}[5]\\sphinxAtStartFootnote\n'
|
||||
'footnotes in table\n%\n\\end{footnotetext}') in result
|
||||
|
||||
|
||||
@ -507,18 +507,18 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
|
||||
'%\n\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n'
|
||||
'Footnote in section\n%\n\\end{footnotetext}') in result
|
||||
assert ('\\caption{This is the figure caption with a footnote to '
|
||||
'\\sphinxfootnotemark[6].}\label{\\detokenize{index:id27}}\end{figure}\n'
|
||||
'\\sphinxfootnotemark[6].}\\label{\\detokenize{index:id27}}\\end{figure}\n'
|
||||
'%\n\\begin{footnotetext}[6]\\sphinxAtStartFootnote\n'
|
||||
'Footnote in caption\n%\n\\end{footnotetext}')in result
|
||||
assert ('\\caption{footnote \\sphinxfootnotemark[7] '
|
||||
'in caption of normal table}\\label{\\detokenize{index:id28}}') in result
|
||||
assert ('\\caption{footnote \\sphinxfootnotemark[8] '
|
||||
'in caption \sphinxfootnotemark[9] of longtable}') in result
|
||||
assert ('\end{longtable}\n%\n\\begin{footnotetext}[8]'
|
||||
'\sphinxAtStartFootnote\n'
|
||||
'in caption \\sphinxfootnotemark[9] of longtable}') in result
|
||||
assert ('\\end{longtable}\n%\n\\begin{footnotetext}[8]'
|
||||
'\\sphinxAtStartFootnote\n'
|
||||
'Foot note in longtable\n%\n\\end{footnotetext}' in result)
|
||||
assert ('This is a reference to the code-block in the footnote:\n'
|
||||
'{\hyperref[\\detokenize{index:codeblockinfootnote}]'
|
||||
'{\\hyperref[\\detokenize{index:codeblockinfootnote}]'
|
||||
'{\\sphinxcrossref{\\DUrole{std,std-ref}{I am in a footnote}}}}') in result
|
||||
assert ('&\nThis is one more footnote with some code in it '
|
||||
'\\sphinxfootnotemark[10].\n\\\\') in result
|
||||
@ -855,7 +855,7 @@ def test_latex_table_tabulars(app, status, warning):
|
||||
# table having :align: option (tabular)
|
||||
table = tables['table having :align: option (tabular)']
|
||||
assert ('\\begingroup\n\\raggedright\n'
|
||||
'\\begin{tabular}{|\X{30}{100}|\X{70}{100}|}\n' in table)
|
||||
'\\begin{tabular}{|\\X{30}{100}|\\X{70}{100}|}\n' in table)
|
||||
assert ('\\hline\n\\end{tabular}\n\\par\n\\endgroup' in table)
|
||||
|
||||
# table with tabularcolumn
|
||||
|
@ -67,7 +67,7 @@ def test_code_block_caption_latex(app, status, warning):
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
|
||||
link = '\hyperref[\\detokenize{caption:name-test-rb}]' \
|
||||
link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \
|
||||
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}'
|
||||
assert caption in latex
|
||||
assert label in latex
|
||||
@ -263,7 +263,7 @@ def test_literalinclude_caption_latex(app, status, warning):
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
|
||||
link = '\hyperref[\\detokenize{caption:name-test-py}]' \
|
||||
link = '\\hyperref[\\detokenize{caption:name-test-py}]' \
|
||||
'{Listing \\ref{\\detokenize{caption:name-test-py}}}'
|
||||
assert caption in latex
|
||||
assert label in latex
|
||||
|
@ -520,12 +520,12 @@ def test_build_domain_cpp_with_add_function_parentheses_is_True(app, status, war
|
||||
('', 'MyEnum')
|
||||
]
|
||||
parenPatterns = [
|
||||
('ref function without parens ', 'paren_1\(\)'),
|
||||
('ref function with parens ', 'paren_2\(\)'),
|
||||
('ref function without parens ', r'paren_1\(\)'),
|
||||
('ref function with parens ', r'paren_2\(\)'),
|
||||
('ref function without parens, explicit title ', 'paren_3_title'),
|
||||
('ref function with parens, explicit title ', 'paren_4_title'),
|
||||
('ref op call without parens ', 'paren_5::operator\(\)\(\)'),
|
||||
('ref op call with parens ', 'paren_6::operator\(\)\(\)'),
|
||||
('ref op call without parens ', r'paren_5::operator\(\)\(\)'),
|
||||
('ref op call with parens ', r'paren_6::operator\(\)\(\)'),
|
||||
('ref op call without parens, explicit title ', 'paren_7_title'),
|
||||
('ref op call with parens, explicit title ', 'paren_8_title')
|
||||
]
|
||||
@ -566,8 +566,8 @@ def test_build_domain_cpp_with_add_function_parentheses_is_False(app, status, wa
|
||||
('ref function with parens ', 'paren_2'),
|
||||
('ref function without parens, explicit title ', 'paren_3_title'),
|
||||
('ref function with parens, explicit title ', 'paren_4_title'),
|
||||
('ref op call without parens ', 'paren_5::operator\(\)'),
|
||||
('ref op call with parens ', 'paren_6::operator\(\)'),
|
||||
('ref op call without parens ', r'paren_5::operator\(\)'),
|
||||
('ref op call with parens ', r'paren_6::operator\(\)'),
|
||||
('ref op call without parens, explicit title ', 'paren_7_title'),
|
||||
('ref op call with parens, explicit title ', 'paren_8_title')
|
||||
]
|
||||
|
@ -20,8 +20,8 @@ def test_graphviz_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
|
||||
html = (r'<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = 'Hello <img .*?/>\n graphviz world'
|
||||
@ -30,8 +30,8 @@ def test_graphviz_html(app, status, warning):
|
||||
html = '<img src=".*?" alt="digraph {\n bar -> baz\n}" />'
|
||||
assert re.search(html, content, re.M)
|
||||
|
||||
html = ('<div class="figure align-right" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
||||
html = (r'<div class="figure align-right" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@ -41,16 +41,16 @@ def test_graphviz_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'SphinxTests.tex').text()
|
||||
macro = ('\\\\begin{figure}\[htbp\]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\includegraphics{graphviz-\w+.pdf}\n'
|
||||
macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\includegraphics{graphviz-\\w+.pdf}\n'
|
||||
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
|
||||
assert re.search(macro, content, re.S)
|
||||
|
||||
macro = 'Hello \\\\includegraphics{graphviz-\w+.pdf} graphviz world'
|
||||
macro = 'Hello \\\\includegraphics{graphviz-\\w+.pdf} graphviz world'
|
||||
assert re.search(macro, content, re.S)
|
||||
|
||||
macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n'
|
||||
'\\\\includegraphics{graphviz-\w+.pdf}\n'
|
||||
'\\\\includegraphics{graphviz-\\w+.pdf}\n'
|
||||
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
|
||||
assert re.search(macro, content, re.S)
|
||||
|
||||
|
@ -24,7 +24,7 @@ def test_inheritance_diagram_html(app, status, warning):
|
||||
content = (app.outdir / 'index.html').text()
|
||||
|
||||
pattern = ('<div class="figure" id="id1">\n'
|
||||
'<img src="_images/inheritance-\w+.png" alt="Inheritance diagram of test.Foo" '
|
||||
'<img src="_images/inheritance-\\w+.png" alt="Inheritance diagram of test.Foo" '
|
||||
'class="inheritance"/>\n<p class="caption"><span class="caption-text">'
|
||||
'Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Permalink to this image">\xb6</a></p>')
|
||||
|
@ -45,8 +45,8 @@ def test_imgmath_png(app, status, warning):
|
||||
raise SkipTest('dvipng command "dvipng" is not available')
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"'
|
||||
'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"'
|
||||
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@ -61,8 +61,8 @@ def test_imgmath_svg(app, status, warning):
|
||||
raise SkipTest('dvisvgm command "dvisvgm" is not available')
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"'
|
||||
'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"'
|
||||
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
|
@ -12,5 +12,5 @@ from sphinx.util.rst import escape
|
||||
|
||||
|
||||
def test_escape():
|
||||
assert escape(':ref:`id`') == '\:ref\:\`id\`'
|
||||
assert escape('footnote [#]_') == 'footnote \[\#\]\_'
|
||||
assert escape(':ref:`id`') == r'\:ref\:\`id\`'
|
||||
assert escape('footnote [#]_') == r'footnote \[\#\]\_'
|
||||
|
@ -29,9 +29,9 @@ def bump_version(path, version_info):
|
||||
|
||||
with open(path, 'r+') as f:
|
||||
body = f.read()
|
||||
body = re.sub("(?<=__version__ = ')[^']+", version, body)
|
||||
body = re.sub("(?<=__released__ = ')[^']+", release, body)
|
||||
body = re.sub("(?<=version_info = )\(.*\)", str(version_info), body)
|
||||
body = re.sub(r"(?<=__version__ = ')[^']+", version, body)
|
||||
body = re.sub(r"(?<=__released__ = ')[^']+", release, body)
|
||||
body = re.sub(r"(?<=version_info = )\(.*\)", str(version_info), body)
|
||||
|
||||
f.seek(0)
|
||||
f.truncate(0)
|
||||
@ -39,23 +39,23 @@ def bump_version(path, version_info):
|
||||
|
||||
|
||||
def parse_version(version):
|
||||
matched = re.search('^(\d+)\.(\d+)$', version)
|
||||
matched = re.search(r'^(\d+)\.(\d+)$', version)
|
||||
if matched:
|
||||
major, minor = matched.groups()
|
||||
return (int(major), int(minor), 0, 'final', 0)
|
||||
|
||||
matched = re.search('^(\d+)\.(\d+)\.(\d+)$', version)
|
||||
matched = re.search(r'^(\d+)\.(\d+)\.(\d+)$', version)
|
||||
if matched:
|
||||
major, minor, rev = matched.groups()
|
||||
return (int(major), int(minor), int(rev), 'final', 0)
|
||||
|
||||
matched = re.search('^(\d+)\.(\d+)\s*(a|b|alpha|beta)(\d+)$', version)
|
||||
matched = re.search(r'^(\d+)\.(\d+)\s*(a|b|alpha|beta)(\d+)$', version)
|
||||
if matched:
|
||||
major, minor, typ, relver = matched.groups()
|
||||
release = RELEASE_TYPE.get(typ, typ)
|
||||
return (int(major), int(minor), 0, release, int(relver))
|
||||
|
||||
matched = re.search('^(\d+)\.(\d+)\.(\d+)\s*(a|b|alpha|beta)(\d+)$', version)
|
||||
matched = re.search(r'^(\d+)\.(\d+)\.(\d+)\s*(a|b|alpha|beta)(\d+)$', version)
|
||||
if matched:
|
||||
major, minor, rev, typ, relver = matched.groups()
|
||||
release = RELEASE_TYPE.get(typ, typ)
|
||||
@ -90,7 +90,7 @@ class Changes(object):
|
||||
def fetch_version(self):
|
||||
with open(self.path) as f:
|
||||
version = f.readline().strip()
|
||||
matched = re.search('^Release (.*) \((.*)\)$', version)
|
||||
matched = re.search(r'^Release (.*) \((.*)\)$', version)
|
||||
if matched is None:
|
||||
raise RuntimeError('Unknown CHANGES format: %s' % version)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user