Skip to content

Commit 02e804d

Browse files
committed
gh-512 python: % -> format(); other small refactoring
1 parent b6b3f53 commit 02e804d

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

docs/SConscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ if GetOption('enable_sphinx'):
7777
doc_env.AlwaysBuild(doc_env.Alias('docs', ['doxygen', 'sphinx']))
7878

7979
for manpage in doc_env.GlobFiles('#docs/sphinx/manuals/*.rst'):
80-
doc_env.AddDistFile(GetOption('mandir'), '#docs/man/%s.1' %
81-
manpage.srcnode().name.replace('.rst', '').replace('_', '-'))
80+
doc_env.AddDistFile(GetOption('mandir'), '#docs/man/{}.1'.format(
81+
manpage.srcnode().name.replace('.rst', '').replace('_', '-')))

docs/sphinx/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
def get_version():
1010
proc = subprocess.Popen(
1111
[sys.executable,
12-
'%s/../../scripts/scons_helpers/parse-version.py' %
13-
os.path.dirname(os.path.realpath(__file__))],
12+
os.path.dirname(os.path.realpath(__file__)) +
13+
'/../../scripts/scons_helpers/parse-version.py'],
1414
stdout=subprocess.PIPE,
1515
stderr=subprocess.STDOUT)
1616
return tuple(proc.stdout.read().decode().strip().split('.'))
@@ -32,13 +32,13 @@ def get_version():
3232
master_doc = 'index'
3333

3434
project = u'Roc Toolkit'
35-
copyright = u'%s, Roc Streaming authors' % datetime.datetime.now().year
35+
copyright = u'{}, Roc Streaming authors'.format(datetime.datetime.now().year)
3636
author = u'Roc Streaming authors'
3737

3838
version_tuple = get_version()
3939

40-
version = 'Roc Toolkit %s' % '.'.join(version_tuple[:2])
41-
release = '%s' % '.'.join(version_tuple)
40+
version = 'Roc Toolkit {}'.format('.'.join(version_tuple[:2]))
41+
release = '.'.join(version_tuple)
4242

4343
today_fmt = '%Y'
4444

@@ -55,7 +55,7 @@ def get_version():
5555

5656
# -- Options for HTML output ----------------------------------------------
5757

58-
html_title = '%s %s' % (project, release)
58+
html_title = '{} {}'.format(project, release)
5959

6060
html_theme = 'nature'
6161

scripts/help2rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def format_options(inp):
3838
col2.append(m.group(3))
3939

4040
for c1, c2 in zip(col1, col2):
41-
print(('%-'+str(maxlen+2)+'s%s') % (c1, c2))
41+
print(('{:<' + str(maxlen + 2) + '}{}').format(c1, c2))
4242

4343
format_options(
4444
filter_options(

scripts/scons_helpers/clangdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def funlock(fp):
5050
db_path = os.path.join(build_dir, "compile_commands.json")
5151

5252
cmd = {
53-
"command": "%s %s" % (compiler, ' '.join(compiler_args)),
53+
"command": "{} {}".format(compiler, ' '.join(compiler_args)),
5454
"directory": root_dir,
5555
"file": source_file,
5656
}
@@ -81,7 +81,7 @@ def funlock(fp):
8181
funlock(fp)
8282
except:
8383
e = sys.exc_info()[1]
84-
print("error: unable to write clangdb to %s" % db_path, file=sys.stderr)
84+
print("error: unable to write clangdb to " + db_path, file=sys.stderr)
8585
print(str(e), file=sys.stderr)
8686

8787
cmd = shlex.split(compiler) + compiler_args

scripts/scons_helpers/format-header.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
import datetime
2+
import fnmatch
13
import os
24
import re
5+
import shutil
36
import sys
4-
import fnmatch
57
import tempfile
6-
import shutil
7-
import datetime
8-
9-
copyright_str = '''
10-
/*
11-
* Copyright (c) %s Roc Streaming authors
12-
*
13-
* This Source Code Form is subject to the terms of the Mozilla Public
14-
* License, v. 2.0. If a copy of the MPL was not distributed with this
15-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
16-
*/
17-
''' % datetime.datetime.now().year
8+
import textwrap
9+
10+
copyright_str = textwrap.dedent('''
11+
/*
12+
* Copyright (c) {} Roc Streaming authors
13+
*
14+
* This Source Code Form is subject to the terms of the Mozilla Public
15+
* License, v. 2.0. If a copy of the MPL was not distributed with this
16+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
17+
*/
18+
''').format(datetime.datetime.now().year)
1819

1920
def is_header(path):
2021
return re.search('\.h$', path)
@@ -51,12 +52,12 @@ def make_guard(path):
5152
def make_doxygen_path(path):
5253
path = '/'.join(path.split(os.sep))
5354
path = re.sub('^\.?/', '', path)
54-
return '@file %s' % path
55+
return '@file ' + path
5556

5657
def make_doxygen_brief(text):
5758
if not text.endswith('.'):
5859
text += '.'
59-
return '@brief %s' % text
60+
return '@brief ' + text
6061

6162
def format_file(output, path):
6263
def fprint(s):
@@ -140,7 +141,7 @@ def fprint(s):
140141
continue
141142

142143
if re.match(r'^\s*//!\s*@file', line):
143-
fprint('//! %s' % make_doxygen_path(path))
144+
fprint('//! {}'.format(make_doxygen_path(path)))
144145
else:
145146
fprint(line)
146147

@@ -152,8 +153,8 @@ def fprint(s):
152153
else:
153154
if not has_doxygen:
154155
if is_header(path):
155-
fprint('//! %s' % make_doxygen_path(path))
156-
fprint('//! %s' % make_doxygen_brief(brief))
156+
fprint('//! {}'.format(make_doxygen_path(path)))
157+
fprint('//! {}'.format(make_doxygen_brief(brief)))
157158
section = 'guard'
158159
else:
159160
section = 'body'
@@ -165,12 +166,12 @@ def fprint(s):
165166
m = re.match(r'#\s*(ifndef|define)', line)
166167
if m:
167168
has_guard = True
168-
fprint('#%s %s' % (m.group(1), make_guard(path)))
169+
fprint('#{} {}'.format(m.group(1), make_guard(path)))
169170
continue
170171
else:
171172
if not has_guard:
172-
fprint('#ifndef %s' % make_guard(path))
173-
fprint('#define %s' % make_guard(path))
173+
fprint('#ifndef {}'.format_file(make_guard(path)))
174+
fprint('#define {}'.format_file(make_guard(path)))
174175
fprint('')
175176
section = 'body'
176177

@@ -182,7 +183,7 @@ def fprint(s):
182183

183184
if is_header(path):
184185
fprint('')
185-
fprint('#endif // %s' % make_guard(path))
186+
fprint('#endif // {}'.format(make_guard(path)))
186187

187188
def walk_dir(directory, patterns):
188189
for root, dirs, files in os.walk(directory):

scripts/scons_helpers/parse-version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import print_function
2+
23
import os
34
import os.path
45
import re

scripts/scons_helpers/timeout-run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
proc = subprocess.Popen(cmd)
1818

1919
def trap():
20-
print("timeout of %ss expired, aborting" % timeout, file=sys.stderr)
20+
print("timeout of {}s expired, aborting".format(timeout), file=sys.stderr)
2121
try:
2222
proc.terminate()
2323
except:

0 commit comments

Comments
 (0)