aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-05-17 13:02:51 +0200
committerEgor Tensin <egor@tensin.name>2026-05-17 13:02:51 +0200
commit64899879b001d08efd5b62b97daa85d5c825c1ee (patch)
tree2cffff91f869ea9b3182961c2d3f9d859090275c
parentworkflows: add Python black run (diff)
downloadcmake-common-64899879b001d08efd5b62b97daa85d5c825c1ee.tar.gz
cmake-common-64899879b001d08efd5b62b97daa85d5c825c1ee.zip
reformat everything for fun
-rw-r--r--project/boost/archive.py5
-rw-r--r--project/boost/build.py140
-rw-r--r--project/boost/download.py51
-rw-r--r--project/boost/version.py1
-rw-r--r--project/build.py170
-rw-r--r--project/linkage.py8
-rw-r--r--project/platform.py8
-rw-r--r--project/toolset.py28
-rw-r--r--project/utils.py5
-rw-r--r--project/version.py5
-rwxr-xr-xtools/ctest-driver.py102
-rwxr-xr-xtools/project-clang-format.py66
12 files changed, 408 insertions, 181 deletions
diff --git a/project/boost/archive.py b/project/boost/archive.py
index e15e457..ee46728 100644
--- a/project/boost/archive.py
+++ b/project/boost/archive.py
@@ -75,8 +75,9 @@ class TemporaryStorage(ArchiveStorage):
@contextmanager
def write_archive(self, version, contents):
- tmp = temp_file(prefix=f'boost_{version}_',
- suffix=version.archive_ext, dir=self._dir)
+ tmp = temp_file(
+ prefix=f'boost_{version}_', suffix=version.archive_ext, dir=self._dir
+ )
with tmp as archive_path:
with open(archive_path, mode='wb') as fd:
fd.write(contents)
diff --git a/project/boost/build.py b/project/boost/build.py
index 8ef993c..a15388b 100644
--- a/project/boost/build.py
+++ b/project/boost/build.py
@@ -41,18 +41,30 @@ from project.toolset import Toolset, ToolsetVersion
from project.utils import normalize_path, setup_logging
import project.version
-
DEFAULT_PLATFORMS = (Platform.AUTO,)
-DEFAULT_CONFIGURATIONS = (Configuration.DEBUG, Configuration.RELEASE,)
+DEFAULT_CONFIGURATIONS = (
+ Configuration.DEBUG,
+ Configuration.RELEASE,
+)
DEFAULT_TOOLSET_VERSION = ToolsetVersion.default()
B2_QUIET = ['warnings=off', '-d0']
B2_VERBOSE = ['warnings=all', '-d2', '--debug-configuration']
class BuildParameters:
- def __init__(self, boost_dir, libraries, build_dir=None, platforms=None,
- configurations=None, link=None, runtime_link=None,
- toolset_version=None, verbose=False, b2_args=None):
+ def __init__(
+ self,
+ boost_dir,
+ libraries,
+ build_dir=None,
+ platforms=None,
+ configurations=None,
+ link=None,
+ runtime_link=None,
+ toolset_version=None,
+ verbose=False,
+ b2_args=None,
+ ):
boost_dir = normalize_path(boost_dir)
libraries = libraries or []
@@ -99,7 +111,9 @@ class BuildParameters:
yield self.build_dir
return
- with tempfile.TemporaryDirectory(dir=os.path.dirname(self.boost_dir)) as build_dir:
+ with tempfile.TemporaryDirectory(
+ dir=os.path.dirname(self.boost_dir)
+ ) as build_dir:
logging.info('Build directory: %s', build_dir)
try:
yield build_dir
@@ -139,59 +153,107 @@ def _parse_args(argv=None):
sys.exit(0)
parser = argparse.ArgumentParser(
- description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+ )
- parser.add_argument('--help-toolsets', action='store_true',
- help='show detailed info about supported toolsets')
+ parser.add_argument(
+ '--help-toolsets',
+ action='store_true',
+ help='show detailed info about supported toolsets',
+ )
project.version.add_to_arg_parser(parser)
- parser.add_argument('-v', '--verbose', action='store_true',
- help='verbose b2 invocation (quiet by default)')
+ parser.add_argument(
+ '-v',
+ '--verbose',
+ action='store_true',
+ help='verbose b2 invocation (quiet by default)',
+ )
- parser.add_argument('--toolset', metavar='TOOLSET', dest='toolset_version',
- type=ToolsetVersion.parse, default=DEFAULT_TOOLSET_VERSION,
- help=f'toolset to use ({ToolsetVersion.usage()})')
+ parser.add_argument(
+ '--toolset',
+ metavar='TOOLSET',
+ dest='toolset_version',
+ type=ToolsetVersion.parse,
+ default=DEFAULT_TOOLSET_VERSION,
+ help=f'toolset to use ({ToolsetVersion.usage()})',
+ )
platform_options = '/'.join(map(str, Platform.all()))
configuration_options = '/'.join(map(str, Configuration.all()))
# These are used to put the built libraries into proper installation
# directory subdirectories (to avoid name clashes).
- parser.add_argument('--platform', metavar='PLATFORM', dest='platforms',
- nargs='*', type=Platform.parse, default=[],
- help=f'target platform ({platform_options})')
- parser.add_argument('--configuration', metavar='CONFIGURATION', dest='configurations',
- nargs='*', type=Configuration.parse, default=[],
- help=f'target configuration ({configuration_options})')
+ parser.add_argument(
+ '--platform',
+ metavar='PLATFORM',
+ dest='platforms',
+ nargs='*',
+ type=Platform.parse,
+ default=[],
+ help=f'target platform ({platform_options})',
+ )
+ parser.add_argument(
+ '--configuration',
+ metavar='CONFIGURATION',
+ dest='configurations',
+ nargs='*',
+ type=Configuration.parse,
+ default=[],
+ help=f'target configuration ({configuration_options})',
+ )
linkage_options = '/'.join(map(str, Linkage.all()))
# This is needed because the default behaviour on Linux and Windows is
# different: static & dynamic libs are built on Linux, but only static libs
# are built on Windows by default.
- parser.add_argument('--link', metavar='LINKAGE',
- type=Linkage.parse, default=Linkage.default_link(),
- help=f'how the libraries are linked ({linkage_options})')
+ parser.add_argument(
+ '--link',
+ metavar='LINKAGE',
+ type=Linkage.parse,
+ default=Linkage.default_link(),
+ help=f'how the libraries are linked ({linkage_options})',
+ )
# This is used to omit runtime-link=static I'd have to otherwise use a lot,
# plus the script validates the link= and runtime-link= combinations.
- parser.add_argument('--runtime-link', metavar='LINKAGE',
- type=Linkage.parse, default=Linkage.default_runtime_link(),
- help=f'how the libraries link to the runtime ({linkage_options})')
+ parser.add_argument(
+ '--runtime-link',
+ metavar='LINKAGE',
+ type=Linkage.parse,
+ default=Linkage.default_runtime_link(),
+ help=f'how the libraries link to the runtime ({linkage_options})',
+ )
- parser.add_argument('--build', metavar='DIR', dest='build_dir',
- type=normalize_path,
- help='Boost build directory (temporary directory unless specified)')
+ parser.add_argument(
+ '--build',
+ metavar='DIR',
+ dest='build_dir',
+ type=normalize_path,
+ help='Boost build directory (temporary directory unless specified)',
+ )
- parser.add_argument('--b2-arg', metavar='ARG', dest='b2_args',
- action='extend', nargs='*',
- help='additional b2 arguments, to be passed verbatim')
+ parser.add_argument(
+ '--b2-arg',
+ metavar='ARG',
+ dest='b2_args',
+ action='extend',
+ nargs='*',
+ help='additional b2 arguments, to be passed verbatim',
+ )
- parser.add_argument('boost_dir', metavar='BOOST_DIR',
- type=normalize_path,
- help='root Boost directory')
- parser.add_argument('libraries', metavar='LIBRARIES',
- action='extend', nargs='*',
- help='libraries to build (all libraries by default)')
+ parser.add_argument(
+ 'boost_dir',
+ metavar='BOOST_DIR',
+ type=normalize_path,
+ help='root Boost directory',
+ )
+ parser.add_argument(
+ 'libraries',
+ metavar='LIBRARIES',
+ action='extend',
+ nargs='*',
+ help='libraries to build (all libraries by default)',
+ )
return parser.parse_args(argv)
diff --git a/project/boost/download.py b/project/boost/download.py
index aee80dc..5ee5e96 100644
--- a/project/boost/download.py
+++ b/project/boost/download.py
@@ -32,8 +32,9 @@ import project.version
class Download:
- def __init__(self, version, unpack_dir=None, cache_dir=None,
- dest_path=None, no_retry=False):
+ def __init__(
+ self, version, unpack_dir=None, cache_dir=None, dest_path=None, no_retry=False
+ ):
if unpack_dir is None:
if cache_dir is None:
unpack_dir = '.'
@@ -125,25 +126,39 @@ def _parse_args(argv=None):
argv = sys.argv[1:]
parser = argparse.ArgumentParser(
- description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+ )
project.version.add_to_arg_parser(parser)
- parser.add_argument('--unpack', metavar='DIR', dest='unpack_dir',
- type=normalize_path,
- help='directory to unpack the archive to')
- parser.add_argument('--cache', metavar='DIR', dest='cache_dir',
- type=normalize_path,
- help='download directory (temporary file unless specified)')
- parser.add_argument('--no-retry', action='store_true',
- help=argparse.SUPPRESS)
- parser.add_argument('version', metavar='VERSION',
- type=Version.from_string,
- help='Boost version (in the MAJOR.MINOR.PATCH format)')
- parser.add_argument('dest_path', metavar='DIR', nargs='?',
- type=normalize_path,
- help='rename the boost directory to DIR')
+ parser.add_argument(
+ '--unpack',
+ metavar='DIR',
+ dest='unpack_dir',
+ type=normalize_path,
+ help='directory to unpack the archive to',
+ )
+ parser.add_argument(
+ '--cache',
+ metavar='DIR',
+ dest='cache_dir',
+ type=normalize_path,
+ help='download directory (temporary file unless specified)',
+ )
+ parser.add_argument('--no-retry', action='store_true', help=argparse.SUPPRESS)
+ parser.add_argument(
+ 'version',
+ metavar='VERSION',
+ type=Version.from_string,
+ help='Boost version (in the MAJOR.MINOR.PATCH format)',
+ )
+ parser.add_argument(
+ 'dest_path',
+ metavar='DIR',
+ nargs='?',
+ type=normalize_path,
+ help='rename the boost directory to DIR',
+ )
return parser.parse_args(argv)
diff --git a/project/boost/version.py b/project/boost/version.py
index e49a81f..134c62a 100644
--- a/project/boost/version.py
+++ b/project/boost/version.py
@@ -8,7 +8,6 @@ from functools import total_ordering
import os.path
import re
-
_Version = namedtuple('_Version', ['major', 'minor', 'patch'])
diff --git a/project/build.py b/project/build.py
index 984bf0e..a2f2fb7 100644
--- a/project/build.py
+++ b/project/build.py
@@ -34,7 +34,6 @@ from project.toolset import Toolset, ToolsetVersion
from project.utils import normalize_path, mkdir_parent, run, setup_logging
import project.version
-
DEFAULT_PLATFORM = Platform.AUTO
DEFAULT_CONFIGURATION = Configuration.DEBUG
DEFAULT_TOOLSET_VERSION = ToolsetVersion.default()
@@ -52,9 +51,18 @@ def run_cmake(cmake_args):
class GenerationPhase:
- def __init__(self, src_dir, build_dir, platform=None, configuration=None,
- boost_dir=None, link=None, runtime_link=None,
- install_dir=None, cmake_args=None):
+ def __init__(
+ self,
+ src_dir,
+ build_dir,
+ platform=None,
+ configuration=None,
+ boost_dir=None,
+ link=None,
+ runtime_link=None,
+ install_dir=None,
+ cmake_args=None,
+ ):
self.src_dir = normalize_path(src_dir)
self.build_dir = normalize_path(build_dir)
@@ -99,10 +107,7 @@ class GenerationPhase:
args += [f'-DCMAKE_INSTALL_PREFIX={self.install_dir}']
# Important! -H must come as the last parameter, older CMake versions
# don't like it when it's not.
- args += [
- f'-B{self.build_dir}',
- f'-H{self.src_dir}'
- ]
+ args += [f'-B{self.build_dir}', f'-H{self.src_dir}']
return args
def run(self, toolset):
@@ -128,9 +133,19 @@ class BuildPhase:
class BuildParameters:
- def __init__(self, src_dir, build_dir, install_dir=None, platform=None,
- configuration=None, boost_dir=None, link=None,
- runtime_link=None, toolset_version=None, cmake_args=None):
+ def __init__(
+ self,
+ src_dir,
+ build_dir,
+ install_dir=None,
+ platform=None,
+ configuration=None,
+ boost_dir=None,
+ link=None,
+ runtime_link=None,
+ toolset_version=None,
+ cmake_args=None,
+ ):
self.src_dir = normalize_path(src_dir)
self.build_dir = normalize_path(build_dir) if build_dir else None
@@ -157,7 +172,9 @@ class BuildParameters:
yield self.build_dir
return
- with tempfile.TemporaryDirectory(dir=os.path.dirname(self.src_dir)) as build_dir:
+ with tempfile.TemporaryDirectory(
+ dir=os.path.dirname(self.src_dir)
+ ) as build_dir:
logging.info('Build directory: %s', build_dir)
try:
yield build_dir
@@ -169,17 +186,23 @@ def build(params):
with params.create_build_dir() as build_dir:
toolset = Toolset.make(params.toolset_version, params.platform)
- gen_phase = GenerationPhase(params.src_dir, build_dir,
- platform=params.platform,
- configuration=params.configuration,
- boost_dir=params.boost_dir,
- link=params.link,
- runtime_link=params.runtime_link,
- install_dir=params.install_dir,
- cmake_args=params.cmake_args)
+ gen_phase = GenerationPhase(
+ params.src_dir,
+ build_dir,
+ platform=params.platform,
+ configuration=params.configuration,
+ boost_dir=params.boost_dir,
+ link=params.link,
+ runtime_link=params.runtime_link,
+ install_dir=params.install_dir,
+ cmake_args=params.cmake_args,
+ )
gen_phase.run(toolset)
- build_phase = BuildPhase(build_dir, install_dir=params.install_dir,
- configuration=params.configuration)
+ build_phase = BuildPhase(
+ build_dir,
+ install_dir=params.install_dir,
+ configuration=params.configuration,
+ )
build_phase.run(toolset)
@@ -192,52 +215,91 @@ def _parse_args(argv=None):
sys.exit(0)
parser = argparse.ArgumentParser(
- description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+ )
- parser.add_argument('--help-toolsets', action='store_true',
- help='show detailed info about supported toolsets')
+ parser.add_argument(
+ '--help-toolsets',
+ action='store_true',
+ help='show detailed info about supported toolsets',
+ )
project.version.add_to_arg_parser(parser)
- parser.add_argument('--toolset', metavar='TOOLSET', dest='toolset_version',
- type=ToolsetVersion.parse, default=DEFAULT_TOOLSET_VERSION,
- help=f'toolset to use ({ToolsetVersion.usage()})')
+ parser.add_argument(
+ '--toolset',
+ metavar='TOOLSET',
+ dest='toolset_version',
+ type=ToolsetVersion.parse,
+ default=DEFAULT_TOOLSET_VERSION,
+ help=f'toolset to use ({ToolsetVersion.usage()})',
+ )
platform_options = '/'.join(map(str, Platform.all()))
configuration_options = '/'.join(map(str, Configuration.all()))
- parser.add_argument('--platform', metavar='PLATFORM',
- type=Platform.parse,
- help=f'target platform ({platform_options})')
- parser.add_argument('--configuration', metavar='CONFIG',
- type=Configuration.parse, default=DEFAULT_CONFIGURATION,
- help=f'build configuration ({configuration_options})')
+ parser.add_argument(
+ '--platform',
+ metavar='PLATFORM',
+ type=Platform.parse,
+ help=f'target platform ({platform_options})',
+ )
+ parser.add_argument(
+ '--configuration',
+ metavar='CONFIG',
+ type=Configuration.parse,
+ default=DEFAULT_CONFIGURATION,
+ help=f'build configuration ({configuration_options})',
+ )
- parser.add_argument('--boost', metavar='DIR', dest='boost_dir',
- type=normalize_path,
- help='set Boost directory path')
+ parser.add_argument(
+ '--boost',
+ metavar='DIR',
+ dest='boost_dir',
+ type=normalize_path,
+ help='set Boost directory path',
+ )
linkage_options = '/'.join(map(str, Linkage.all()))
- parser.add_argument('--link', metavar='LINKAGE',
- type=Linkage.parse, default=Linkage.default_link(),
- help=f'how Boost libraries are linked ({linkage_options})')
- parser.add_argument('--runtime-link', metavar='LINKAGE',
- type=Linkage.parse, default=Linkage.default_runtime_link(),
- help=f'which runtime to link to ({linkage_options})')
+ parser.add_argument(
+ '--link',
+ metavar='LINKAGE',
+ type=Linkage.parse,
+ default=Linkage.default_link(),
+ help=f'how Boost libraries are linked ({linkage_options})',
+ )
+ parser.add_argument(
+ '--runtime-link',
+ metavar='LINKAGE',
+ type=Linkage.parse,
+ default=Linkage.default_runtime_link(),
+ help=f'which runtime to link to ({linkage_options})',
+ )
- parser.add_argument('--install', metavar='DIR', dest='install_dir',
- type=normalize_path,
- help='install directory')
+ parser.add_argument(
+ '--install',
+ metavar='DIR',
+ dest='install_dir',
+ type=normalize_path,
+ help='install directory',
+ )
- parser.add_argument('--cmake-arg', metavar='ARG', dest='cmake_args',
- action='extend', nargs='*',
- help='additional CMake arguments, to be passed verbatim')
+ parser.add_argument(
+ '--cmake-arg',
+ metavar='ARG',
+ dest='cmake_args',
+ action='extend',
+ nargs='*',
+ help='additional CMake arguments, to be passed verbatim',
+ )
- parser.add_argument('src_dir', type=normalize_path,
- help='source directory')
- parser.add_argument('build_dir', type=normalize_path, nargs='?',
- help='build directory (a temporary directory if omitted)')
+ parser.add_argument('src_dir', type=normalize_path, help='source directory')
+ parser.add_argument(
+ 'build_dir',
+ type=normalize_path,
+ nargs='?',
+ help='build directory (a temporary directory if omitted)',
+ )
return parser.parse_args(argv)
diff --git a/project/linkage.py b/project/linkage.py
index 49d9d23..3a12393 100644
--- a/project/linkage.py
+++ b/project/linkage.py
@@ -42,10 +42,14 @@ class Linkage(Enum):
def validate_linkage(link, runtime_link):
if runtime_link is Linkage.STATIC:
if link is Linkage.SHARED:
- logging.warning("Cannot link the runtime statically to a dynamic library, going to link dynamically")
+ logging.warning(
+ "Cannot link the runtime statically to a dynamic library, going to link dynamically"
+ )
runtime_link = Linkage.SHARED
elif on_linux_like():
- logging.warning("Cannot link to the GNU C Library or BSD libc (which are assumed) statically, going to link dynamically")
+ logging.warning(
+ "Cannot link to the GNU C Library or BSD libc (which are assumed) statically, going to link dynamically"
+ )
runtime_link = Linkage.SHARED
return link, runtime_link
diff --git a/project/platform.py b/project/platform.py
index fa0a7d3..39ec91b 100644
--- a/project/platform.py
+++ b/project/platform.py
@@ -68,7 +68,9 @@ class Platform(Enum):
# On Windows, use the host architecture.
return Platform.windows_native().address_model()
# On Linux, assume that the target is x64.
- raise RuntimeError('cannot determine address model unless the target platform is specified explicitly')
+ raise RuntimeError(
+ 'cannot determine address model unless the target platform is specified explicitly'
+ )
if self is Platform.X86:
return 32
if self is Platform.X64:
@@ -129,7 +131,9 @@ set(CMAKE_CXX_FLAGS -m{address_model})
return Platform.windows_native().msvc_arch()
# I don't think the -A argument is supported on any generators
# except the Visual Studio ones.
- raise RuntimeError('-A parameter is only supported for Visual Studio generators')
+ raise RuntimeError(
+ '-A parameter is only supported for Visual Studio generators'
+ )
if self is Platform.X86:
return 'Win32'
if self is Platform.X64:
diff --git a/project/toolset.py b/project/toolset.py
index 2a9d797..3c90f9b 100644
--- a/project/toolset.py
+++ b/project/toolset.py
@@ -80,7 +80,9 @@ class MSVCVersion(Enum):
try:
numeric = int(self.value)
except ValueError as e:
- raise RuntimeError(f'what? MSVC versions are supposed to be integers: {self.value}') from e
+ raise RuntimeError(
+ f'what? MSVC versions are supposed to be integers: {self.value}'
+ ) from e
numeric = Decimal(numeric) / 10
numeric = numeric.quantize(Decimal('1.0'))
return str(numeric)
@@ -113,7 +115,9 @@ class VisualStudioVersion(Enum):
try:
return VisualStudioVersion(s)
except ValueError as e:
- raise argparse.ArgumentTypeError(f'invalid Visual Studio version: {s}') from e
+ raise argparse.ArgumentTypeError(
+ f'invalid Visual Studio version: {s}'
+ ) from e
@staticmethod
def all():
@@ -138,9 +142,7 @@ _msvc_to_vs_version = {
MSVCVersion.VS2022: VisualStudioVersion.VS2022,
MSVCVersion.VS2026: VisualStudioVersion.VS2026,
}
-_vs_to_msvc_version = {
- v: k for k, v in _msvc_to_vs_version.items()
-}
+_vs_to_msvc_version = {v: k for k, v in _msvc_to_vs_version.items()}
class ToolsetType(Enum):
@@ -253,7 +255,13 @@ class ToolsetVersion:
a list of all supported toolset versions:
'''
- max_name = max((len(str(hint) + str(version)) for hint in ToolsetType.all_versioned() for version in hint.all_versions()))
+ max_name = max(
+ (
+ len(str(hint) + str(version))
+ for hint in ToolsetType.all_versioned()
+ for version in hint.all_versions()
+ )
+ )
for hint in ToolsetType.all_versioned():
for version in hint.all_versions():
name = f'{hint}{version}'
@@ -270,7 +278,7 @@ a list of all supported toolset versions:
for hint in sorted(ToolsetType.all_versioned(), key=str, reverse=True):
prefix = f'{hint}'
if s.startswith(prefix):
- return ToolsetVersion(hint, hint.parse_version(s[len(prefix):]))
+ return ToolsetVersion(hint, hint.parse_version(s[len(prefix) :]))
raise argparse.ArgumentTypeError(f'invalid toolset: {s}')
@@ -307,7 +315,10 @@ class Toolset(abc.ABC):
def detect(version):
if version.hint is ToolsetType.AUTO:
return Auto
- if version.hint is ToolsetType.MSVC or version.hint is ToolsetType.VISUAL_STUDIO:
+ if (
+ version.hint is ToolsetType.MSVC
+ or version.hint is ToolsetType.VISUAL_STUDIO
+ ):
return MSVC
if version.hint is ToolsetType.GCC:
return GCC
@@ -560,7 +571,6 @@ class Clang(BoostCustom, CMakeCustom):
options = GCC.b2_build_options()
options += [
('cxxflags', '-DBOOST_USE_WINDOWS_H'),
-
# Even with <warnings>off, the build might sometimes fail with the
# following error:
#
diff --git a/project/utils.py b/project/utils.py
index b96250c..08afef5 100644
--- a/project/utils.py
+++ b/project/utils.py
@@ -52,7 +52,8 @@ def setup_logging():
level=logging.INFO,
# Log to stdout, because that's where subprocess's output goes (so that
# they don't get interleaved).
- stream=sys.stdout)
+ stream=sys.stdout,
+ )
try:
yield
except Exception as e:
@@ -126,5 +127,7 @@ def retry(exc_type, timeout=5, tries=3, backoff=2):
current_timeout *= backoff
continue
raise
+
return func2
+
return wrapper
diff --git a/project/version.py b/project/version.py
index a860fbf..41b36ad 100644
--- a/project/version.py
+++ b/project/version.py
@@ -11,5 +11,6 @@ except:
def add_to_arg_parser(parser):
- parser.add_argument('--version', '-V', action='version',
- version=f'%(prog)s {__version__}')
+ parser.add_argument(
+ '--version', '-V', action='version', version=f'%(prog)s {__version__}'
+ )
diff --git a/tools/ctest-driver.py b/tools/ctest-driver.py
index f429a0c..2a75534 100755
--- a/tools/ctest-driver.py
+++ b/tools/ctest-driver.py
@@ -22,7 +22,6 @@ import re
import subprocess
import sys
-
SCRIPT_NAME = os.path.basename(__file__)
@@ -41,9 +40,13 @@ def read_file(path):
def run(cmd_line):
try:
- result = subprocess.run(cmd_line, check=True, universal_newlines=True,
- stderr=subprocess.STDOUT,
- stdout=subprocess.PIPE)
+ result = subprocess.run(
+ cmd_line,
+ check=True,
+ universal_newlines=True,
+ stderr=subprocess.STDOUT,
+ stdout=subprocess.PIPE,
+ )
assert result.returncode == 0
return result.stdout
except subprocess.CalledProcessError as e:
@@ -53,8 +56,9 @@ def run(cmd_line):
def run_new_window(cmd_line):
try:
- result = subprocess.run(cmd_line, check=True,
- creationflags=subprocess.CREATE_NEW_CONSOLE)
+ result = subprocess.run(
+ cmd_line, check=True, creationflags=subprocess.CREATE_NEW_CONSOLE
+ )
assert result.returncode == 0
return None
except subprocess.CalledProcessError as e:
@@ -77,8 +81,10 @@ def match_pass_regexes(output, regexes):
if not regexes:
return
if not match_all(output, regexes):
- err("Couldn't match test program's output against all of the"\
- " regular expressions:")
+ err(
+ "Couldn't match test program's output against all of the"
+ " regular expressions:"
+ )
for regex in regexes:
err(f'\t{regex}')
sys.exit(1)
@@ -88,8 +94,7 @@ def match_fail_regexes(output, regexes):
if not regexes:
return
if match_any(output, regexes):
- err("Matched test program's output against some of the regular"\
- " expressions:")
+ err("Matched test program's output against some of the regular" " expressions:")
for regex in regexes:
err(f'\t{regex}')
sys.exit(1)
@@ -120,34 +125,67 @@ def parse_args(argv=None):
argv = sys.argv[1:]
parser = argparse.ArgumentParser(
- description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+ )
subparsers = parser.add_subparsers(dest='command')
- parser_run = subparsers.add_parser('run', help='run an executable and check its output')
- parser_run.add_argument('-p', '--pass-regex', nargs='*',
- dest='pass_regexes', metavar='REGEX',
- help='pass if all of these regexes match')
- parser_run.add_argument('-f', '--fail-regex', nargs='*',
- dest='fail_regexes', metavar='REGEX',
- help='fail if any of these regexes matches')
- parser_run.add_argument('-n', '--new-window', action='store_true',
- help='launch child process in a new console window')
- parser_run.add_argument('exe_path', metavar='PATH',
- help='path to the test executable')
+ parser_run = subparsers.add_parser(
+ 'run', help='run an executable and check its output'
+ )
+ parser_run.add_argument(
+ '-p',
+ '--pass-regex',
+ nargs='*',
+ dest='pass_regexes',
+ metavar='REGEX',
+ help='pass if all of these regexes match',
+ )
+ parser_run.add_argument(
+ '-f',
+ '--fail-regex',
+ nargs='*',
+ dest='fail_regexes',
+ metavar='REGEX',
+ help='fail if any of these regexes matches',
+ )
+ parser_run.add_argument(
+ '-n',
+ '--new-window',
+ action='store_true',
+ help='launch child process in a new console window',
+ )
+ parser_run.add_argument(
+ 'exe_path', metavar='PATH', help='path to the test executable'
+ )
# nargs='*' here would discard additional '--'s.
- parser_run.add_argument('exe_args', metavar='ARG', nargs=argparse.REMAINDER,
- help='test executable arguments')
+ parser_run.add_argument(
+ 'exe_args',
+ metavar='ARG',
+ nargs=argparse.REMAINDER,
+ help='test executable arguments',
+ )
parser_run.set_defaults(func=run_actual_test_driver)
- parser_grep = subparsers.add_parser('grep', help='check file contents for matching patterns')
- parser_grep.add_argument('-p', '--pass-regex', nargs='*',
- dest='pass_regexes', metavar='REGEX',
- help='pass if all of these regexes match')
- parser_grep.add_argument('-f', '--fail-regex', nargs='*',
- dest='fail_regexes', metavar='REGEX',
- help='fail if any of these regexes matches')
+ parser_grep = subparsers.add_parser(
+ 'grep', help='check file contents for matching patterns'
+ )
+ parser_grep.add_argument(
+ '-p',
+ '--pass-regex',
+ nargs='*',
+ dest='pass_regexes',
+ metavar='REGEX',
+ help='pass if all of these regexes match',
+ )
+ parser_grep.add_argument(
+ '-f',
+ '--fail-regex',
+ nargs='*',
+ dest='fail_regexes',
+ metavar='REGEX',
+ help='fail if any of these regexes matches',
+ )
parser_grep.add_argument('path', metavar='PATH', help='text file path')
parser_grep.set_defaults(func=grep_file)
diff --git a/tools/project-clang-format.py b/tools/project-clang-format.py
index 2f36613..113f7ff 100755
--- a/tools/project-clang-format.py
+++ b/tools/project-clang-format.py
@@ -26,7 +26,8 @@ def setup_logging():
logging.basicConfig(
format='%(asctime)s | %(levelname)s | %(message)s',
datefmt='%Y-%m-%d %H:%M:%S%z',
- level=logging.INFO)
+ level=logging.INFO,
+ )
try:
yield
except Exception as e:
@@ -51,8 +52,13 @@ def normalize_path(entry):
def run(cmd_line):
logging.debug('Running executable: %s', cmd_line)
try:
- return subprocess.run(cmd_line, check=True, universal_newlines=True,
- stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ return subprocess.run(
+ cmd_line,
+ check=True,
+ universal_newlines=True,
+ stderr=subprocess.STDOUT,
+ stdout=subprocess.PIPE,
+ )
except subprocess.CalledProcessError as e:
logging.error('Process finished with exit code %d: %s', e.returncode, cmd_line)
logging.error('Its output was:\n%s', e.output)
@@ -87,8 +93,13 @@ class ClangFormat:
original_lbl = f'{path} (original)'
formatted_lbl = f'{path} (formatted)'
- diff = difflib.unified_diff(original, formatted, fromfile=original_lbl,
- tofile=formatted_lbl, lineterm='')
+ diff = difflib.unified_diff(
+ original,
+ formatted,
+ fromfile=original_lbl,
+ tofile=formatted_lbl,
+ lineterm='',
+ )
clean = True
for line in diff:
@@ -136,7 +147,9 @@ def filter_files(paths, exclude):
return (path for path in paths if not excluded(path, exclude))
-CPP_FILE_EXTENSIONS = set(('.c', '.h', '.cc', '.hh', '.cpp', '.hpp', '.cxx', '.hxx', '.cp', '.c++'))
+CPP_FILE_EXTENSIONS = set(
+ ('.c', '.h', '.cc', '.hh', '.cpp', '.hpp', '.cxx', '.hxx', '.cp', '.c++')
+)
def list_cpp_files():
@@ -150,8 +163,9 @@ DEFAULT_VERSION = 'clang-format'
DEFAULT_STYLE = 'file'
-def process_cpp_files(version=DEFAULT_VERSION, style=DEFAULT_STYLE,
- in_place=False, exclude=None):
+def process_cpp_files(
+ version=DEFAULT_VERSION, style=DEFAULT_STYLE, in_place=False, exclude=None
+):
clang_format = ClangFormat(version, style)
with cd(git_root_dir()):
cpp_files = filter_files(list_cpp_files(), exclude)
@@ -167,18 +181,32 @@ def parse_args(argv=None):
argv = sys.argv[1:]
parser = argparse.ArgumentParser(
- description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+ )
- parser.add_argument('-b', '--clang-format', dest='version',
- default=DEFAULT_VERSION,
- help='clang-format executable file path')
- parser.add_argument('-s', '--style', default=DEFAULT_STYLE,
- help='clang-format -style parameter argument')
- parser.add_argument('-i', '--in-place', action='store_true',
- help='edit the files in-place')
- parser.add_argument('-e', '--exclude', nargs='*', type=normalize_path,
- help='files or directories to exclude')
+ parser.add_argument(
+ '-b',
+ '--clang-format',
+ dest='version',
+ default=DEFAULT_VERSION,
+ help='clang-format executable file path',
+ )
+ parser.add_argument(
+ '-s',
+ '--style',
+ default=DEFAULT_STYLE,
+ help='clang-format -style parameter argument',
+ )
+ parser.add_argument(
+ '-i', '--in-place', action='store_true', help='edit the files in-place'
+ )
+ parser.add_argument(
+ '-e',
+ '--exclude',
+ nargs='*',
+ type=normalize_path,
+ help='files or directories to exclude',
+ )
return parser.parse_args(argv)