Skip to content

Commit 5f55f48

Browse files
commit
1 parent bd2e5f0 commit 5f55f48

File tree

7 files changed

+42
-25
lines changed

7 files changed

+42
-25
lines changed

Lib/test/test_tools/i18n_data/messages.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ msgid ""
3333
" multiline!\n"
3434
msgstr ""
3535

36-
#: messages.py:46 messages.py:89 messages.py:90 messages.py:93 messages.py:94
37-
#: messages.py:99 messages.py:100 messages.py:101
36+
#: messages.py:46 messages.py:92 messages.py:93 messages.py:96 messages.py:97
37+
#: messages.py:102 messages.py:103 messages.py:104
3838
msgid "foo"
3939
msgid_plural "foos"
4040
msgstr[0] ""
@@ -80,18 +80,18 @@ msgstr ""
8080
msgid "default value"
8181
msgstr ""
8282

83-
#: messages.py:91 messages.py:92 messages.py:95 messages.py:96
83+
#: messages.py:94 messages.py:95 messages.py:98 messages.py:99
8484
msgctxt "context"
8585
msgid "foo"
8686
msgid_plural "foos"
8787
msgstr[0] ""
8888
msgstr[1] ""
8989

90-
#: messages.py:102
90+
#: messages.py:105
9191
msgid "domain foo"
9292
msgstr ""
9393

94-
#: messages.py:118 messages.py:119
94+
#: messages.py:121 messages.py:122
9595
msgid "world"
9696
msgid_plural "worlds"
9797
msgstr[0] ""

Lib/test/test_tools/i18n_data/messages.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def _(x="don't extract me"):
8585
pass
8686

8787

88+
def func():
89+
"""Docstring..."""
90+
8891
# Other gettext functions
8992
gettext("foo")
9093
ngettext("foo", "foos", 1)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def test(x):
2+
"""'I think he’s had a heart attack!'
3+
'IF THERE’S ONE THING I CAN’T STAND IS PEOPLE HAVING HEART ATTACKS!!!'
4+
'I’m fine, now!'
5+
'Good. Now we’re getting somewhere.'
6+
"""
7+
8+
class Foo:
9+
"""Docstring"""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fileloc.py
2+
3+
skipdocstrings.py
4+
messages.py
5+
messages.py

Lib/test/test_tools/test_i18n.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def extract_from_snapshots():
589589
'messages.py': (),
590590
'fileloc.py': ('--docstrings',),
591591
'docstrings.py': ('--docstrings',),
592+
('docstrings.py', 'skipdocstrings.py', 'docstrings.pot'): ('--docstrings', f'--no-docstrings={DATA_DIR}{os.path.sep}skipdocstrings.txt'),
592593
'comments.py': ('--add-comments=i18n:',),
593594
'custom_keywords.py': ('--keyword=foo', '--keyword=nfoo:1,2',
594595
'--keyword=pfoo:1c,2',
@@ -606,18 +607,20 @@ def extract_from_snapshots():
606607

607608
for filename, args in snapshots.items():
608609
if isinstance(filename, tuple):
609-
filename, output_file = filename
610+
*filenames, output_file = filename
610611
output_file = DATA_DIR / output_file
611-
input_file = DATA_DIR / filename
612+
input_files = [DATA_DIR / file for file in filenames]
612613
else:
613-
input_file = DATA_DIR / filename
614-
output_file = input_file.with_suffix('.pot')
615-
contents = input_file.read_bytes()
614+
input_files = [DATA_DIR / filename]
615+
output_file = input_files[0].with_suffix('.pot')
616+
616617
with temp_cwd(None):
617-
Path(input_file.name).write_bytes(contents)
618+
for input_file in input_files:
619+
contents = input_file.read_bytes()
620+
Path(input_file.name).write_bytes(contents)
618621
assert_python_ok('-Xutf8', Test_pygettext.script, *args,
619-
input_file.name)
620-
yield (input_file, output_file,
622+
*[file.name for file in input_files])
623+
yield (input_files, output_file,
621624
Path('messages.pot').read_text(encoding='utf-8'))
622625

623626

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix and test the ``--no-docstrings`` option in :program:`pygettext`.

Tools/i18n/pygettext.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def visit_Call(self, node):
483483

484484
def _extract_docstring(self, node):
485485
if (not self.options.docstrings or
486-
self.options.nodocstrings.get(self.filename)):
486+
os.path.basename(self.filename) in self.options.nodocstrings):
487487
return
488488

489489
docstring = ast.get_docstring(node)
@@ -692,7 +692,7 @@ def main():
692692
'help', 'keyword=', 'no-default-keywords',
693693
'add-location', 'no-location', 'output=', 'output-dir=',
694694
'style=', 'verbose', 'version', 'width=', 'exclude-file=',
695-
'docstrings', 'no-docstrings',
695+
'docstrings', 'no-docstrings=',
696696
])
697697
except getopt.error as msg:
698698
usage(1, msg)
@@ -714,7 +714,7 @@ class Options:
714714
width = 78
715715
excludefilename = ''
716716
docstrings = 0
717-
nodocstrings = {}
717+
nodocstrings = []
718718
comment_tags = set()
719719

720720
options = Options()
@@ -767,15 +767,11 @@ class Options:
767767
elif opt in ('-x', '--exclude-file'):
768768
options.excludefilename = arg
769769
elif opt in ('-X', '--no-docstrings'):
770-
fp = open(arg)
771-
try:
772-
while 1:
773-
line = fp.readline()
774-
if not line:
775-
break
776-
options.nodocstrings[line[:-1]] = 1
777-
finally:
778-
fp.close()
770+
with open(arg, 'r') as nodocstrings_file:
771+
for line in nodocstrings_file:
772+
filename = os.path.basename(line.strip())
773+
if filename not in options.nodocstrings:
774+
options.nodocstrings.append(filename)
779775

780776
options.comment_tags = tuple(options.comment_tags)
781777

0 commit comments

Comments
 (0)