src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/eradicate.py

branch
eric7
changeset 10176
5e26785b93b8
parent 9849
99782ca569ed
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/eradicate.py	Thu Aug 31 13:59:43 2023 +0200
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/eradicate.py	Thu Aug 31 14:07:24 2023 +0200
@@ -27,10 +27,17 @@
 import difflib
 import io
 import os
+import sys
 import re
 import tokenize
 
-__version__ = '2.2.0'
+try:
+    detect_encoding = tokenize.detect_encoding
+except AttributeError:
+    from lib2to3.pgen2 import tokenize as lib2to3_tokenize
+    detect_encoding = lib2to3_tokenize.detect_encoding
+
+__version__ = '2.3.0'
 
 
 class Eradicator(object):
@@ -213,8 +220,7 @@
         """Return file encoding."""
         try:
             with open(filename, 'rb') as input_file:
-                from lib2to3.pgen2 import tokenize as lib2to3_tokenize
-                encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0]
+                encoding = detect_encoding(input_file.readline)[0]
 
                 # Check for correctness of encoding.
                 with self.open_with_encoding(filename, encoding) as input_file:
@@ -236,7 +242,7 @@
                 flags=re.IGNORECASE)
 
 
-def main(argv, standard_out, standard_error):
+def main(argv=sys.argv, standard_out=sys.stdout, standard_error=sys.stderr):
     """Main entry point."""
     import argparse
     parser = argparse.ArgumentParser(description=__doc__, prog='eradicate')
@@ -292,5 +298,10 @@
             except IOError as exception:
                 print('{}'.format(exception), file=standard_error)
                 change_or_error = True
+
     if change_or_error and args.error:
         return 1
+
+
+if __name__ == '__main__':
+    main()

eric ide

mercurial