[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-i18n-doc
Subject: Re: [Patch] Remove trailing whitespace from translated json files
From: Elvis Angelaccio <elvis.angelaccio () kde ! org>
Date: 2017-03-30 10:53:18
Message-ID: CALN1cnubnr5+atLR90y82zGyAAP+sNPswOb8k4JPE5RiTiEZMg () mail ! gmail ! com
[Download RAW message or body]
On Thu, Mar 30, 2017 at 12:51 PM, Elvis Angelaccio
<elvis.angelaccio@kde.org> wrote:
> On Thu, Mar 30, 2017 at 1:08 AM, Luigi Toscano <luigi.toscano@tiscali.it> wrote:
>> Elvis Angelaccio ha scritto:
>>> Scripty adds trailing whitespace when committing translations to json
>>> files. This is annoying because the git diff output is polluted with
>>> visual warnings.
>>>
>>> According to [1], python2 adds trailing whitespace when json.dumps has
>>> the indent parameter set. The same page also suggests the fix for
>>> this, which is what you can find in the attached patch.
>>>
>>
>> Uhm, I would trust the python documentation (the behavior with python 3 seems
>> a bit different; not a concert now and you may want to add a comment before
>> the line as reminder to revisit this when it will be important).
>>
>> I would say: wait for the tagging of the next Frameworks and commit it to
>> trunk/l10n-kf5/scripts, and let's see.
>
> Right, it seems python >= 3.4 behaves properly. I added a comment in
> the patch, will commit next week :)
Sorry, forgot to attach it...
>
>>
>> --
>> Luigi
["trailing-whitespace.patch" (text/x-patch)]
Index: filljsonfrompo.py
===================================================================
--- filljsonfrompo.py (revision 1486313)
+++ filljsonfrompo.py (working copy)
@@ -130,7 +130,10 @@
# verbosePrint('final result:\n "%s"\n\n' % (pprint.pformat(jsondata)))
with io.open(jsonfilename, 'w', encoding='utf-8') as data_file:
- output = json.dumps(jsondata, sort_keys=True, indent=4, ensure_ascii=False)
+ # python2 adds trailing whitespace if the indent parameter is set.
+ # To prevent this behavior we use custom separators.
+ # TODO: this won't be necessary anymore with python >= 3.4
+ output = json.dumps(jsondata, sort_keys=True, indent=4, separators=(',', ': \
'), ensure_ascii=False) output += '\n'
data_file.write(output)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic