sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.42k stars 2.09k forks source link

[macOS] Unable to "make html" due to locale.Error: unsupported locale setting #11739

Open DelazJ opened 10 months ago

DelazJ commented 10 months ago

Describe the bug

Hi, I'm trying to build docs locally on a macOS machine with recent versions and running make html reports

Traceback (most recent call last): File "/Users/DelazJ/Documents/gh/anotherDocBranch/venv/bin/sphinx-build", line 8, in sys.exit(main()) File "/Users/DelazJ/Documents/gh/anotherDocBranch/venv/lib/python3.9/site-packages/sphinx/cmd/build.py", line 326, in main locale.setlocale(locale.LC_ALL, '') File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/locale.py", line 610, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting make: *** [html] Error 1

Since my 4.x version of Sphinx buils without issue, and trying to understand, I found that this was a macOS issue worked around by https://github.com/sphinx-doc/sphinx/issues/5724 some time ago, and this patch was removed in https://github.com/sphinx-doc/sphinx/commit/c7d7f2951d0c43280f78c84b65df11d207ea6177 (I couldn't find the rationale but assumed because the issue on Python side is resolved?)

How to Reproduce

I think the issue relates to the OS and a Sphinx version >= 6.2.0. Any project could be used I think.

Environment Information

Platform:              darwin; (macOS-13.6-arm64-arm-64bit)
Python version:        3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.18.1
Jinja2 version:        3.1.2
Pygments version:      2.16.1

Sphinx extensions

No response

Additional context

No response

latk commented 10 months ago

Seeing the same problem on Linux. As a workaround, running under the LC_ALL=C.UTF-8 environment variable works.

feefladder commented 10 months ago

I had the same problem under Linux as well while building QGIS documentation. Environment variable didn't work, but directly calling sphinx-build worked

picnixz commented 8 months ago

I don't know why it doesn't work and I think it would be too difficult to handle each corner case. At least it appears that there is a workaround for those on Linux. As for those on Mac, this will be hard to replicate since I don't use Mac.

Maybe your environment has some invalid locale settings or things like this? I think this issue will likely stay opened a long time because it's very hard to reproduce and I think it might be an issue with the OS itself.

AA-Turner commented 8 months ago

This is likely due to https://github.com/sphinx-doc/sphinx/commit/c7d7f2951d0c43280f78c84b65df11d207ea6177. Previously we ignored locale errors (#5724) due to an issue in CPython (https://github.com/python/cpython/issues/62578#issuecomment-1093620758).

Please check in a Python console that import locale; locale.setlocale(locale.LC_ALL, '') succeeds.

A

DelazJ commented 8 months ago

Please check in a Python console that import locale; locale.setlocale(locale.LC_ALL, '') succeeds.

I get 'fr_FR.UTF-8'. TBH I don't know what to do next 😢.

AA-Turner commented 8 months ago

Is that running on Python 3.9? What's the output of the Python -VV?

DelazJ commented 8 months ago

Yes

Python 3.9.6 (default, Nov 10 2023, 13:38:27) [Clang 15.0.0 (clang-1500.1.0.2.5)]

feefladder commented 8 months ago

he lol, put it in a docker with us/utf-8 locale settings :D

MrTob commented 3 months ago

same problem on an self-hosted ubuntu runner for github actions

akshay-joshi commented 1 month ago

Do you have any idea when this issue will be resolved? We have to pin the Sphinx version to 6.1.3.

sphinx-build -W -b epub -d _build/doctrees   . _build/epub
 Traceback (most recent call last):
   File "/home/jenkins/workspace/pgadmin4-epub-snapshot/venv/bin/sphinx-build", line 8, in <module>
     sys.exit(main())
              ^^^^^^
   File "/home/jenkins/workspace/pgadmin4-epub-snapshot/venv/lib/python3.11/site-packages/sphinx/cmd/build.py", line 369, in main
     locale.setlocale(locale.LC_ALL, '')
   File "/usr/lib/python3.11/locale.py", line 626, in setlocale
     return _setlocale(category, locale)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 locale.Error: unsupported locale setting

I have tried all the workarounds above; nothing works on our build machines.

thiagocrepaldi commented 3 weeks ago

import locale; locale.setlocale(locale.LC_ALL, '')

Python fails withen_US.UTF-8`

LC_ALL="en_US.UTF-8" python -c "import locale; locale.setlocale(locale.LC_ALL, '')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/thiagofc/miniconda/envs/dev311/lib/python3.11/locale.py", line 627, in setlocale
    return _setlocale(category, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
locale.Error: unsupported locale setting

but LC_ALL="C.UTF-8" python -c "import locale; locale.setlocale(locale.LC_ALL, '')" succeeds