Skip to content

[WIP] Add functionality to create output file if it doesn't exist#104

Merged
ChipWolf merged 2 commits intomainfrom
copilot/create-output-file-if-not-exists
Nov 13, 2025
Merged

[WIP] Add functionality to create output file if it doesn't exist#104
ChipWolf merged 2 commits intomainfrom
copilot/create-output-file-if-not-exists

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 13, 2025

Plan: Create output file if it doesn't exist

Problem

When a user specifies an output file with -o or output: that doesn't exist, BadgeSort crashes with FileNotFoundError instead of creating the file.

Solution

Modify the file handling logic in badgesort/icons.py to:

  • Check if the output file exists before trying to read it
  • Create an empty file if it doesn't exist
  • Append badges to the new file (since there are no markers)

Implementation Checklist

  • Understand the issue and existing codebase
  • Run existing tests to ensure they pass
  • Write tests for non-existent file scenario
  • Modify badgesort/icons.py to create file if it doesn't exist
  • Run tests to verify the fix works
  • Manually test the CLI with non-existent file
  • Request code review
  • Run security scans

Changes Made

  1. Added test: test_integration_create_output_file_if_not_exists in tests/test_integration.py to verify the new behavior
  2. Modified badgesort/icons.py: Added os.path.exists() check before reading the output file. If the file doesn't exist, it initializes output_content as an empty string and logs an informative message.

Testing

  • All 23 tests pass (22 existing + 1 new)
  • Manual CLI testing confirms file is created and badges are appended correctly
  • Subsequent runs update the file as expected
Original prompt

This section details on the original issue you should resolve

<issue_title>Create the output file if it doesn't exist</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ChipWolf <3164166+ChipWolf@users.noreply.github.com>
@ChipWolf ChipWolf marked this pull request as ready for review November 13, 2025 13:54
Copilot AI review requested due to automatic review settings November 13, 2025 13:54
@ChipWolf ChipWolf merged commit 0ddd200 into main Nov 13, 2025
@ChipWolf ChipWolf deleted the copilot/create-output-file-if-not-exists branch November 13, 2025 13:54
Copilot AI requested a review from ChipWolf November 13, 2025 13:54
ChipWolf added a commit that referenced this pull request Nov 13, 2025
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ChipWolf <3164166+ChipWolf@users.noreply.github.com>
ChipWolf added a commit that referenced this pull request Nov 13, 2025
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ChipWolf <3164166+ChipWolf@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to create an output file if it doesn't exist, preventing FileNotFoundError crashes when users specify a non-existent file with the -o or output: option.

Key Changes:

  • Added file existence check before reading output file
  • New files are created with empty content and badges are appended
  • Comprehensive integration test validates the new behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
badgesort/icons.py Added os.path.exists() check to create output file if it doesn't exist, with informative logging
tests/test_integration.py Added test_integration_create_output_file_if_not_exists to verify file creation and badge generation for non-existent files
Comments suppressed due to low confidence (2)

badgesort/icons.py:163

  • 'except' clause does nothing but pass and there is no explanatory comment.
            except OSError:

badgesort/icons.py:210

  • 'except' clause does nothing but pass and there is no explanatory comment.
            except OSError:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create the output file if it doesn't exist

3 participants