Skip to content

Commit 1ea36ad

Browse files
authored
Merge pull request #1278 from wireservice/pythonioencoding
Use PYTHONIOENCODING if set (--encoding takes priority)
2 parents c327a1b + 4b0b397 commit 1ea36ad

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
- run: pip install .[test] coveralls
1919
- env:
2020
LANG: en_US.UTF-8
21-
PYTHONIOENCODING: utf-8
2221
PYTHONUTF8: 1
2322
run: pytest --cov csvkit
2423
# csvpy cannot accept input as piped data via STDIN.

csvkit/cli.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def _init_common_parser(self):
198198
help='Maximum length of a single field in the input CSV file.')
199199
if 'e' not in self.override_flags:
200200
self.argparser.add_argument(
201-
'-e', '--encoding', dest='encoding', default='utf-8-sig',
201+
'-e', '--encoding', dest='encoding', default=os.getenv('PYTHONIOENCODING', 'utf-8-sig'),
202202
help='Specify the encoding of the input CSV file.')
203203
if 'L' not in self.override_flags:
204204
self.argparser.add_argument(
@@ -330,9 +330,10 @@ def handler(t, value, traceback):
330330
# Special case handling for Unicode errors, which behave very strangely
331331
# when cast with unicode()
332332
if t == UnicodeDecodeError:
333-
sys.stderr.write('Your file is not "%s" encoded. Please specify the correct encoding with the -e '
334-
'flag or with the PYTHONIOENCODING environment variable. Use the -v flag to see '
335-
'the complete error.\n' % self.args.encoding)
333+
sys.stderr.write(
334+
'Your file is not "%s" encoded. Please specify the correct encoding with the --encoding flag.'
335+
' Use the -v flag to see the complete error.\n' % self.args.encoding
336+
)
336337
else:
337338
sys.stderr.write(f'{t.__name__}: {str(value)}\n')
338339

docs/common_arguments.rst

-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ The output of csvkit's tools is always formatted with "default" formatting optio
6868

6969
See the documentation of :doc:`/scripts/csvclean` for a description of the default formatting options.
7070

71-
.. note::
72-
73-
The ``--encoding`` option has no effect if reading from standard input. Set the ``PYTHONIOENCODING`` environment variable instead.
74-
7571
.. seealso::
7672

7773
For a list of possible values for the ``--encoding`` option, see the `Python documentation <https://docs.python.org/3/library/codecs.html#standard-encodings>`__.

0 commit comments

Comments
 (0)