Skip to content

Commit 9e5becf

Browse files
authored
Fix bug where condition always evaluate to true (#116)
* Fix bug where condition always evaluate to true * Update CHANGELOG
1 parent 658b047 commit 9e5becf

File tree

3 files changed

+107
-27
lines changed

3 files changed

+107
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Apply new linter/formatters
1313

14+
### Fixed
15+
16+
- Fixed a bug where a condition always evaluated to `true`
17+
1418
### Repository
1519

1620
- Update GitHub Action `action/setup-python` to v5

cmake_pc_hooks/_cmake.py

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def get_cmake_command(cmake_names=None): # pragma: nocover
6666
cmake_names = ['cmake', 'cmake3']
6767

6868
for cmake in cmake_names:
69-
cmake_cmd = [shutil.which(cmake)]
70-
if cmake_cmd is not None and _try_calling_cmake(cmake_cmd):
71-
return cmake_cmd
69+
cmake_cmd = shutil.which(cmake)
70+
if cmake_cmd is not None and _try_calling_cmake([cmake_cmd]):
71+
return [cmake_cmd]
7272

7373
# CMake not in PATH, should have installed Python CMake module
7474
# -> try to find out where it is
@@ -128,7 +128,8 @@ def add_cmake_arguments_to_parser(parser):
128128
description='Options mirroring those of CMake and that will be passed onto CMake as-is.',
129129
)
130130
options = parser.add_argument_group(
131-
title='Other CMake related options', description='Options used to configure how CMake is called'
131+
title='Other CMake related options',
132+
description='Options used to configure how CMake is called',
132133
)
133134
platform_specific_cmake = parser.add_argument_group(
134135
title='Options to define platform-dependent CMake variables',
@@ -141,7 +142,11 @@ def add_cmake_arguments_to_parser(parser):
141142

142143
# Custom options
143144
options.add_argument('--clean', action='store_true', help='Start from a clean build directory')
144-
options.add_argument('--cmake', type=_argparse.executable_path, help='Specify path to CMake executable.')
145+
options.add_argument(
146+
'--cmake',
147+
type=_argparse.executable_path,
148+
help='Specify path to CMake executable.',
149+
)
145150
options.add_argument(
146151
'--detect-configured-files',
147152
action='store_true',
@@ -171,20 +176,40 @@ def add_cmake_arguments_to_parser(parser):
171176
help='Unix-only (ie. Linux and MacOS) options for CMake',
172177
)
173178
platform_specific_cmake.add_argument(
174-
'--linux', action=_argparse.OSSpecificAction, type=str, help='Linux-only options for CMake'
179+
'--linux',
180+
action=_argparse.OSSpecificAction,
181+
type=str,
182+
help='Linux-only options for CMake',
175183
)
176184
platform_specific_cmake.add_argument(
177-
'--mac', action=_argparse.OSSpecificAction, type=str, help='Mac-only options for CMake'
185+
'--mac',
186+
action=_argparse.OSSpecificAction,
187+
type=str,
188+
help='Mac-only options for CMake',
178189
)
179190
platform_specific_cmake.add_argument(
180-
'--win', action=_argparse.OSSpecificAction, type=str, help='Windows-only options for CMake'
191+
'--win',
192+
action=_argparse.OSSpecificAction,
193+
type=str,
194+
help='Windows-only options for CMake',
181195
)
182196

183197
# CMake-like options
184198
cmake_options.add_argument('-S', '--source-dir', type=str, help='Path to build directory', default='.')
185-
cmake_options.add_argument('-B', '--build-dir', action='append', type=str, help='Path to build directory')
186199
cmake_options.add_argument(
187-
'-D', dest='defines', action='append', type=str, help='Create or update a cmake cache entry.', default=[]
200+
'-B',
201+
'--build-dir',
202+
action='append',
203+
type=str,
204+
help='Path to build directory',
205+
)
206+
cmake_options.add_argument(
207+
'-D',
208+
dest='defines',
209+
action='append',
210+
type=str,
211+
help='Create or update a cmake cache entry.',
212+
default=[],
188213
)
189214
cmake_options.add_argument(
190215
'-U',
@@ -196,11 +221,23 @@ def add_cmake_arguments_to_parser(parser):
196221
)
197222
cmake_options.add_argument('-G', dest='generator', type=str, help='Specify a build system generator.')
198223
cmake_options.add_argument(
199-
'-T', dest='toolset', type=str, help='Specify toolset name if supported by generator.'
224+
'-T',
225+
dest='toolset',
226+
type=str,
227+
help='Specify toolset name if supported by generator.',
200228
)
201-
cmake_options.add_argument('-A', dest='platform', type=str, help='Specify platform if supported by generator.')
202229
cmake_options.add_argument(
203-
'-Werror', dest='errors', choices=['dev'], help='Make developer warnings errors.', default=[]
230+
'-A',
231+
dest='platform',
232+
type=str,
233+
help='Specify platform if supported by generator.',
234+
)
235+
cmake_options.add_argument(
236+
'-Werror',
237+
dest='errors',
238+
choices=['dev'],
239+
help='Make developer warnings errors.',
240+
default=[],
204241
)
205242
cmake_options.add_argument(
206243
'-Wno-error',
@@ -211,9 +248,17 @@ def add_cmake_arguments_to_parser(parser):
211248
)
212249
cmake_options.add_argument('--preset', type=str, help='Specify a configure preset.')
213250

214-
cmake_options.add_argument('-Wdev', dest='dev_warnings', action='store_true', help='Enable developer warnings.')
215251
cmake_options.add_argument(
216-
'-Wno-dev', dest='no_dev_warnings', action='store_true', help='Suppress developer warnings.'
252+
'-Wdev',
253+
dest='dev_warnings',
254+
action='store_true',
255+
help='Enable developer warnings.',
256+
)
257+
cmake_options.add_argument(
258+
'-Wno-dev',
259+
dest='no_dev_warnings',
260+
action='store_true',
261+
help='Suppress developer warnings.',
217262
)
218263

219264
def resolve_build_directory(self, build_dir_list=None, *, automatic_discovery=True):
@@ -222,7 +267,10 @@ def resolve_build_directory(self, build_dir_list=None, *, automatic_discovery=Tr
222267
build_dir_list = [] if build_dir_list is None else [Path(path) for path in build_dir_list]
223268
for build_dir in build_dir_list:
224269
if build_dir.exists() and Path(build_dir, 'CMakeCache.txt').exists():
225-
logging.debug('Located valid build directory with CMakeCache.txt at: %s', str(build_dir))
270+
logging.debug(
271+
'Located valid build directory with CMakeCache.txt at: %s',
272+
str(build_dir),
273+
)
226274
self.build_dir = build_dir.resolve()
227275
return
228276

@@ -243,7 +291,10 @@ def resolve_build_directory(self, build_dir_list=None, *, automatic_discovery=Tr
243291
self.build_dir = self.source_dir / self.DEFAULT_BUILD_DIR
244292
else:
245293
self.build_dir = Path(build_dir_list[0]).resolve()
246-
logging.info('Unable to locate a valid build directory. Will be creating one at %s', str(self.build_dir))
294+
logging.info(
295+
'Unable to locate a valid build directory. Will be creating one at %s',
296+
str(self.build_dir),
297+
)
247298

248299
def setup_cmake_args(self, cmake_args): # noqa: C901
249300
"""
@@ -272,7 +323,8 @@ def setup_cmake_args(self, cmake_args): # noqa: C901
272323
self.no_cmake_configure = cmake_args.no_cmake_configure
273324

274325
self.resolve_build_directory(
275-
build_dir_list=cmake_args.build_dir, automatic_discovery=cmake_args.automatic_discovery
326+
build_dir_list=cmake_args.build_dir,
327+
automatic_discovery=cmake_args.automatic_discovery,
276328
)
277329

278330
if cmake_args.detect_configured_files and self.build_dir:
@@ -344,13 +396,29 @@ def configure(self, command, *, clean_build=False):
344396
try:
345397
with cmake_configure_try_lock.acquire(blocking=False): # noqa: SIM117
346398
with cmake_configure_lock.write_lock():
347-
logging.debug('Command %s with id %s is running CMake configure', command, os.getpid())
399+
logging.debug(
400+
'Command %s with id %s is running CMake configure',
401+
command,
402+
os.getpid(),
403+
)
348404
returncode = self._configure(
349-
lock_files=(cmake_configure_lock_file, cmake_configure_try_lock_file), clean_build=clean_build
405+
lock_files=(
406+
cmake_configure_lock_file,
407+
cmake_configure_try_lock_file,
408+
),
409+
clean_build=clean_build,
410+
)
411+
logging.debug(
412+
'Command %s with id %s is done running CMake configure',
413+
command,
414+
os.getpid(),
350415
)
351-
logging.debug('Command %s with id %s is done running CMake configure', command, os.getpid())
352416
except filelock.Timeout:
353-
logging.debug('Command %s with id %s is not running CMake configure and waiting', command, os.getpid())
417+
logging.debug(
418+
'Command %s with id %s is not running CMake configure and waiting',
419+
command,
420+
os.getpid(),
421+
)
354422
with cmake_configure_lock.read_lock():
355423
logging.debug('Command %s with id %s is done waiting', command, os.getpid())
356424
returncode = 0
@@ -368,7 +436,8 @@ def _call_cmake(self, extra_args=None):
368436
extra_args = []
369437

370438
result = _call_process.call_process(
371-
[*command, str(self.source_dir), *self.cmake_args, *extra_args], cwd=str(self.build_dir)
439+
[*command, str(self.source_dir), *self.cmake_args, *extra_args],
440+
cwd=str(self.build_dir),
372441
)
373442
result.stdout = '\n'.join([
374443
f'Running CMake with: {[*command, str(self.source_dir), *self.cmake_args]}',
@@ -392,7 +461,11 @@ def _configure(self, lock_files, clean_build):
392461

393462
extra_args = []
394463
if self.cmake_trace_log:
395-
extra_args.extend(['--trace-expand', '--trace-format=json-v1', f'--trace-redirect={self.cmake_trace_log}'])
464+
extra_args.extend([
465+
'--trace-expand',
466+
'--trace-format=json-v1',
467+
f'--trace-redirect={self.cmake_trace_log}',
468+
])
396469

397470
result = self._call_cmake(extra_args=extra_args)
398471

@@ -451,7 +524,11 @@ def _is_relevant_configure_file_call(json_data):
451524
input_file, configured_file = (Path(arg) for arg in configure_file_call['args'][:2])
452525
if not configured_file.is_absolute():
453526
configured_file = self.build_dir / configured_file
454-
logging.debug('detected call to configure_file(%s %s [...])', str(input_file), str(configured_file))
527+
logging.debug(
528+
'detected call to configure_file(%s %s [...])',
529+
str(input_file),
530+
str(configured_file),
531+
)
455532
self.cmake_configured_files.append(str(configured_file))
456533

457534

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ indent-style = "space"
150150
line-ending = 'lf'
151151
skip-magic-trailing-comma = false
152152

153-
[tool.ruff.per-file-ignores]
153+
[tool.ruff.lint.per-file-ignores]
154154

155155
'tests/python/*.py' = ['S101', 'SLF001', 'PLR0913', 'PLR2004', 'D']
156156

157-
158157
[tool.ruff.lint.flake8-annotations]
159158
allow-star-arg-any = true
160159
ignore-fully-untyped = true

0 commit comments

Comments
 (0)