Skip to content

Commit

Permalink
gh-512 python: % -> format(); other small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed May 13, 2023
1 parent b6b3f53 commit 02e804d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ if GetOption('enable_sphinx'):
doc_env.AlwaysBuild(doc_env.Alias('docs', ['doxygen', 'sphinx']))

for manpage in doc_env.GlobFiles('#docs/sphinx/manuals/*.rst'):
doc_env.AddDistFile(GetOption('mandir'), '#docs/man/%s.1' %
manpage.srcnode().name.replace('.rst', '').replace('_', '-'))
doc_env.AddDistFile(GetOption('mandir'), '#docs/man/{}.1'.format(
manpage.srcnode().name.replace('.rst', '').replace('_', '-')))
12 changes: 6 additions & 6 deletions docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
def get_version():
proc = subprocess.Popen(
[sys.executable,
'%s/../../scripts/scons_helpers/parse-version.py' %
os.path.dirname(os.path.realpath(__file__))],
os.path.dirname(os.path.realpath(__file__)) +
'/../../scripts/scons_helpers/parse-version.py'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return tuple(proc.stdout.read().decode().strip().split('.'))
Expand All @@ -32,13 +32,13 @@ def get_version():
master_doc = 'index'

project = u'Roc Toolkit'
copyright = u'%s, Roc Streaming authors' % datetime.datetime.now().year
copyright = u'{}, Roc Streaming authors'.format(datetime.datetime.now().year)
author = u'Roc Streaming authors'

version_tuple = get_version()

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

today_fmt = '%Y'

Expand All @@ -55,7 +55,7 @@ def get_version():

# -- Options for HTML output ----------------------------------------------

html_title = '%s %s' % (project, release)
html_title = '{} {}'.format(project, release)

html_theme = 'nature'

Expand Down
2 changes: 1 addition & 1 deletion scripts/help2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def format_options(inp):
col2.append(m.group(3))

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

format_options(
filter_options(
Expand Down
4 changes: 2 additions & 2 deletions scripts/scons_helpers/clangdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def funlock(fp):
db_path = os.path.join(build_dir, "compile_commands.json")

cmd = {
"command": "%s %s" % (compiler, ' '.join(compiler_args)),
"command": "{} {}".format(compiler, ' '.join(compiler_args)),
"directory": root_dir,
"file": source_file,
}
Expand Down Expand Up @@ -81,7 +81,7 @@ def funlock(fp):
funlock(fp)
except:
e = sys.exc_info()[1]
print("error: unable to write clangdb to %s" % db_path, file=sys.stderr)
print("error: unable to write clangdb to " + db_path, file=sys.stderr)
print(str(e), file=sys.stderr)

cmd = shlex.split(compiler) + compiler_args
Expand Down
45 changes: 23 additions & 22 deletions scripts/scons_helpers/format-header.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import datetime
import fnmatch
import os
import re
import shutil
import sys
import fnmatch
import tempfile
import shutil
import datetime

copyright_str = '''
/*
* Copyright (c) %s Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
''' % datetime.datetime.now().year
import textwrap

copyright_str = textwrap.dedent('''
/*
* Copyright (c) {} Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
''').format(datetime.datetime.now().year)

def is_header(path):
return re.search('\.h$', path)
Expand Down Expand Up @@ -51,12 +52,12 @@ def make_guard(path):
def make_doxygen_path(path):
path = '/'.join(path.split(os.sep))
path = re.sub('^\.?/', '', path)
return '@file %s' % path
return '@file ' + path

def make_doxygen_brief(text):
if not text.endswith('.'):
text += '.'
return '@brief %s' % text
return '@brief ' + text

def format_file(output, path):
def fprint(s):
Expand Down Expand Up @@ -140,7 +141,7 @@ def fprint(s):
continue

if re.match(r'^\s*//!\s*@file', line):
fprint('//! %s' % make_doxygen_path(path))
fprint('//! {}'.format(make_doxygen_path(path)))
else:
fprint(line)

Expand All @@ -152,8 +153,8 @@ def fprint(s):
else:
if not has_doxygen:
if is_header(path):
fprint('//! %s' % make_doxygen_path(path))
fprint('//! %s' % make_doxygen_brief(brief))
fprint('//! {}'.format(make_doxygen_path(path)))
fprint('//! {}'.format(make_doxygen_brief(brief)))
section = 'guard'
else:
section = 'body'
Expand All @@ -165,12 +166,12 @@ def fprint(s):
m = re.match(r'#\s*(ifndef|define)', line)
if m:
has_guard = True
fprint('#%s %s' % (m.group(1), make_guard(path)))
fprint('#{} {}'.format(m.group(1), make_guard(path)))
continue
else:
if not has_guard:
fprint('#ifndef %s' % make_guard(path))
fprint('#define %s' % make_guard(path))
fprint('#ifndef {}'.format_file(make_guard(path)))
fprint('#define {}'.format_file(make_guard(path)))
fprint('')
section = 'body'

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

if is_header(path):
fprint('')
fprint('#endif // %s' % make_guard(path))
fprint('#endif // {}'.format(make_guard(path)))

def walk_dir(directory, patterns):
for root, dirs, files in os.walk(directory):
Expand Down
1 change: 1 addition & 0 deletions scripts/scons_helpers/parse-version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function

import os
import os.path
import re
Expand Down
2 changes: 1 addition & 1 deletion scripts/scons_helpers/timeout-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
proc = subprocess.Popen(cmd)

def trap():
print("timeout of %ss expired, aborting" % timeout, file=sys.stderr)
print("timeout of {}s expired, aborting".format(timeout), file=sys.stderr)
try:
proc.terminate()
except:
Expand Down

0 comments on commit 02e804d

Please sign in to comment.