Skip to content

pkgsMusl.python27Packages.Babel tests fail with unicode error #74904

Closed

Description

@nh2

Issue description

Building pkgsMusl.python27Packages.Babel on latest master fails for me with:

ERROR: test_abort_invalid_po_file (tests.messages.test_pofile.ReadPoTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/Babel-2.7.0/tests/messages/test_pofile.py", line 458, in test_abort_invalid_po_file
    output = pofile.read_po(buf, locale='fr', abort_invalid=False)
  File "/build/Babel-2.7.0/babel/messages/pofile.py", line 377, in read_po
    parser.parse(fileobj)
  File "/build/Babel-2.7.0/babel/messages/pofile.py", line 310, in parse
    self._process_message_line(lineno, line)
  File "/build/Babel-2.7.0/babel/messages/pofile.py", line 210, in _process_message_line
    self._process_keyword_line(lineno, line, obsolete)
  File "/build/Babel-2.7.0/babel/messages/pofile.py", line 222, in _process_keyword_line
    self._invalid_pofile(line, lineno, "Start of line didn't match any expected keyword.")
  File "/build/Babel-2.7.0/babel/messages/pofile.py", line 325, in _invalid_pofile
    print(u"WARNING: Problem on line {0}: {1}".format(lineno + 1, line))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 84: ordinal not in range(128)

----------------------------------------------------------------------
Ran 253 tests in 0.432s

FAILED (errors=1)

Relevant code:

checkInputs = [ pytest freezegun glibcLocales ];
doCheck = !stdenv.isDarwin;
preCheck = ''
export LC_ALL="en_US.UTF-8"
'';

I think libcLocales is not necessary for musl (see also #43666), but I haven't managed to make that test not fail.

Do locales with Python have to be handled differently with musl somehow?

CC @dtzWill

Activity

  1. dtzWill commented on Dec 3, 2019

    @dtzWill
    Member

    Dropping glibcLocales and the preCheck might be a good idea anyway-- looks like they might not be needed on glibc, at least it seems fine when dropping them locally.

    I don't have the deps for this handy (using musl), but the usual fix is to drop glibcLocales if possible (or conditionally include it if needed). Right now I'm not remembering why pulling in glibcLocales breaks things (instead of simply being unnecessary), but it's easy enough to test regardless ;).

    Can you try dropping glibcLocales and the preCheck, see if that helps or changes things?


    FWIW now that we include C.UTF-8 locale in glibc, that's almost always better for things like "generic UTF-8 locale for testing" and avoids hardcoding en_US... all without needing to pull in glibcLocales for sake of a reasonable locale.

    Treewide cleanup of en_US.UTF-8 (and glibcLocales when it is only pulled in to provide that locale) might be a good idea.

  2. nh2 commented on Dec 15, 2019

    @nh2
    ContributorAuthor

    For me it looks like glibcLocales are needed with glibc (normal python27Packages.Babel) -- but not with Python 3, and Python 3 also works with musl without problems.

    So it seems to be a Python 2 problem, not a musl problem. I'll make a PR.

  3. nh2 commented on Dec 15, 2019

    @nh2
    ContributorAuthor

    PR at #75676.

  4. added a commit that references this issue on Dec 15, 2019
    9cfb480
  5. jtojnar commented on Dec 15, 2019

    @jtojnar
    Member

    I think the issue might come from the fact that Python 3 defaults to C.UTF-8, whereas Python 2 to en_US.UTF-8 or something. See #20192 (comment)

    Dropping glibcLocales and setting the locale to C.UTF-8 for Python 2 might fix it.

  6. nh2 commented on Dec 16, 2019

    @nh2
    ContributorAuthor

    Dropping glibcLocales and setting the locale to C.UTF-8 for Python 2 might fix it.

    @jtojnar This does not suffice for me; with this diff on top of #75676

    % git --no-pager diff 
    diff --git a/pkgs/development/python-modules/Babel/default.nix b/pkgs/development/python-modules/Babel/default.nix
    index 7aa743c06b2..8df9bdcf8da 100644
    --- a/pkgs/development/python-modules/Babel/default.nix
    +++ b/pkgs/development/python-modules/Babel/default.nix
    @@ -15,13 +15,17 @@ buildPythonPackage rec {
         # Without this, tests fail with a unicode error on Python < 3
         # (checked with 2.7) if glibc is used, see:
         # https://github.com/NixOS/nixpkgs/issues/74904
    -    ++ lib.optionals (!isPy3k && stdenv.hostPlatform.libc == "glibc") [ glibcLocales ];
    +    ;
     
       doCheck = !stdenv.isDarwin
         # Test failure on musl when Python < 3 (checked with 2.7) is used:
         # https://github.com/NixOS/nixpkgs/issues/74904 (like above).
         && !(stdenv.hostPlatform.isMusl && !isPy3k);
     
    +  preCheck = ''
    +    export LC_ALL="C.UTF-8"
    +  '';
    +
       meta = with lib; {
         homepage = http://babel.edgewall.org;
         description = "A collection of tools for internationalizing Python applications";

    (or commit at nh2@fdf5da6) it still fails with the error on python27Packages.Babel. So it seems glibcLocales is needed on Python 2.7 with glibc.

  7. added 2 commits that reference this issue on Dec 16, 2019
    dad0586
    fdf5da6
  8. FRidh commented on Dec 30, 2019

    @FRidh
    Member

    I pushed d64a456aad9b11628837817d1a64420816bdafcc to python-unstable which hopefully lands in the new staging-next today. Note I did not test with Musl. I could imagine we would need a change in buildPythonPackage instead.

  9. nh2 commented on Jan 28, 2020

    @nh2
    ContributorAuthor

    Not actually musl related, see #75676 (comment).

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions