Conversation
…nd import (fixes ros-infrastructure#116) The commands `vcs validate` and `vcs import` used `argparse.FileType('r')` which opens files at parse-time but doesn't provide a way to close them, resulting in unclosed file handle warnings. This replaces `argparse.FileType` with string path arguments and explicitly manages the file descriptors using context managers (`with` statements) for files, standard input, and URL streams. Signed-off-by: Federico Rossi <federico.rossi@creativa77.com.ar>
KmoM88
marked this pull request as draft
August 13, 2026 14:15
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #121 +/- ##
===========================================
+ Coverage 26.76% 37.46% +10.70%
===========================================
Files 31 31
Lines 2298 2306 +8
Branches 405 407 +2
===========================================
+ Hits 615 864 +249
+ Misses 1623 1334 -289
- Partials 60 108 +48 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
KmoM88
force-pushed
the
fix/resource-warning-FileType
branch
5 times, most recently
from
August 13, 2026 16:41
a6f5e33 to
7e37a4f
Compare
Signed-off-by: Federico Rossi <federico.rossi@creativa77.com.ar>
KmoM88
marked this pull request as ready for review
August 13, 2026 18:11
There was a problem hiding this comment.
Pull request overview
Prevents file-handle leaks when validating or importing repository definitions.
Changes:
- Defers opening input paths until command execution.
- Closes local files and URL streams with context managers.
- Adds direct command invocation tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
vcs2l/commands/validate.py |
Manages validation input streams explicitly. |
vcs2l/commands/import_.py |
Manages file and URL input streams explicitly. |
test/test_commands.py |
Adds direct invocation coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| else: | ||
| with open(args.input, 'r', encoding='utf-8') as f: | ||
| repos = get_repositories(f) | ||
| except (RuntimeError, FileNotFoundError) as e: |
| else: | ||
| with open(input_, 'r', encoding='utf-8') as f: | ||
| repos = get_repositories(f) | ||
| except (RuntimeError, request.URLError, FileNotFoundError) as e: |
Comment on lines
+579
to
+583
| args=['--input', self.repos_file_path], | ||
| stdout=self.stdout, | ||
| stderr=self.stderr, | ||
| ) | ||
| self.assertEqual(rc, 0) |
| unittest.main() | ||
|
|
||
|
|
||
| class TestDirectMainCall(StagedReposFile): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basic Info
The commands vcs validate and vcs import used
argparse.FileType('r')which opens files at parse-time but doesn't provide a way to close them, resulting in unclosed file handle warnings.This PR replaces
argparse.FileTypewith string path arguments and explicitly manages the file descriptors using context managers for files, standard input, and URL streams.Description of contribution in a few bullet points
argparse.FileTypewith string arguments: Avoids opening files at argument parse time, preventing automatic file handle leaks.-) to preserve standard pipe-input workflows without closing the system's stdin stream.Description of how this change was tested
Clone repository and create a Test File:
example.reposwith the following content:Reproduce the Warning (on
mainbranch):validatecommand with warnings enabled:ResourceWarning: unclosed filein the output.Verify the Fix (on
fix/resource-warning-FileTypebranch):ResourceWarning.importcommand and with stdin as well: