Repository navigation
Fix CLI mode crash when -o/--output or -t/--target is missing - #1964
mayuriphad wants to merge 4 commits into
Conversation
normalize_output_path called os.path.isdir(None) when -s and -t were given without -o, so 'python run.py -s face.jpg -t clip.mp4' died with a TypeError. Default the output to <source>-<target><ext> next to the target, the same name the directory case already uses. Passing only some of -s/-t/-o also switches to CLI mode, where start() then failed on a None target. Report a usage error instead. Fixes hacksider#1962 Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Reviewer's GuideImplementationUpdate output path normalization to support a missing output, enhancer-only naming, and unused suffixed names while preserving explicit output paths.
Validate CLI target and face-swapper source requirements during argument parsing while allowing enhancer-only runs without a source.
TestsAdd tests for CLI argument validation and GUI fallback, plus default, collision-safe, directory, and explicit-file output path behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/utilities.py" line_range="240-244" />
<code_context>
if source_path and target_path:
source_name, _ = os.path.splitext(os.path.basename(source_path))
target_name, target_extension = os.path.splitext(os.path.basename(target_path))
+ if not output_path:
+ # No -o/--output: write next to the target, named like the directory case.
+ return os.path.join(
+ os.path.dirname(target_path), source_name + "-" + target_name + target_extension
+ )
if os.path.isdir(output_path):
return os.path.join(
</code_context>
<issue_to_address>
**Concurrent outputs are corrupted**
When two CLI processes run concurrently with different sources and the same target, omitting `-o/--output`, `get_temp_output_path(target_path)` returns the same target-keyed temporary path for both processes, so their frame extraction or `temp.mp4` encoding overwrites or consumes the other process’s intermediates before each moves to its distinct default output, leaving one or both outputs corrupted or missing.
Use unique temporary paths for each process so their frame extraction and encoding intermediates cannot collide.
</issue_to_address>
### Comment 2
<location path="tests/test_utilities.py" line_range="100-101" />
<code_context>
+ utilities = _load_utilities_module()
+
+ with mock.patch.object(utilities.os.path, "isdir", return_value=True):
+ self.assertEqual(
+ utilities.normalize_output_path("source.jpg", "target.mp4", "out"),
+ utilities.os.path.join("out", "source-target.mp4"),
+ )
+
+ def test_output_file_is_kept(self) -> None:
+ utilities = _load_utilities_module()
+
+ self.assertEqual(
+ utilities.normalize_output_path("source.jpg", "target.mp4", "result.mp4"),
+ "result.mp4",
+ )
</code_context>
<issue_to_address>
**Explicit-file test depends on cwd**
When a directory named `result.mp4` exists in the test's current working directory, in `test_output_file_is_kept`, the call at `tests/test_utilities.py:101` treats `result.mp4` as a directory when one exists in the working directory, so the equality at line 102 fails even though the function correctly handles directory outputs.
Run this check in a temporary directory where `result.mp4` is known not to be a directory, or mock `os.path.isdir` to return false.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when -o is omitted, the generated output is placed beside the target using a predictable source-target filename; if a file with that name already exists, processing may overwrite it. Reverting restores the old path behavior but cannot recover the overwritten file.
Blocking findings: modules/utilities.py:244, tests/test_utilities.py:101
Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
|
Hi, just checking whether anything else is needed from my side on this PR. Happy to make changes if so. |
|
This looks good overall, but the new check blocks enhancer-only runs like: python run.py --frame-processor face_enhancer -t target.jpg -o enhanced.jpg Enhancers don’t need a source image. Could you require -s only when face_swapper is selected and add a test for this case? The GPEN enhancers are affected too. |
Enhancer-only CLI runs (face_enhancer, face_enhancer_gpen256, face_enhancer_gpen512) do not use a source image. Require -t/--target in CLI mode and -s/--source only for face_swapper. Without a source the default output name is <target>-enhanced, so the target is never overwritten. Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
|
Thanks, good catch. Changed in 6e19293:
|
Linked issuesChecked at commit 70f8258 #1962 CLI mode without -o/--output crashes with TypeError in normalize_output_path · 2 of 2 met
|
|
the cli crash is fixed, but omitting |
Without -o/--output the generated output name could already exist next to the target, and the run silently replaced it. Add a -1, -2, ... suffix until the name is unused. Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
|
Good point, changed in 70f8258: without |
Fixes #1962
Running in CLI mode without
-o/--outputcrashes during argument parsing:Changes:
normalize_output_path: when-sand-tare given but-ois not, the output now defaults to<source>-<target><ext>in the target's directory. That's the same name the code already builds when-ois a directory. An explicit-ofile or directory works as before.parse_args: passing only some of-s/-t/-o(for example only-o) also switches to CLI mode, andstart()then failed onhas_image_extension(None). It now exits with an argparse usage error:CLI mode needs both -s/--source and -t/--target. Starting with no arguments still opens the GUI.Tests:
tests/test_utilities.py:normalize_output_pathwith no output, an output directory and an output file.tests/test_core_parse_args.py: the usage error for-oonly and-sonly, plus the valid CLI and GUI cases. It reuses the import stubs fromtest_core_map_faces_fallback.py.The new tests fail on
mainand pass with the change.pytest tests/passes, excepttest_ui_live_preview.py, which needscv2and isn't installed on my machine.ruff checkis clean.Summary by Sourcery
Harden CLI argument validation and output-path handling for source, target, and enhancer workflows.
Bug Fixes:
Enhancements:
Tests: