Skip to content

Commit 2957743

Browse files
committed
Don't init chardet if it's not being used
This way codespell can be run on a system without chardet installed.
1 parent e47b050 commit 2957743

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

codespell.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ def __str__(self):
8989
class FileOpener:
9090
def __init__(self, use_chardet):
9191
self.use_chardet = use_chardet
92-
self.init_chardet()
92+
if use_chardet:
93+
self.init_chardet()
9394

9495
def init_chardet(self):
95-
from chardet.universaldetector import UniversalDetector
96+
try:
97+
from chardet.universaldetector import UniversalDetector
98+
except ImportError:
99+
raise Exception("There's no chardet installed to import from. "
100+
"Please, install it and check your PYTHONPATH "
101+
"environment variable")
96102

97103
self.encdetector = UniversalDetector()
98104

0 commit comments

Comments
 (0)