28 from eric7 import Preferences |
30 from eric7 import Preferences |
29 from eric7.EricWidgets import EricMessageBox |
31 from eric7.EricWidgets import EricMessageBox |
30 |
32 |
31 from .FormattingDiffWidget import FormattingDiffWidget |
33 from .FormattingDiffWidget import FormattingDiffWidget |
32 from .IsortFormattingAction import IsortFormattingAction |
34 from .IsortFormattingAction import IsortFormattingAction |
33 from .IsortUtilities import suppressStderr |
|
34 from .Ui_IsortFormattingDialog import Ui_IsortFormattingDialog |
35 from .Ui_IsortFormattingDialog import Ui_IsortFormattingDialog |
35 |
36 |
36 |
37 |
37 class IsortFormattingDialog(QDialog, Ui_IsortFormattingDialog): |
38 class IsortFormattingDialog(QDialog, Ui_IsortFormattingDialog): |
38 """ |
39 """ |
548 @type bool (optional) |
549 @type bool (optional) |
549 @return result object |
550 @return result object |
550 @rtype IsortResult |
551 @rtype IsortResult |
551 """ |
552 """ |
552 diffIO = io.StringIO() if withDiff else False |
553 diffIO = io.StringIO() if withDiff else False |
553 with suppressStderr(): |
554 with open(os.devnull, "w") as devnull: |
554 ok = check_file(filename, show_diff=diffIO, config=isortConfig) |
555 with contextlib.redirect_stderr(devnull): |
|
556 ok = check_file( |
|
557 filename, |
|
558 show_diff=diffIO, |
|
559 config=isortConfig, |
|
560 ) |
555 if withDiff: |
561 if withDiff: |
556 data = "" if ok else diffIO.getvalue() |
562 data = "" if ok else diffIO.getvalue() |
557 diffIO.close() |
563 diffIO.close() |
558 else: |
564 else: |
559 data = "" |
565 data = "" |
572 @param isortConfig config object for isort |
578 @param isortConfig config object for isort |
573 @type isort.Config |
579 @type isort.Config |
574 @return result object |
580 @return result object |
575 @rtype IsortResult |
581 @rtype IsortResult |
576 """ |
582 """ |
577 with suppressStderr(): |
583 with open(os.devnull, "w") as devnull: |
578 ok = sort_file( |
584 with contextlib.redirect_stderr(devnull): |
579 filename, |
585 ok = sort_file( |
580 config=isortConfig, |
586 filename, |
581 ask_to_apply=False, |
587 config=isortConfig, |
582 write_to_stdout=False, |
588 ask_to_apply=False, |
583 show_diff=False, |
589 write_to_stdout=False, |
584 ) |
590 show_diff=False, |
|
591 ) |
585 |
592 |
586 status = "changed" if ok else "unchanged" |
593 status = "changed" if ok else "unchanged" |
587 |
594 |
588 return IsortResult(status=status, filename=filename) |
595 return IsortResult(status=status, filename=filename) |
589 |
596 |