Skip to content

Commit

Permalink
build: use python f-strings
Browse files Browse the repository at this point in the history
Change-Id: I5a6537d263d8bd6297b0975f34c90dd76b9468cd
  • Loading branch information
Pesa committed Sep 12, 2023
1 parent 4a9e0b1 commit b6e10dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions tests/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 9 additions & 9 deletions tools/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions wscript
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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'
Expand Down

0 comments on commit b6e10dd

Please sign in to comment.