Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CTRL+C by showing a better message #3511

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Aug 8, 2024

This tidies-up messages while using interactive codespell, if the user decides to cancel using CTRL+C.

For example, before this PR:

$ codespell -i1 file.txt
hte
	hte ==> the (Y/n) ^CTraceback (most recent call last):
  File "/tmp/py310/bin/codespell", line 8, in <module>
    sys.exit(_script_main())
  File "/home/mtoews/src/codespell/codespell_lib/_codespell.py", line 1102, in _script_main
    return main(*sys.argv[1:])
  File "/home/mtoews/src/codespell/codespell_lib/_codespell.py", line 1324, in main
    bad_count += parse_file(
  File "/home/mtoews/src/codespell/codespell_lib/_codespell.py", line 1007, in parse_file
    fix, fixword = ask_for_word_fix(
  File "/home/mtoews/src/codespell/codespell_lib/_codespell.py", line 775, in ask_for_word_fix
    r = sys.stdin.readline().strip().upper()
KeyboardInterrupt

$ echo $?
130

and after this PR:

$ codespell -i1 file.txt
hte
	hte ==> the (Y/n) ^C
Cancelling '/tmp/py310/bin/codespell'
$ echo $?
130

And the same behaviour if a user starts codespell with python -m codespell_lib ...


Currently there is no test for this. It's probably possible, but not easy for me to construct. If this is important to include, I'd appreciate some tips on how to enable testing SIGINT.

@mwtoews
Copy link
Contributor Author

mwtoews commented Aug 8, 2024

Another arbitrary decision that can be changed is the return code. I've set this as 1 for now. But it could also be restored to 130 (the default for KeyboardInterrupt) or 0 for "no error". Opinions welcome.

Update: after reading up on error codes, it seems that 130 is a better choice for CTRL+C.

@mwtoews
Copy link
Contributor Author

mwtoews commented Aug 9, 2024

See related xref #3217 #3218. This PR moves the try/catch to _script_main where is is more generically caught.

@DimitriPapadopoulos DimitriPapadopoulos merged commit 3a47391 into codespell-project:master Sep 9, 2024
14 of 15 checks passed
@DimitriPapadopoulos
Copy link
Collaborator

Thank you @mwtoews!

@mwtoews mwtoews deleted the ctrl-c branch September 9, 2024 17:51
humaton pushed a commit to fedora-infra/forgejo-deployment-images that referenced this pull request Jan 24, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [codespell](https://github.com/codespell-project/codespell) | dev | minor | `2.3.0` -> `2.4.0` |

---

### Release Notes

<details>
<summary>codespell-project/codespell (codespell)</summary>

### [`v2.4.0`](https://github.com/codespell-project/codespell/releases/tag/v2.4.0)

[Compare Source](codespell-project/codespell@v2.3.0...v2.4.0)

<!-- Release notes generated using configuration in .github/release.yml at main -->

#### What's Changed

-   Exclude bots from generated release notes by [@&#8203;hugovk](https://github.com/hugovk) in codespell-project/codespell#3432
-   Refactor: Move some code to new files for reuse by [@&#8203;nthykier](https://github.com/nthykier) in codespell-project/codespell#3434
-   Add `equipmnet->equipment` by [@&#8203;korverdev](https://github.com/korverdev) in codespell-project/codespell#3438
-   Set better project description by [@&#8203;mtelka](https://github.com/mtelka) in codespell-project/codespell#3435
-   Additional en-GB → en-US entries by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3058
-   Consistent error messages by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3440
-   Add 'driven' as 'drivin' variant by [@&#8203;korverdev](https://github.com/korverdev) in codespell-project/codespell#3441
-   More typos by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3439
-   Add reusing misspelling and variants by [@&#8203;korverdev](https://github.com/korverdev) in codespell-project/codespell#3445
-   Add typos found in Emacs and elsewhere by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3447
-   MAINT: Fix codecov by [@&#8203;larsoner](https://github.com/larsoner) in codespell-project/codespell#3451
-   Add typos found in GNU Guile by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3448
-   Add corrections from Aspell (fix [#&#8203;3356](codespell-project/codespell#3356)) by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3453
-   Add entries to dictionary_informal.txt by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3456
-   Add rare typo `lien->line` by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3460
-   Add rare typo `firs->first` by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3459
-   Add rare typo `hep->heap, help,` by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3461
-   Add rare typo `brunch->branch` by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3458
-   Add corrections from `typos` dictionary (A1) by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3450
-   Add timestmp->timestamp and its variations by [@&#8203;fkmy](https://github.com/fkmy) in codespell-project/codespell#3464
-   Add .venv to .gitignore by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3466
-   Only accept documented choices after `-i` and `-q` by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3344
-   Move assertIn to the code dictionary as it's a Python test function by [@&#8203;peternewman](https://github.com/peternewman) in codespell-project/codespell#3469
-   Add some more typos by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3468
-   Add some typos from Emacs by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3471
-   Add corrections from `typos` dictionary (A2) by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3454
-   Add variations for words starting with `non-` by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3467
-   Update "Using a config file" README entry  by [@&#8203;oddhack](https://github.com/oddhack) in codespell-project/codespell#3478
-   Add two choices for verision typo fix by [@&#8203;yarikoptic](https://github.com/yarikoptic) in codespell-project/codespell#3252
-   fix typo by [@&#8203;spaette](https://github.com/spaette) in codespell-project/codespell#3479
-   \[pre-commit.ci] pre-commit manual update (ruff 0.5.0) by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3481
-   Add trusthworth(y|iness)->trustworth(y|iness) correction. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3482
-   Add thrustworth(y|iness)->trustworth(y|iness). by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3483
-   New typos by [@&#8203;gforcada](https://github.com/gforcada) in codespell-project/codespell#3484
-   add enrol->enroll to en-GB to en-US dictionary by [@&#8203;slitvackwinkler](https://github.com/slitvackwinkler) in codespell-project/codespell#3485
-   Add --ignore-multiline-regex option. by [@&#8203;julian-smith-artifex-com](https://github.com/julian-smith-artifex-com) in codespell-project/codespell#3476
-   Add spelling correction for separately. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3487
-   Start testing with Python 3.13 by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3488
-   Missing typo in dictionary by [@&#8203;matlupi](https://github.com/matlupi) in codespell-project/codespell#3497
-   Add enterpris->enterprise spelling correction. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3498
-   Add spelling correction for proir and variant. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3499
-   fix issue [#&#8203;3220](codespell-project/codespell#3220): interactive model & write-changes by [@&#8203;MercuryDemo](https://github.com/MercuryDemo) in codespell-project/codespell#3340
-   infastructure typo (15.6k hits on github) by [@&#8203;yarikoptic](https://github.com/yarikoptic) in codespell-project/codespell#3501
-   Add several spelling corrections by [@&#8203;luzpaz](https://github.com/luzpaz) in codespell-project/codespell#3500
-   Add "releaseds->released, releases," spelling correction by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3503
-   Several spelling suggestions by [@&#8203;mdeweerd](https://github.com/mdeweerd) in codespell-project/codespell#3504
-   Add favilitate->facilitate and its variations by [@&#8203;luzpaz](https://github.com/luzpaz) in codespell-project/codespell#3505
-   Add seemd -> seemed by [@&#8203;fishilico](https://github.com/fishilico) in codespell-project/codespell#3508
-   feat: add typo spelling for capabilities by [@&#8203;IndexSeek](https://github.com/IndexSeek) in codespell-project/codespell#3507
-   entirerly -> entirely by [@&#8203;matlupi](https://github.com/matlupi) in codespell-project/codespell#3512
-   Add stuty -> study and variations by [@&#8203;fishilico](https://github.com/fishilico) in codespell-project/codespell#3514
-   readibly->readably by [@&#8203;claydugo](https://github.com/claydugo) in codespell-project/codespell#3518
-   Add clapse->collapse to dictionary.txt by [@&#8203;Runtemund](https://github.com/Runtemund) in codespell-project/codespell#3513
-   fix(rare): remove loath->loathe, as loath is as common as loathe by [@&#8203;corneliusroemer](https://github.com/corneliusroemer) in codespell-project/codespell#3523
-   Add variations of 'symetriy' typo by [@&#8203;luzpaz](https://github.com/luzpaz) in codespell-project/codespell#3528
-   Add distriute->distribute (and variations) to dictionary.txt by [@&#8203;corneliusroemer](https://github.com/corneliusroemer) in codespell-project/codespell#3517
-   Some extra spelling suggestions for the dictionnary (aumatically, ...) by [@&#8203;mdeweerd](https://github.com/mdeweerd) in codespell-project/codespell#3516
-   More typos by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3465
-   Add a spelling correction by [@&#8203;fxlb](https://github.com/fxlb) in codespell-project/codespell#3533
-   Move `hom` to code dictionary by [@&#8203;skangas](https://github.com/skangas) in codespell-project/codespell#3490
-   Add `realtd->related`, `prediced->predicted` by [@&#8203;janosh](https://github.com/janosh) in codespell-project/codespell#3536
-   Handle CTRL+C by showing a better message by [@&#8203;mwtoews](https://github.com/mwtoews) in codespell-project/codespell#3511
-   Move crate->create to code dictionary by [@&#8203;luzpaz](https://github.com/luzpaz) in codespell-project/codespell#3537
-   More typos by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3535
-   Add cirumvent -> circumvent suggestion by [@&#8203;algonell](https://github.com/algonell) in codespell-project/codespell#3540
-   More typos found in numpy by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3541
-   Add spelling correction for appliance and variants. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3544
-   Workaround for Python issue by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3546
-   Partially undo [`293bec1`](codespell-project/codespell@293bec1) / [#&#8203;3465](codespell-project/codespell#3465) by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3548
-   master → main by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3555
-   Add a spelling correction by [@&#8203;fxlb](https://github.com/fxlb) in codespell-project/codespell#3552
-   Add spelling corrections for remote and variants. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3551
-   Add spelling correction for revert and variants. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3553
-   workdlow->workflow by [@&#8203;peterjc](https://github.com/peterjc) in codespell-project/codespell#3556
-   More typos found in Scipy by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3547
-   Update ruff settings by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3558
-   Improve config file documentation in README by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3495
-   Support Python 3.13 by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3560
-   feat: add typo for override and overridden by [@&#8203;IndexSeek](https://github.com/IndexSeek) in codespell-project/codespell#3564
-   feat: add strring entry for string and stirring by [@&#8203;IndexSeek](https://github.com/IndexSeek) in codespell-project/codespell#3565
-   Add spelling correction for credential and variant. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3567
-   Typo from filesystem_spec by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3559
-   Add zarr as a fix for zar. by [@&#8203;yarikoptic](https://github.com/yarikoptic) in codespell-project/codespell#3568
-   Add multiple spellings by [@&#8203;mdeweerd](https://github.com/mdeweerd) in codespell-project/codespell#3569
-   acceleratored->accelerated by [@&#8203;SpookyYomo](https://github.com/SpookyYomo) in codespell-project/codespell#3571
-   Add correction for seens->seems, seen, scenes, by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3572
-   Add generaml->general spelling correction. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3573
-   Add forach->foreach, orach, spelling correction by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3576
-   Add spelling correction for leadin. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3578
-   Minor typo fix in README  by [@&#8203;DanielYang59](https://github.com/DanielYang59) in codespell-project/codespell#3580
-   Add pauload->payload and friend by [@&#8203;peternewman](https://github.com/peternewman) in codespell-project/codespell#3581
-   These typos do not belong to code, do they? by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3470
-   Add spelling correction for "agos". by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3586
-   If `writeable` is OK, so is `overwriteable` by [@&#8203;DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in codespell-project/codespell#3593
-   Add `atfer`->`after` and variations by [@&#8203;fishilico](https://github.com/fishilico) in codespell-project/codespell#3598
-   Add poduce->produce and friends by [@&#8203;peternewman](https://github.com/peternewman) in codespell-project/codespell#3599
-   Add variations for correction: reurn->return by [@&#8203;jdufresne](https://github.com/jdufresne) in codespell-project/codespell#3600
-   Add spelling correction for various variants of everything. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3601
-   Add "sems->seems, stems, semis, sens, seams," correction by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3603
-   Add replacements for complasance and complisance by [@&#8203;TheGiraffe3](https://github.com/TheGiraffe3) in codespell-project/codespell#3597
-   Add typos found in software projects by [@&#8203;mwtoews](https://github.com/mwtoews) in codespell-project/codespell#3595
-   Add distinghish->distinguish and variations by [@&#8203;fishilico](https://github.com/fishilico) in codespell-project/codespell#3604
-   docs: typo in an example by [@&#8203;12rambau](https://github.com/12rambau) in codespell-project/codespell#3610
-   Add typos found in various software projects by [@&#8203;luzpaz](https://github.com/luzpaz) in codespell-project/codespell#3612
-   Add spelling correction for denila and variant. by [@&#8203;cfi-gb](https://github.com/cfi-gb) in codespell-project/codespell#3616
-   Remove socioeconomic entries by [@&#8203;isaak654](https://github.com/isaak654) in codespell-project/codespell#3353
-   Run pytest GitHub Action on an ARM processor by [@&#8203;cclauss](https://github.com/cclauss) in codespell-project/codespell#3619

#### New Contributors

-   [@&#8203;nthykier](https://github.com/nthykier) made their first contribution in codespell-project/codespell#3434
-   [@&#8203;mtelka](https://github.com/mtelka) made their first contribution in codespell-project/codespell#3435
-   [@&#8203;fkmy](https://github.com/fkmy) made their first contribution in codespell-project/codespell#3464
-   [@&#8203;oddhack](https://github.com/oddhack) made their first contribution in codespell-project/codespell#3478
-   [@&#8203;spaette](https://github.com/spaette) made their first contribution in codespell-project/codespell#3479
-   [@&#8203;slitvackwinkler](https://github.com/slitvackwinkler) made their first contribution in codespell-project/codespell#3485
-   [@&#8203;julian-smith-artifex-com](https://github.com/julian-smith-artifex-com) made their first contribution in codespell-project/codespell#3476
-   [@&#8203;Runtemund](https://github.com/Runtemund) made their first contribution in codespell-project/codespell#3513
-   [@&#8203;corneliusroemer](https://github.com/corneliusroemer) made their first contribution in codespell-project/codespell#3523
-   [@&#8203;mwtoews](https://github.com/mwtoews) made their first contribution in codespell-project/codespell#3511
-   [@&#8203;algonell](https://github.com/algonell) made their first contribution in codespell-project/codespell#3540
-   [@&#8203;peterjc](https://github.com/peterjc) made their first contribution in codespell-project/codespell#3556
-   [@&#8203;SpookyYomo](https://github.com/SpookyYomo) made their first contribution in codespell-project/codespell#3571
-   [@&#8203;DanielYang59](https://github.com/DanielYang59) made their first contribution in codespell-project/codespell#3580
-   [@&#8203;TheGiraffe3](https://github.com/TheGiraffe3) made their first contribution in codespell-project/codespell#3597

**Full Changelog**: codespell-project/codespell@v2.3.0...v2.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "* 0-3 * * *" (UTC), Automerge - "* 0-3 * * *" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMDYuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEwNi4wIiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6652
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants