Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode Extension overrides LANG settings unconditionally, leading to non-working Python locale #814

Open
Flameeyes opened this issue Jan 17, 2024 · 8 comments

Comments

@Flameeyes
Copy link
Contributor

I'm not sure how to gather more debug information, but the VSCode extension appears to sometimes not detect correctly that the open folder is a valid Sapling checkout:

Not a valid repository
/home/flameeyes/repos/unpaper is not a valid Sapling repository. Clone or init a repository to use ISL.

(venv) flameeyes@Gamestation:~/repos/unpaper$ pwd
/home/flameeyes/repos/unpaper
(venv) flameeyes@Gamestation:~/repos/unpaper$ sl status
M imageprocess.c
M imageprocess.h
M meson.build
M unpaper.c
? imageprocess/deskew.c
? imageprocess/deskew.h

opening a different folder and going back to the original appears to fix it, but I have no idea why is that even the case.

@quark-zju
Copy link
Contributor

Does the "Output" -> "Sapling ISL" provide some insights?

image

@Flameeyes
Copy link
Contributor Author

sigh I was looking everywhere and couldn't find that.

I can't reproduce it right now, it might have something to do with a cold open? I'll see if I can reproduce this tomorrow, usually I seem to get it once every so often, and when I do I'll post here!

@Flameeyes
Copy link
Contributor Author

Hah, I just found a failure after returning from (computer's) sleep:

Failed to fetch commits
Command failed with exit code 1: sl log --template {node} {desc|firstline} {author} {committerdate|isodatesec} {phase} {bookmarks % '{bookmark}\0'} {remotenames % '{remotename}\0'} {parents % "{node}\0"} {ifcontains(rev, revset('.'), '@')} {file_adds|json} {file_mods|json} {file_dels|json} {mutations % "{operation}:{successors % "{node}"},"} {predecessors % "{node},"} {if(phabdiff, phabdiff, github_pull_request_number)} {desc} <<COMMIT_END_MARK>> --rev smartlog(((interestingbookmarks() + heads(draft())) & date(-14)) + .) --noninteractive --config extensions.blackbox=! Traceback (most recent call last): File "static:sapling", line 64, in run from . import dispatch File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.dispatch", line 27, in <module> from . import ( File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.cmdutil", line 29, in <module> from . import ( File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.crecord", line 32, in <module> locale.setlocale(locale.LC_ALL, "") File "/usr/lib/python3.10/locale.py", line 620, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting
You are here
Failed to fetch Uncommitted Changes
Command failed with exit code 1: sl status -Tjson --copies --noninteractive --config extensions.blackbox=! --config fsmonitor.watchman-query-lock=True Traceback (most recent call last): File "static:sapling", line 64, in run from . import dispatch File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.dispatch", line 27, in <module> from . import ( File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.cmdutil", line 29, in <module> from . import ( File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "static:sapling.crecord", line 32, in <module> locale.setlocale(locale.LC_ALL, "") File "/usr/lib/python3.10/locale.py", line 620, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting
[Open](https://github.com/unpaper/unpaper/pull/148)
2

Uncommit

Split

[Merged](https://github.com/unpaper/unpaper/pull/147)

Goto

[Merged](https://github.com/unpaper/unpaper/pull/146)

Goto


Edit stack

Goto

Load more commits
sl pull
Traceback (most recent call last):
  File "static:sapling", line 64, in run
    from . import dispatch
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "static:sapling.dispatch", line 27, in <module>
    from . import (
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "static:sapling.cmdutil", line 29, in <module>
    from . import (
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "static:sapling.crecord", line 32, in <module>
    locale.setlocale(locale.LC_ALL, "")
  File "/usr/lib/python3.10/locale.py", line 620, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
Commit Info

But the locale.setlocale(locale.LC_ALL, "") should reasonably work. I can't imagine why it wouldn't.

@Flameeyes
Copy link
Contributor Author

I think I found something, but it might even be a VSCode/WSL problem, I'm not sure.

Most of the invocations of sl get an environment of LANG=C.UTF-8, which work just fine. But in some cases (usually coming back from sleep it seems, and possibly at first boot up), they have LANG=en_US.utf-8 — as far as I can tell this is only true for invocations for the Smartlog, other processes spawned by the VSCode server component don't seem to set it to anything but C.UTF-8 which is the default it seems.

When LANG=en_US.utf-8 is set, I can reproduce this:

(venv) flameeyes@Gamestation:~/env-vars$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/locale.py", line 620, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

@quark-zju
Copy link
Contributor

Thanks for the info! I think you can enable the locale in WSL via:

sudo sed -i "s/# en_US.UTF/en_US.UTF/" /etc/locale.gen
sudo locale-gen

The setlocale logic might be unnecessary. If so, we might want to remove it.

@Flameeyes
Copy link
Contributor Author

Yeah I'm unfortunately quite aware of the glibc locale generation, so that as a workaround would work.

But I also just found

LANG: 'en_US.utf-8', // make sure to use unicode if user hasn't set LANG themselves
which appears to be how en_US.utf-8 gets injected as a locale.

@Flameeyes Flameeyes changed the title VSCode/ISL integration sometimes shows "Not a valid repository" on WSL VSCode Extension overrides LANG settings unconditionally, leading to non-working Python locale Jan 20, 2024
@quark-zju
Copy link
Contributor

Thanks! I'll update the related logic to not assume en_US.utf-8 is valid.

@Flameeyes
Copy link
Contributor Author

I think the easiest would be to use C.UTF-8 which AFAIR is always present, as it doesn't require generating any locale.

Flameeyes added a commit to Flameeyes/sapling that referenced this issue Jan 20, 2024
glibc does not generate all combinations of locales by default, and Python
fails when requesting to enforce a locale that does not exist.

Since the extension is not caring for the translation chosen, but rather
only trying to enforce UTF-8 support, use the C.UTF-8 locale which is
guaranteed to exist as per https://www.gnu.org/software/libc/manual/html_node/Choosing-Locale.html

Fixes facebook#814 where VSCode would intermittently be unable to identify
a valid Sapling checkout and/or pull from a repository.
facebook-github-bot pushed a commit that referenced this issue Jan 22, 2024
Summary:
See #814.
The "en_US.UTF-8" locale is not always valid. WSL uses `C.UTF-8` locale.
Change the `LANG` environment calculation to:
- Respect users' LANG setting if it's already UTF-8.
- Fallback to `C.UTF-8` instead of `en_US.UTF-8`, which works in WSL.

Reviewed By: evangrayk

Differential Revision: D52927838

fbshipit-source-id: c9110437e00382bb84e50d6b141fe5d4ce69f813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants