Fix Python argparse.FileType deprecation warning

...seen at least with --with-system-python against
python3-3.14.0~rc3-1.fc43.x86_64, causing

> [PRL] CustomTarget/postprocess/images/sorted.lst
> Traceback (most recent call last):
>   File "/home/sberg/lo-plain/core/solenv/bin/image-sort.py", line 130, in <module>
>     parser.add_argument('output', metavar='output file', type=argparse.FileType('w'),
>                                                               ~~~~~~~~~~~~~~~~~^^^^^
>   File "/usr/lib64/python3.14/argparse.py", line 1356, in __init__
>     warnings.warn(
>     ~~~~~~~~~~~~~^
>         "FileType is deprecated. Simply open files after parsing arguments.",
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>         category=PendingDeprecationWarning,
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>         stacklevel=2
>         ^^^^^^^^^^^^
>     )
>     ^
> PendingDeprecationWarning: FileType is deprecated. Simply open files after parsing arguments.
> make[1]: *** [/home/sberg/lo-plain/core/postprocess/CustomTarget_images.mk:124: /home/sberg/lo-plain/core/workdir/CustomTarget/postprocess/images/sorted.lst] Error 1

to fail

Change-Id: I1dbebabb494f90698436dada6cd8e16ba98c1ea1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191354
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@collabora.com>
This commit is contained in:
Stephan Bergmann
2025-09-22 17:27:24 +02:00
parent c5c8e28959
commit 6ebe4cb27a
+6 -5
View File
@@ -127,7 +127,7 @@ parser.add_argument('control_file', metavar='image-sort.lst',
# where the uiconfigs live
parser.add_argument('base_path', metavar='directory',
help='path to the UIConfigs directory')
parser.add_argument('output', metavar='output file', type=argparse.FileType('w'),
parser.add_argument('output', metavar='output file',
nargs='?', default=None, help='optionally write to this output file')
parser.add_argument("-q", "--quiet", action="store_true",
help="don't print status messages to stdout")
@@ -135,9 +135,10 @@ parser.add_argument("-q", "--quiet", action="store_true",
args = parser.parse_args()
if args.output is not None:
output = open(args.output, mode = 'w')
close_output = True
else:
args.output = sys.stdout
output = sys.stdout
close_output = False
with open(args.control_file) as cf:
@@ -145,13 +146,13 @@ with open(args.control_file) as cf:
for icon in global_list:
if not icon.startswith('sc_'):
args.output.write(icon + "\n")
output.write(icon + "\n")
for icon in global_list:
if icon.startswith('sc_'):
args.output.write(icon + "\n")
output.write(icon + "\n")
if close_output:
args.output.close()
output.close()
# dnl vim:set shiftwidth=4 softtabstop=4 expandtab: