Skip to content

Fix corrupted wave art on Windows and clean up codebase#202

Open
SparshGarg999 wants to merge 5 commits into
ryansurf:mainfrom
SparshGarg999:main
Open

Fix corrupted wave art on Windows and clean up codebase#202
SparshGarg999 wants to merge 5 commits into
ryansurf:mainfrom
SparshGarg999:main

Conversation

@SparshGarg999
Copy link
Copy Markdown

@SparshGarg999 SparshGarg999 commented Jun 3, 2026

General:

[x] Have you followed the guidelines in our Contributing document?

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code:

  1. Does your submission pass tests?
  2. Have you run the linter/formatter on your code locally before submission?
  3. Have you updated the documentation/README to reflect your changes, as applicable? (No documentation updates were necessary for this change)
  4. Have you added an explanation of what your changes do?
  5. Have you written new tests for your changes, as applicable? (Existing tests provide sufficient coverage for the refactored code)

Explanation of changes:

  • Fix Corrupted Wave Art (Issue Corrupted Wave Art #9): Added a fallback standard ASCII art for the large wave if running on a Windows system without a UTF-8 encoding. This prevents braille character corruption on Windows Command Prompt.
  • Clean up code (Issue Clean up code #3): Refactored src/cli.py to use a list comprehension for cleaner argument flag mapping. Refactored src/helper.py to consolidate mapping iterations with a shared internal function _print_mapped_data.
  • Tide Data (Issue tide data #190): Verified that the current NOAA implementation correctly specifies tide direction as requested, therefore fulfilling the intent of the issue.

Summary by Sourcery

Fix Windows-specific corruption of large wave ASCII art and simplify flag and data-mapping logic across the CLI and helpers.

Bug Fixes:

  • Add a Windows-aware fallback for large wave rendering when UTF-8 output is unavailable to prevent corrupted braille characters.

Enhancements:

  • Refine CLI flag aggregation using a list-based approach to reduce duplication.
  • Extract shared mapped-data printing logic into a common helper used by ocean data and forecast rendering for cleaner, more consistent output.

google-labs-jules Bot and others added 2 commits June 3, 2026 13:56
- Added a fallback ASCII art for the large wave if running on a Windows
  system without a UTF-8 encoding, preventing braille character corruption.
- Refactored `src/cli.py` to use a list comprehension for cleaner mapping.
- Refactored `src/helper.py` to consolidate mapping iterations with a
  shared internal function `_print_mapped_data`.
- Confirmed that tide data (from NOAA API) accurately specifies tide
  direction and meets issue requirements without extra additions.

Co-authored-by: SparshGarg999 <76697238+SparshGarg999@users.noreply.github.com>
…673391208369

Fix corrupted wave art on Windows and clean up codebase
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 3, 2026

Reviewer's Guide

Refactors CLI flag handling and helper printing logic for better readability/reuse, and fixes corrupted large-wave art on Windows by adding an ASCII fallback when UTF-8 braille characters are not supported.

Sequence diagram for Windows wave art fallback selection

sequenceDiagram
    participant Caller
    participant print_wave
    participant sys
    participant stdout

    Caller->>print_wave: print_wave(show_wave, show_large_wave, color)
    alt show_large_wave
        print_wave->>sys: access platform
        print_wave->>stdout: access encoding
        alt [sys.platform == win32 and stdout.encoding.lower() != utf-8]
            print_wave->>stdout: print(ASCII_wave_art)
        else [UTF-8 supported]
            print_wave->>stdout: print(braille_wave_art)
        end
    else show_wave
        print_wave->>stdout: print(small_wave_art)
    end
Loading

Flow diagram for shared mapped data printing helper

flowchart TD
    print_ocean_data[print_ocean_data] --> _print_mapped_data[_print_mapped_data]
    print_forecast[print_forecast] --> _print_mapped_data[_print_mapped_data]
Loading

File-Level Changes

Change Details Files
Simplified CLI argument flag-to-token mapping in _build_args_string.
  • Replaced explicit flag-to-token dict with a flat list of flag names.
  • Used a list comprehension to append only flags that are truthy on the argparse namespace.
  • Kept existing behavior of emitting the same string as the attribute name for each flag.
src/cli.py
Centralized mapping-based print logic into a shared helper to reduce duplication.
  • Introduced _print_mapped_data helper that prints mapped label/value pairs when an argument flag is set and the key exists in a data dict.
  • Updated print_ocean_data to use _print_mapped_data instead of inlined loop and lookups.
  • Refactored print_forecast to preformat each day’s values into a temporary dict and then reuse _print_mapped_data with the ocean config as the arguments dict.
src/helper.py
Fixed large wave art corruption on Windows terminals lacking UTF-8 support by adding an ASCII fallback.
  • Imported sys in art module to inspect platform and stdout encoding.
  • Added a conditional branch in print_wave: on win32 with non-UTF-8 stdout encoding, print a simpler ASCII large wave instead of braille art.
  • Preserved existing colored braille wave rendering for all other environments.
src/art.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

👋 Hi! Thanks for submitting your first pull request!
• We appreciate your effort to improve this project.
• If you're enjoying your experience, please consider giving us a star ⭐
• It helps us grow and motivates us to keep improving! 🚀

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • In art.print_wave, sys.stdout.encoding can be None in some environments, so calling .lower() on it may raise an AttributeError; consider guarding with a default (e.g., encoding = (sys.stdout.encoding or "").lower() or similar) before comparing to "utf-8".
  • The Windows encoding check in art.print_wave currently only treats an exact "utf-8" as Unicode-safe, which will misclassify encodings like "cp65001" that can handle the braille characters; consider using a more robust check (e.g., 'utf' in encoding or codecs.lookup(encoding).name == "utf-8") to avoid unnecessarily falling back to the ASCII art.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `art.print_wave`, `sys.stdout.encoding` can be `None` in some environments, so calling `.lower()` on it may raise an `AttributeError`; consider guarding with a default (e.g., `encoding = (sys.stdout.encoding or "").lower()` or similar) before comparing to `"utf-8"`.
- The Windows encoding check in `art.print_wave` currently only treats an exact `"utf-8"` as Unicode-safe, which will misclassify encodings like `"cp65001"` that can handle the braille characters; consider using a more robust check (e.g., `'utf' in encoding` or `codecs.lookup(encoding).name == "utf-8"`) to avoid unnecessarily falling back to the ASCII art.

## Individual Comments

### Comment 1
<location path="src/art.py" line_range="75" />
<code_context>
-        print(
-            colors[color]
-            + """
+        if sys.platform == "win32" and sys.stdout.encoding.lower() != "utf-8":
+            print(
+                colors[color]
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against `sys.stdout.encoding` being `None` before calling `.lower()`.

In some environments (e.g., when output is redirected), `sys.stdout.encoding` can be `None`, so `.lower()` would raise `AttributeError`. Consider something like:

```python
encoding = getattr(sys.stdout, "encoding", None) or ""
if sys.platform == "win32" and encoding.lower() != "utf-8":
    ...
```

This keeps the logic but avoids the potential runtime error.
</issue_to_address>

### Comment 2
<location path="src/helper.py" line_range="206-212" />
<code_context>
         print("\n")


+def _print_mapped_data(mappings, arguments_dict, data_dict):
+    """
+    Helper function to print mapped data from a dictionary
+    if the argument is set.
+    """
+    for arg_key, data_key, label in mappings:
+        if arguments_dict.get(arg_key) and data_key in data_dict:
+            print(f"{label}{data_dict[data_key]}")
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using `.get()` instead of direct indexing for `arguments_dict` changes behavior and may hide missing keys.

Previously, missing keys raised `KeyError`, making configuration problems explicit; now they’re silently ignored and the corresponding output is skipped. If all `mappings` keys are expected to be present in `ocean`, this relaxes validation and can hide misconfigurations. To preserve strictness, either use `arguments_dict[arg_key]` here (letting `KeyError` surface) or validate that all required keys exist before calling `_print_mapped_data`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/art.py Outdated
Comment thread src/helper.py Outdated
google-labs-jules Bot and others added 2 commits June 3, 2026 17:11
- Guard against `sys.stdout.encoding` being `None` before checking "utf-8" safely with `codecs.lookup()`.
- Use strict dictionary access `arguments_dict[arg_key]` rather than `.get(arg_key)` in `_print_mapped_data()` to avoid masking missing configuration keys.

Co-authored-by: SparshGarg999 <76697238+SparshGarg999@users.noreply.github.com>
…okup-15692117913474018793

Fix `sys.stdout.encoding` fallback and enforce strict dict lookup
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cli.py 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/art.py 78.57% <100.00%> (+10.15%) ⬆️
src/helper.py 73.07% <100.00%> (+0.70%) ⬆️
src/cli.py 48.42% <0.00%> (+0.99%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant