Skip to content

Commit 414bb00

Browse files
committed
fix: use shutil.which to find executable to make platform independent and move to common implementation in ament_lint
Signed-off-by: Tony Paulussen <[email protected]>
1 parent c945d90 commit 414bb00

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

ament_clang_format/ament_clang_format/main.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import yaml
2727

28+
from ament_lint.filesystem_helpers import find_executable
29+
2830

2931
def main(argv=sys.argv[1:]):
3032
config_file = os.path.join(
@@ -245,16 +247,6 @@ def main(argv=sys.argv[1:]):
245247
return rc
246248

247249

248-
def find_executable(file_names):
249-
paths = os.getenv('PATH').split(os.path.pathsep)
250-
for file_name in file_names:
251-
for path in paths:
252-
file_path = os.path.join(path, file_name)
253-
if os.path.isfile(file_path) and os.access(file_path, os.X_OK):
254-
return file_path
255-
return None
256-
257-
258250
def get_files(paths, extensions):
259251
files = []
260252
for path in paths:

ament_clang_format/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<author>Dirk Thomas</author>
1818
<author email="[email protected]">Michel Hidalgo</author>
1919

20+
<exec_depend>ament_lint</exec_depend>
2021
<exec_depend>clang-format</exec_depend>
2122
<exec_depend>python3-yaml</exec_depend>
2223

ament_clang_tidy/ament_clang_tidy/main.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import yaml
3232

33+
from ament_lint.filesystem_helpers import find_executable
3334

3435
def main(argv=sys.argv[1:]):
3536
extensions = ['c', 'cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx']
@@ -265,16 +266,6 @@ def start_subprocess(full_cmd):
265266
f.write(xml)
266267

267268

268-
def find_executable(file_names):
269-
paths = os.getenv('PATH').split(os.path.pathsep)
270-
for file_name in file_names:
271-
for path in paths:
272-
file_path = os.path.join(path, file_name)
273-
if os.path.isfile(file_path) and os.access(file_path, os.X_OK):
274-
return file_path
275-
return None
276-
277-
278269
def get_compilation_db_files(paths):
279270
files = []
280271
for path in paths:

ament_clang_tidy/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<author>Claire Wang</author>
1717
<author email="[email protected]">Michel Hidalgo</author>
1818

19+
<exec_depend>ament_lint</exec_depend>
1920
<exec_depend>clang-tidy</exec_depend>
2021
<exec_depend>python3-yaml</exec_depend>
2122

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2019 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import shutil
16+
17+
def find_executable(file_names: list[str]) -> str | None:
18+
for name in file_names:
19+
found = shutil.which(name)
20+
if found:
21+
return found
22+
return None

0 commit comments

Comments
 (0)