From b6e10dd86a45457fd682908238eb6160539e2f6e Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Mon, 11 Sep 2023 21:41:24 -0400 Subject: [PATCH] build: use python f-strings Change-Id: I5a6537d263d8bd6297b0975f34c90dd76b9468cd --- tests/wscript | 6 +++--- tools/wscript | 18 +++++++++--------- wscript | 15 ++++++++------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/wscript b/tests/wscript index 3ecb2e0..5a21139 100644 --- a/tests/wscript +++ b/tests/wscript @@ -3,8 +3,8 @@ top = '..' def build(bld): bld.program( - target='../unit-tests', + target=f'{top}/unit-tests', name='unit-tests', - source=bld.path.ant_glob(['*.cpp'] + ['%s/**/*.cpp' % tool for tool in bld.env.BUILD_TOOLS]), - use=['core-objects'] + ['%s-objects' % tool for tool in bld.env.BUILD_TOOLS], + source=bld.path.ant_glob(['*.cpp'] + [f'{tool}/**/*.cpp' for tool in bld.env.BUILD_TOOLS]), + use=['core-objects'] + [f'{tool}-objects' for tool in bld.env.BUILD_TOOLS], install_path=None) diff --git a/tools/wscript b/tools/wscript index b374494..05041e7 100644 --- a/tools/wscript +++ b/tools/wscript @@ -6,12 +6,12 @@ from waflib import Options def options(opt): for subdir in opt.path.ant_glob('*', dir=True, src=False): tool = subdir.path_from(opt.path) - opt.add_option('--enable-%s' % tool, - help='Build tool %s (enabled by default)' % tool, - action='store_true', dest='enable_%s' % tool) - opt.add_option('--disable-%s' % tool, - help='Do not build tool %s' % tool, - action='store_true', dest='disable_%s' % tool) + opt.add_option(f'--enable-{tool}', + help=f'Build tool {tool} (enabled by default)', + action='store_true', dest=f'enable_{tool}') + opt.add_option(f'--disable-{tool}', + help=f'Do not build tool {tool}', + action='store_true', dest=f'disable_{tool}') opt.recurse(str(tool), mandatory=False) def configure(conf): @@ -23,11 +23,11 @@ def configure(conf): tool = subdir.path_from(conf.path) all_tools.add(tool) - is_enabled = getattr(Options.options, 'enable_%s' % tool) - is_disabled = getattr(Options.options, 'disable_%s' % tool) + is_enabled = getattr(Options.options, f'enable_{tool}') + is_disabled = getattr(Options.options, f'disable_{tool}') if is_enabled and is_disabled: - conf.fatal('--enable-%s and --disable-%s cannot be both specified' % (tool, tool)) + conf.fatal(f'--enable-{tool} and --disable-{tool} cannot be both specified') if is_enabled: enabled_tools.add(tool) diff --git a/wscript b/wscript index 99283ed..c6a2fa7 100644 --- a/wscript +++ b/wscript @@ -1,7 +1,8 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- +import os +import subprocess from waflib import Context, Logs, Utils -import os, subprocess VERSION = '22.12' APPNAME = 'ndn-tools' @@ -107,16 +108,16 @@ def version(ctx): # first, try to get a version string from git gotVersionFromGit = False try: - cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] - out = subprocess.check_output(cmd, universal_newlines=True).strip() + cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*'] + out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip() if out: gotVersionFromGit = True if out.startswith(GIT_TAG_PREFIX): Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) else: # no tags matched - Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) - except (OSError, subprocess.CalledProcessError): + Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}' + except (OSError, subprocess.SubprocessError): pass versionFile = ctx.path.find_node('VERSION.info') @@ -134,14 +135,14 @@ def version(ctx): # already up-to-date return except EnvironmentError as e: - Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) + Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})') else: versionFile = ctx.path.make_node('VERSION.info') try: versionFile.write(Context.g_module.VERSION) except EnvironmentError as e: - Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) + Logs.warn(f'{versionFile} is not writable ({e.strerror})') def dist(ctx): ctx.algo = 'tar.xz'