[rb-general] patching python glob

Ximin Luo infinity0 at debian.org
Wed May 24 16:21:00 CEST 2017

Bernhard M. Wiedemann:
> I am thinking to propose to python upstream
> https://github.com/python/cpython/compare/master...distropatches:glob?expand=1
> which would make every call of glob.glob deliver (reproducible) sorted
> output.
> That would help a large number of existing projects
> to get reproducible builds like
> https://github.com/pytries/datrie/blob/master/setup.py#L10
> https://github.com/jonashaag/bjoern/blob/master/setup.py#L6
> https://github.com/scipy/scipy/blob/master/scipy/sparse/linalg/dsolve/setup.py#L28
> https://www.riverbankcomputing.com/pipermail/pyqt/2017-May/039214.html
> and also future ones.
> What do you think?

Contrary to what others were assuming, python's glob is *not* implemented in terms of the libc glob. You can verify this by reading the source code:


Python's glob is in fact not sorted, and using sorted() will do a locale-independent sort.

The libc glob is local-dependently sorted and you have to run it with LC_ALL=C.UTF-8 for reproducible results.

So, the patch seems fine to me. Though sorted(list(xx)) is redundant and you can just use sorted(xx) directly even if xx is a generator/iterator.


GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE

More information about the rb-general mailing list