File tree Expand file tree Collapse file tree 6 files changed +39
-7
lines changed Expand file tree Collapse file tree 6 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ Deprecated
23
23
Patch by Adam Turner.
24
24
* #13644: Deprecate the :py:attr: `!Parser.config ` and :py:attr: `!env ` attributes.
25
25
Patch by Adam Turner.
26
+ * #13665: Deprecate support for non-UTF 8 source encodings,
27
+ scheduled for removal in Sphinx 10.
28
+ Patch by Adam Turner.
26
29
27
30
Features added
28
31
--------------
Original file line number Diff line number Diff line change @@ -1157,6 +1157,9 @@ Options for source files
1157
1157
The recommended encoding is ``'utf-8-sig' ``.
1158
1158
1159
1159
.. versionadded :: 0.5
1160
+ .. deprecated :: 8.3
1161
+ Support for source encodings other than UTF-8 is deprecated.
1162
+ Sphinx 10 will only support UTF-8 files.
1160
1163
1161
1164
.. confval :: source_suffix
1162
1165
:type: :code-py: `dict[str, str] | Sequence[str] | str `
Original file line number Diff line number Diff line change @@ -646,10 +646,11 @@ configurations:
646
646
Source encoding
647
647
---------------
648
648
649
- Since the easiest way to include special characters like em dashes or copyright
650
- signs in reStructuredText is to directly write them as Unicode characters, one has to
651
- specify an encoding. Sphinx assumes source files to be encoded in UTF-8 by
652
- default; you can change this with the :confval: `source_encoding ` config value.
649
+ Sphinx supports source files that are encoded in UTF-8.
650
+ This means that the full range of Unicode __ characters may be used
651
+ directly in reStructuredText.
652
+
653
+ __ https://www.unicode.org/
653
654
654
655
655
656
Gotchas
Original file line number Diff line number Diff line change @@ -971,7 +971,7 @@ __ https://pygments.org/docs/lexers
971
971
:type: text
972
972
973
973
Explicitly specify the encoding of the file.
974
- This overwrites the default encoding (:confval:`source_encoding` ).
974
+ This overwrites the default encoding (UTF-8 ).
975
975
For example:
976
976
977
977
.. code-block:: rst
Original file line number Diff line number Diff line change @@ -895,7 +895,21 @@ def check_master_doc(
895
895
return changed
896
896
897
897
898
+ def deprecate_source_encoding (_app : Sphinx , config : Config ) -> None :
899
+ """Warn on non-UTF 8 source_encoding."""
900
+ # RemovedInSphinx10Warning
901
+ if config .source_encoding .lower () not in {'utf-8' , 'utf-8-sig' , 'utf8' }:
902
+ msg = _ (
903
+ 'Support for source encodings other than UTF-8 '
904
+ 'is deprecated and will be removed in Sphinx 10. '
905
+ 'Please comment at https://github.com/sphinx-doc/sphinx/issues/13665 '
906
+ 'if this causes a problem.'
907
+ )
908
+ logger .warning (msg )
909
+
910
+
898
911
def setup (app : Sphinx ) -> ExtensionMetadata :
912
+ app .connect ('config-inited' , deprecate_source_encoding , priority = 790 )
899
913
app .connect ('config-inited' , convert_source_suffix , priority = 800 )
900
914
app .connect ('config-inited' , convert_highlight_options , priority = 800 )
901
915
app .connect ('config-inited' , init_numfig_format , priority = 800 )
Original file line number Diff line number Diff line change 19
19
)
20
20
from sphinx .deprecation import RemovedInSphinx90Warning
21
21
from sphinx .errors import ConfigError , ExtensionError , VersionRequirementError
22
+ from sphinx .testing .util import SphinxTestApp
22
23
from sphinx .util .tags import Tags
23
24
24
25
if TYPE_CHECKING :
25
26
from collections .abc import Iterable
27
+ from pathlib import Path
26
28
from typing import TypeAlias
27
29
28
- from sphinx .testing .util import SphinxTestApp
29
-
30
30
CircularList : TypeAlias = list [int | 'CircularList' ]
31
31
CircularDict : TypeAlias = dict [str , int | 'CircularDict' ]
32
32
@@ -811,3 +811,14 @@ def test_root_doc_and_master_doc_are_synchronized() -> None:
811
811
c .root_doc = '1234'
812
812
assert c .master_doc == '1234'
813
813
assert c .root_doc == c .master_doc
814
+
815
+
816
+ def test_source_encoding_deprecation (tmp_path : Path ) -> None :
817
+ (tmp_path / 'conf.py' ).touch ()
818
+ app = SphinxTestApp (
819
+ buildername = 'dummy' ,
820
+ srcdir = tmp_path ,
821
+ confoverrides = {'source_encoding' : 'latin-1' },
822
+ )
823
+ expected = 'Support for source encodings other than UTF-8 is deprecated and will be removed'
824
+ assert expected in app .warning .getvalue ()
You can’t perform that action at this time.
0 commit comments