Skip to content

Commit

Permalink
[python] Sort generated output for reproducibility
Browse files Browse the repository at this point in the history
Sort the list of languages and imports - previously these would come
out in whatever order the filing system reported the directory entries
in.
  • Loading branch information
ojwb committed May 30, 2018
1 parent e4f1564 commit 27ff572
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Expand Up @@ -246,7 +246,7 @@ $(python_output_dir)/%_stemmer.py: algorithms/%.sbl snowball
echo "./snowball $< -py -o $${o} -p BaseStemmer"; \
./snowball $< -py -o $${o} -p BaseStemmer

$(python_output_dir)/__init__.py:
$(python_output_dir)/__init__.py: libstemmer/modules.txt
@mkdir -p $(python_output_dir)
$(python) python/create_init.py $(python_output_dir)

Expand Down
8 changes: 6 additions & 2 deletions python/create_init.py
Expand Up @@ -9,7 +9,7 @@
filematch = re.compile(r"(\w+)_stemmer\.py$")

imports = []
languages = ['_languages = {']
languages = []

for pyscript in os.listdir(python_out_folder):
match = filematch.match(pyscript)
Expand All @@ -18,12 +18,16 @@
titlecase = langname.title()
languages.append(" '%(lang)s': %(title)sStemmer," % {'lang': langname, 'title': titlecase})
imports.append('from .%(lang)s_stemmer import %(title)sStemmer' % {'lang': langname, 'title': titlecase})
languages.append('}');
imports.sort()
languages.sort()

src = '''__all__ = ('language', 'stemmer')
%(imports)s
_languages = {
%(languages)s
}
try:
import Stemmer
Expand Down

0 comments on commit 27ff572

Please sign in to comment.