Skip to content

Commit f7e6b02

Browse files
committed
Move cast from Path to str into finder.find()
finder.find() expects a string for compatibility with legacy interfaces. Performing the cast inside of the function is less error-prone, and will mean fewer updates later when all of the strings are replaced with Paths. Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent d086584 commit f7e6b02

File tree

16 files changed

+22
-16
lines changed

16 files changed

+22
-16
lines changed

codebasin/finder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import collections
99
import logging
1010
import os
11+
from pathlib import Path
1112

1213
from codebasin import file_parser, platform, preprocessor, util
1314
from codebasin.language import FileLanguage
@@ -140,6 +141,11 @@ def find(
140141
lines to platforms.
141142
"""
142143

144+
# Ensure rootdir is a string for compatibility with legacy code.
145+
# TODO: Remove this once all other functionality is ported to Path.
146+
if isinstance(rootdir, Path):
147+
rootdir = str(rootdir)
148+
143149
# Build a tree for each unique file for all platforms.
144150
state = ParserState(summarize_only)
145151
for f in codebase:

tests/basic_asm/test_basic_asm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_yaml(self):
3434
},
3535
)
3636
configuration = {"CPU": entries}
37-
state = finder.find(str(self.rootdir), codebase, configuration)
37+
state = finder.find(self.rootdir, codebase, configuration)
3838
mapper = PlatformMapper(codebase)
3939
setmap = mapper.walk(state)
4040
self.assertDictEqual(
@@ -56,7 +56,7 @@ def test_ptx(self):
5656
self.assertRaises(
5757
RuntimeError,
5858
finder.find,
59-
str(self.rootdir),
59+
self.rootdir,
6060
codebase,
6161
configuration,
6262
)

tests/basic_fortran/test_basic_fortran.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_yaml(self):
4545
},
4646
],
4747
}
48-
state = finder.find(str(self.rootdir), codebase, configuration)
48+
state = finder.find(self.rootdir, codebase, configuration)
4949
mapper = PlatformMapper(codebase)
5050
setmap = mapper.walk(state)
5151
self.assertDictEqual(

tests/build-dir/test_build_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_absolute_paths(self):
6363

6464
expected_setmap = {frozenset(["one", "two"]): 1}
6565

66-
state = finder.find(str(self.rootdir), codebase, configuration)
66+
state = finder.find(self.rootdir, codebase, configuration)
6767
mapper = PlatformMapper(codebase)
6868
setmap = mapper.walk(state)
6969
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")

tests/commented_directive/test_commented_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_yaml(self):
4949
},
5050
],
5151
}
52-
state = finder.find(str(self.rootdir), codebase, configuration)
52+
state = finder.find(self.rootdir, codebase, configuration)
5353
mapper = PlatformMapper(codebase)
5454
setmap = mapper.walk(state)
5555

tests/define/test_define.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_yaml(self):
4444
},
4545
],
4646
}
47-
state = finder.find(str(self.rootdir), codebase, configuration)
47+
state = finder.find(self.rootdir, codebase, configuration)
4848
mapper = PlatformMapper(codebase)
4949
setmap = mapper.walk(state)
5050
self.assertDictEqual(

tests/disjoint/test_disjoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_yaml(self):
4343
},
4444
],
4545
}
46-
state = finder.find(str(self.rootdir), codebase, configuration)
46+
state = finder.find(self.rootdir, codebase, configuration)
4747
mapper = PlatformMapper(codebase)
4848
setmap = mapper.walk(state)
4949
self.assertDictEqual(

tests/duplicates/test_duplicates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_duplicates(self):
4747

4848
expected_setmap = {frozenset(["cpu"]): 1, frozenset(["gpu"]): 1}
4949

50-
state = finder.find(str(self.rootdir), codebase, configuration)
50+
state = finder.find(self.rootdir, codebase, configuration)
5151
mapper = PlatformMapper(codebase)
5252
setmap = mapper.walk(state)
5353
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")

tests/exclude/test_exclude.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _get_setmap(self, excludes):
2727
configuration = {
2828
"test": config.load_database(str(dbpath), str(self.rootdir)),
2929
}
30-
state = finder.find(str(self.rootdir), codebase, configuration)
30+
state = finder.find(self.rootdir, codebase, configuration)
3131
mapper = PlatformMapper(codebase)
3232
setmap = mapper.walk(state)
3333
return setmap

tests/include/test_include.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_include(self):
3636
"GPU": config.load_database(str(gpu_path), str(self.rootdir)),
3737
}
3838

39-
state = finder.find(str(self.rootdir), codebase, configuration)
39+
state = finder.find(self.rootdir, codebase, configuration)
4040
mapper = PlatformMapper(codebase)
4141
setmap = mapper.walk(state)
4242
self.assertDictEqual(

tests/literals/test_literals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_literals(self):
4242
},
4343
],
4444
}
45-
state = finder.find(str(self.rootdir), codebase, configuration)
45+
state = finder.find(self.rootdir, codebase, configuration)
4646
mapper = PlatformMapper(codebase)
4747
setmap = mapper.walk(state)
4848
self.assertDictEqual(

tests/macro_expansion/test_macro_expansion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_macro_expansion(self):
5151
"CPU": cpu_entries,
5252
"GPU": gpu_entries,
5353
}
54-
state = finder.find(str(self.rootdir), codebase, configuration)
54+
state = finder.find(self.rootdir, codebase, configuration)
5555
mapper = PlatformMapper(codebase)
5656
setmap = mapper.walk(state)
5757
self.assertDictEqual(

tests/multi_line/test_multi_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_yaml(self):
4444
},
4545
],
4646
}
47-
state = finder.find(str(self.rootdir), codebase, configuration)
47+
state = finder.find(self.rootdir, codebase, configuration)
4848
mapper = PlatformMapper(codebase)
4949
setmap = mapper.walk(state)
5050
self.assertDictEqual(

tests/nesting/test_nesting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_yaml(self):
4545
},
4646
],
4747
}
48-
state = finder.find(str(self.rootdir), codebase, configuration)
48+
state = finder.find(self.rootdir, codebase, configuration)
4949
mapper = PlatformMapper(codebase)
5050
setmap = mapper.walk(state)
5151
self.assertDictEqual(

tests/once/test_once.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_yaml(self):
4444
},
4545
],
4646
}
47-
state = finder.find(str(self.rootdir), codebase, configuration)
47+
state = finder.find(self.rootdir, codebase, configuration)
4848
mapper = PlatformMapper(codebase)
4949
setmap = mapper.walk(state)
5050
self.assertDictEqual(

tests/operators/test_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_operators(self):
4242
},
4343
],
4444
}
45-
state = finder.find(str(self.rootdir), codebase, configuration)
45+
state = finder.find(self.rootdir, codebase, configuration)
4646
mapper = PlatformMapper(codebase)
4747
setmap = mapper.walk(state)
4848
self.assertDictEqual(

0 commit comments

Comments
 (0)