From b173714e682bfdfd40b318715782de9aff2095ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 14:10:57 +0000 Subject: [PATCH 1/5] Initial plan From a32b06f42b4fd93d569e88122d81c81c7dbc9150 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 14:17:12 +0000 Subject: [PATCH 2/5] Implement STDERR output flag for interactive sort Co-authored-by: MightyHelper <32612290+MightyHelper@users.noreply.github.com> --- main.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 3a6ab74..ac0b40a 100644 --- a/main.py +++ b/main.py @@ -140,8 +140,12 @@ def add_item(self, item): def display_sorted(self): """Displays the current sorted data.""" - os.system('cls' if os.name == 'nt' else 'clear') - print("--- Interactive Sorted Data ---") + output_stream = sys.stderr if self.args.stderr else sys.stdout + + if not self.args.stderr: + os.system('cls' if os.name == 'nt' else 'clear') + + print("--- Interactive Sorted Data ---", file=output_stream) items_to_display = self.data if self.args.unique: items_to_display = sorted(list(set(items_to_display)), key=lambda x: self.data.index(x)) # Maintain original order of first occurrence @@ -149,21 +153,37 @@ def display_sorted(self): items_to_display = reversed(items_to_display) for item in items_to_display: - print(item) - print("-----------------------------") + print(item, file=output_stream) + print("-----------------------------", file=output_stream) + + def output_final_sorted(self): + """Outputs the final sorted data to stdout (used when stderr flag is set).""" + items_to_display = self.data + if self.args.unique: + items_to_display = sorted(list(set(items_to_display)), key=lambda x: self.data.index(x)) # Maintain original order of first occurrence + if self.args.reverse: + items_to_display = reversed(items_to_display) + + for item in items_to_display: + print(item, file=sys.stdout) def run(self): """Runs the interactive sort application.""" - print("Enter lines of text. Press Ctrl+D (or Ctrl+Z then Enter on Windows) to finish.") + output_stream = sys.stderr if self.args.stderr else sys.stdout + print("Enter lines of text. Press Ctrl+D (or Ctrl+Z then Enter on Windows) to finish.", file=output_stream) try: while True: line = input() self.add_item(line) self.display_sorted() except EOFError: - print("\nEnd of input.") + if self.args.stderr: + # When using stderr flag, output final sorted result to stdout + self.output_final_sorted() + else: + print("\nEnd of input.", file=output_stream) except KeyboardInterrupt: - print("\nExiting.") + print("\nExiting.", file=output_stream) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Interactively sort input lines.") @@ -183,6 +203,8 @@ def run(self): help='output only the first of an equal sequence') parser.add_argument('-t', '--field-separator', type=str, default=None, help='use FIELD as the field separator when finding an ordering key') + parser.add_argument('-e', '--stderr', action='store_true', + help='send intermediate output to STDERR, final sorted output to STDOUT') args = parser.parse_args() From d8c1d9c58b21d14a3a51e8826e61901915930eaf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 15:03:45 +0000 Subject: [PATCH 3/5] Add .gitignore to exclude Python cache files Co-authored-by: MightyHelper <32612290+MightyHelper@users.noreply.github.com> --- .gitignore | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dec73e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +*.manifest +*.spec + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db \ No newline at end of file From 62ebf0eeca5f8686157c48d7ddf2296f29546e55 Mon Sep 17 00:00:00 2001 From: Federico Williamson Date: Tue, 9 Sep 2025 09:29:19 +0900 Subject: [PATCH 4/5] Fix tox --- src/interactive_sort/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/interactive_sort/main.py b/src/interactive_sort/main.py index 50329b0..a805b28 100755 --- a/src/interactive_sort/main.py +++ b/src/interactive_sort/main.py @@ -3,6 +3,7 @@ import bisect import os import re +import sys from functools import cmp_to_key @@ -155,10 +156,10 @@ def key_func(x): def display_sorted(self): """Displays the current sorted data.""" output_stream = sys.stderr if self.args.stderr else sys.stdout - + if not self.args.stderr: - os.system('cls' if os.name == 'nt' else 'clear') - + os.system("cls" if os.name == "nt" else "clear") + print("--- Interactive Sorted Data ---", file=output_stream) items_to_display = self.data if self.args.unique: @@ -176,7 +177,9 @@ def output_final_sorted(self): """Outputs the final sorted data to stdout (used when stderr flag is set).""" items_to_display = self.data if self.args.unique: - items_to_display = sorted(list(set(items_to_display)), key=lambda x: self.data.index(x)) # Maintain original order of first occurrence + items_to_display = sorted( + set(items_to_display), key=lambda x: self.data.index(x) + ) # Maintain original order of first occurrence if self.args.reverse: items_to_display = reversed(items_to_display) From 8b5997ca2054c79a2e43f84bfa091117793ee07a Mon Sep 17 00:00:00 2001 From: Federico Williamson Date: Tue, 9 Sep 2025 09:32:08 +0900 Subject: [PATCH 5/5] Update minimum python version to 3.10 because of key parameter in bisect.insort_left --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3db618..18f358a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -49,4 +49,4 @@ jobs: run: tox -e lint - name: Check formatting with ruff - run: tox -e format-check \ No newline at end of file + run: tox -e format-check