Move target directory handling to driver instead of collection.#49
Move target directory handling to driver instead of collection.#49kreuzberger wants to merge 13 commits into
Conversation
ubmarco
left a comment
There was a problem hiding this comment.
Verdict
Request changes. The architectural direction (move "make the target dir" from Collection to each Driver) is the right call, but the implementation does not actually fix issue #22 and introduces three latent regressions.
@kreuzberger thanks a lot for the proposal, this is the right thing to do.
Please tell me whether you want to spent the time to fix below blockers.
Blockers
1. The symlink driver — the one named in #22 — is not touched
The PR comments out makedirs(dirname(target)) in collections.py L84–L87 and adds a create_target_dir() helper to the base driver, but drivers/symlink.py L42–L66 is unchanged and never calls the helper. Any user with target: "subdir/my_link" now hits a new FileNotFoundError (parent never created). No symlink test is added.
2. jinja and git drivers are not touched either
Same problem:
drivers/jinja.pyL122–L126 —open(target, "w")fails for nested targets.drivers/git.pyL37–L44 —Repo.clone_from(...)requires the parent to exist.
Other issues
3. copy_folder is modified but doesn't call create_target_dir
drivers/copy_folder.py L17–L21 — every other modified driver got the helper call. copytree happens to create intermediate dirs, but the inconsistency should be documented or fixed.
4. create_target_dir guard is effectively dead code
drivers/__init__.py L91–L100: by the time the driver sees target, collections.py has resolved it to an absolute path, so any(sep in str(target) for sep in ("/", "\\")) is always true. Replace with if os.path.dirname(target): — handles every case correctly, no special handling needed.
5. Nested try/except in copy_file.py swallows the real error
drivers/copy_file.py L17–L28 — if create_target_dir() raises, the outer handler reports "Problems during copying file" instead of a directory-creation failure. Flatten into a single block or split into two.
6. Misleading comment and leftover dead code in collections.py
L84–L87 — the removed makedirs(dirname(target)) was the existing fix for #22 (commit e8c7229). The "See #22" label suggests the line was the bug, which is the opposite of the truth. Delete the commented lines and reword.
7. Tests silently stop cleaning up
tests/conftest.py L46–L49 — try/finally now just pass. Either restore shutil.rmtree(sphinx_test_tempdir, True) or drop the try/finally entirely. Also note the typo on L13: tmproot = tmproot = tmp / srcdir.name.
Minimum changes to merge
- Add
self.create_target_dir(target)tosymlink,jinja,git(for symlink, the helper creates only the parent, which is the correct behavior). - Decide
copy_folder: add the call or document why it's skipped. - Add a test per affected driver with a nested target (
subdir/leaf). - Replace the separator-string check with
if os.path.dirname(target):. - Remove the commented-out lines in
collections.py; reword the comment. - Flatten the nested
try/exceptincopy_file.py. - Restore or remove the test cleanup
try/finally; fix thetmproottypo.
|
|
fixed 6: removed commented code, added comment why the target dir is here not created |
…d changed comment
…arget dir is created, but requires flag to avoid exceptions
d55aaef to
236592d
Compare
In Issue #22 a bug was reported due to directory handling.
This was not so clear to me cause tests were running, but have race conditions in my project due to symlink handling (directory already exists).
So i think investaged and found PR #23, that got stuck due to "responsiblity".
So i tried to get further on it: