[Python-checkins] bpo-31920: Fixed handling directories as arguments in the ``pygettext`` script. (GH-6259)
Miss Islington (bot)
webhook-mailer at python.org
Mon Apr 9 14:06:12 EDT 2018
https://github.com/python/cpython/commit/e0dbc57e116516f6ca1ef021f71e1a98773d57ed
commit: e0dbc57e116516f6ca1ef021f71e1a98773d57ed
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-04-09T11:06:09-07:00
summary:
bpo-31920: Fixed handling directories as arguments in the ``pygettext`` script. (GH-6259)
Based on patch by Oleg Krasnikov.
(cherry picked from commit c93938b5beea4c3f592119ebee6d4029558db8de)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
A Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
M Lib/test/test_tools/test_i18n.py
M Misc/ACKS
M Tools/i18n/pygettext.py
diff --git a/Lib/test/test_tools/test_i18n.py b/Lib/test/test_tools/test_i18n.py
index 5e7c4bffccde..ade304c0f1ee 100644
--- a/Lib/test/test_tools/test_i18n.py
+++ b/Lib/test/test_tools/test_i18n.py
@@ -6,7 +6,7 @@
from test.support.script_helper import assert_python_ok
from test.test_tools import skip_if_missing, toolsdir
-from test.support import temp_cwd
+from test.support import temp_cwd, temp_dir
skip_if_missing()
@@ -158,3 +158,27 @@ class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
"""doc"""
'''))
self.assertIn('doc', msgids)
+
+ def test_files_list(self):
+ """Make sure the directories are inspected for source files
+ bpo-31920
+ """
+ text1 = 'Text to translate1'
+ text2 = 'Text to translate2'
+ text3 = 'Text to ignore'
+ with temp_cwd(None), temp_dir(None) as sdir:
+ os.mkdir(os.path.join(sdir, 'pypkg'))
+ with open(os.path.join(sdir, 'pypkg', 'pymod.py'), 'w') as sfile:
+ sfile.write(f'_({text1!r})')
+ os.mkdir(os.path.join(sdir, 'pkg.py'))
+ with open(os.path.join(sdir, 'pkg.py', 'pymod2.py'), 'w') as sfile:
+ sfile.write(f'_({text2!r})')
+ os.mkdir(os.path.join(sdir, 'CVS'))
+ with open(os.path.join(sdir, 'CVS', 'pymod3.py'), 'w') as sfile:
+ sfile.write(f'_({text3!r})')
+ assert_python_ok(self.script, sdir)
+ with open('messages.pot') as fp:
+ data = fp.read()
+ self.assertIn(f'msgid "{text1}"', data)
+ self.assertIn(f'msgid "{text2}"', data)
+ self.assertNotIn(text3, data)
diff --git a/Misc/ACKS b/Misc/ACKS
index 7eaee80727dc..8e250f7bb001 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -835,6 +835,7 @@ Maksim Kozyarchuk
Stefan Krah
Rolf Krahl
Bob Kras
+Oleg Krasnikov
Sebastian Kreft
Holger Krekel
Michael Kremer
diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst b/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
new file mode 100644
index 000000000000..39c694b0728d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
@@ -0,0 +1,2 @@
+Fixed handling directories as arguments in the ``pygettext`` script. Based
+on patch by Oleg Krasnikov.
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index 0f0395a4fcab..13d7a649aec4 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -259,24 +259,6 @@ def containsAny(str, set):
return 1 in [c in str for c in set]
-def _visit_pyfiles(list, dirname, names):
- """Helper for getFilesForName()."""
- # get extension for python source files
- if '_py_ext' not in globals():
- global _py_ext
- _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
-
- # don't recurse into CVS directories
- if 'CVS' in names:
- names.remove('CVS')
-
- # add all *.py files to list
- list.extend(
- [os.path.join(dirname, file) for file in names
- if os.path.splitext(file)[1] == _py_ext]
- )
-
-
def getFilesForName(name):
"""Get a list of module files for a filename, a module or package name,
or a directory.
@@ -302,7 +284,17 @@ def getFilesForName(name):
if os.path.isdir(name):
# find all python files in directory
list = []
- os.walk(name, _visit_pyfiles, list)
+ # get extension for python source files
+ _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
+ for root, dirs, files in os.walk(name):
+ # don't recurse into CVS directories
+ if 'CVS' in dirs:
+ dirs.remove('CVS')
+ # add all *.py files to list
+ list.extend(
+ [os.path.join(root, file) for file in files
+ if os.path.splitext(file)[1] == _py_ext]
+ )
return list
elif os.path.exists(name):
# a single file
More information about the Python-checkins
mailing list