Skip to content

Commit c824823

Browse files
committed
Also fail early for non-existent source paths
1 parent 5fcbc6d commit c824823

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You can use gersemi with a pre-commit hook by adding the following to `.pre-comm
8989
```yaml
9090
repos:
9191
- repo: https://github.com/BlankSpruce/gersemi
92-
rev: 0.15.0
92+
rev: 0.15.1
9393
hooks:
9494
- id: gersemi
9595
```

gersemi/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
__license__ = "MPL 2.0"
55
__title__ = "gersemi"
66
__url__ = "https://github.com/BlankSpruce/gersemi"
7-
__version__ = "0.15.0"
7+
__version__ = "0.15.1"

gersemi/configuration.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ def enter_directory(target_directory):
233233

234234

235235
def normalize_definitions(definitions):
236-
return [Path(d).resolve(True) for d in definitions]
236+
try:
237+
return [Path(d).resolve(True) for d in definitions]
238+
except FileNotFoundError as e:
239+
# pylint: disable=broad-exception-raised
240+
raise Exception(f"Definition path doesn't exist: {e.filename}") from e
237241

238242

239243
def sanitize_list_expansion(list_expansion):

gersemi/runner.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_files_from_single_path(path):
4242
return [path]
4343

4444
return set(
45-
item.resolve() if item != Path("-") else item
45+
item.resolve(True) if item != Path("-") else item
4646
for path in paths
4747
for item in get_files_from_single_path(path)
4848
)
@@ -86,7 +86,12 @@ def find_all_custom_command_definitions(
8686
) -> Dict[str, Keywords]:
8787
result: Dict = {}
8888

89-
files = get_files(paths)
89+
try:
90+
files = get_files(paths)
91+
except FileNotFoundError as e:
92+
# pylint: disable=broad-exception-raised
93+
raise Exception(f"Definition path doesn't exist: {e.filename}") from e
94+
9095
find = find_custom_command_definitions_in_file
9196

9297
for defs in pool.imap_unordered(find, files, chunksize=CHUNKSIZE):
@@ -246,7 +251,11 @@ def handle_files_to_format(
246251

247252

248253
def run(mode: Mode, configuration: Configuration, sources: Iterable[Path]):
249-
requested_files = get_files(sources)
254+
try:
255+
requested_files = get_files(sources)
256+
except FileNotFoundError as e:
257+
# pylint: disable=broad-exception-raised
258+
raise Exception(f"Source path doesn't exist: {e.filename}") from e
250259

251260
pool_cm = create_pool(Path("-") in requested_files, configuration.workers)
252261
with create_cache(configuration.cache) as cache, pool_cm() as pool:

tests/test_executable.py

+30
Original file line numberDiff line numberDiff line change
@@ -1174,3 +1174,33 @@ def test_definition_path_doesnt_exist():
11741174
definitions / "back_to_the_future_four.cmake",
11751175
]
11761176
assert_fail(*common_args, *definitions_as_files_with_path_that_doesnt_exist)
1177+
1178+
1179+
def test_source_path_doesnt_exist():
1180+
with temporary_dir_copy(TESTS / "custom_project") as project:
1181+
sources = Path(project) / "formatted"
1182+
definitions = Path(project) / "formatted"
1183+
common_args = ["--definitions", definitions, "--check"]
1184+
1185+
assert_success(*common_args, sources)
1186+
1187+
assert_fail(*common_args, Path(project) / "this_path_doesnt_exist")
1188+
1189+
assert_success(*common_args, sources / ".." / "formatted")
1190+
1191+
assert_fail(*common_args, definitions / ".." / ".." / "formatted")
1192+
1193+
sources_as_files = [
1194+
sources / "CMakeLists.txt",
1195+
sources / "subdirectory_one" / "CMakeLists.txt",
1196+
sources / "subdirectory_two" / "CMakeLists.txt",
1197+
]
1198+
assert_success(*common_args, *sources_as_files)
1199+
1200+
sources_as_files_with_path_that_doesnt_exist = [
1201+
sources / "CMakeLists.txt",
1202+
sources / "this_subdirectory_doesnt_exist" / "CMakeLists.txt",
1203+
sources / "subdirectory_one" / "CMakeLists.txt",
1204+
sources / "subdirectory_two" / "CMakeLists.txt",
1205+
]
1206+
assert_fail(*common_args, *sources_as_files_with_path_that_doesnt_exist)

0 commit comments

Comments
 (0)