From 2c3bf9471d779ea40112a3ae70eec40eaf57cf6f Mon Sep 17 00:00:00 2001 From: Ilmari Lauhakangas Date: Sat, 27 Jul 2024 18:01:30 +0300 Subject: [PATCH] odk, oox, pyuno: fix issues found by Ruff linter Change-Id: I79d56453877a10502768b522ca93da3990891c0b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171098 Tested-by: Jenkins Tested-by: Ilmari Lauhakangas Reviewed-by: Ilmari Lauhakangas --- .../Charts/python/ChartInCalc.py | 5 ---- oox/source/token/namespaces.py | 5 ++-- oox/source/token/properties.py | 5 ++-- pyuno/demo/biblioaccess.py | 4 +-- pyuno/demo/ooextract.py | 3 +- .../pytests/testcollections_XIndexAccess.py | 28 +++++++++---------- pyuno/source/loader/pythonloader.py | 14 +++++----- pyuno/source/officehelper.py | 13 +++++++-- 8 files changed, 41 insertions(+), 36 deletions(-) diff --git a/odk/examples/DevelopersGuide/Charts/python/ChartInCalc.py b/odk/examples/DevelopersGuide/Charts/python/ChartInCalc.py index 787cc2274020..141e939e1cf2 100644 --- a/odk/examples/DevelopersGuide/Charts/python/ChartInCalc.py +++ b/odk/examples/DevelopersGuide/Charts/python/ChartInCalc.py @@ -71,11 +71,6 @@ class ChartInCalc(object): def test_data_point_properties(self): # set properties for a single data point try: - # determine the maximum value of the first series - data_array = self._chart_document.getData() - data = data_array.getData() - max_value = max([data[i][1] for i in range(len(data))]) - # first parameter is the index of the point, the second one is the series point_prop = self._diagram.getDataPointProperties(0, 1) diff --git a/oox/source/token/namespaces.py b/oox/source/token/namespaces.py index 1244e88e857f..41df70a88274 100644 --- a/oox/source/token/namespaces.py +++ b/oox/source/token/namespaces.py @@ -15,7 +15,8 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -import sys, re +import sys +import re infile_name = sys.argv[1] id_out_name = sys.argv[2] @@ -69,7 +70,7 @@ shift = 16 idfile.write("const size_t NMSP_SHIFT = {};\n".format(shift)) -i = 1; +i = 1 for token in sorted(namespaces.keys()): idfile.write("const sal_Int32 NMSP_{} = {} << NMSP_SHIFT;\n".format(token, i)) cur_id = i << shift diff --git a/oox/source/token/properties.py b/oox/source/token/properties.py index 8f8bc437b358..93c82dc1111b 100644 --- a/oox/source/token/properties.py +++ b/oox/source/token/properties.py @@ -15,7 +15,8 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -import sys, re +import sys +import re infile_name = sys.argv[1] id_out_name = sys.argv[2] @@ -37,7 +38,7 @@ with open(infile_name) as infile: idfile = open(id_out_name, 'w') namefile = open(name_out_name, 'w') -i = 0; +i = 0 for token in sorted(props.keys()): idfile.write("const sal_Int32 {} = {};\n".format(props[token], i)) namefile.write("/* {} */ \"{}\",\n".format(i, token)) diff --git a/pyuno/demo/biblioaccess.py b/pyuno/demo/biblioaccess.py index 0e5d0b4c8071..5ad5a2625f01 100644 --- a/pyuno/demo/biblioaccess.py +++ b/pyuno/demo/biblioaccess.py @@ -37,7 +37,7 @@ def main(): rowset.CommandType = COMMAND rowset.Command = "SELECT IDENTIFIER, AUTHOR FROM biblio" - rowset.execute(); + rowset.execute() print("Identifier\tAuthor") @@ -46,7 +46,7 @@ def main(): while rowset.next(): print(rowset.getString(id) + "\t" + repr(rowset.getString(author))) - rowset.dispose(); + rowset.dispose() main() diff --git a/pyuno/demo/ooextract.py b/pyuno/demo/ooextract.py index 0aec00f43a47..e93b169a8273 100644 --- a/pyuno/demo/ooextract.py +++ b/pyuno/demo/ooextract.py @@ -17,7 +17,8 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -import getopt,sys +import getopt +import sys import uno from unohelper import Base,systemPathToFileUrl diff --git a/pyuno/qa/pytests/testcollections_XIndexAccess.py b/pyuno/qa/pytests/testcollections_XIndexAccess.py index 07c14c1b0942..6dd85e39af74 100644 --- a/pyuno/qa/pytests/testcollections_XIndexAccess.py +++ b/pyuno/qa/pytests/testcollections_XIndexAccess.py @@ -75,7 +75,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertEqual(0, count) - doc.close(True); + doc.close(True) # Tests syntax: # num = len(obj) # Number of elements @@ -94,7 +94,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertEqual(1, count) - doc.close(True); + doc.close(True) # Tests syntax: # val = obj[0] # Access by index @@ -119,7 +119,7 @@ class TestXIndexAccess(CollectionsTestBase): self.readValuesTestFixture(doc, 2, 1, 1) self.readValuesTestFixture(doc, 2, 2, IndexError) self.readValuesTestFixture(doc, 2, 3, IndexError) - doc.close(True); + doc.close(True) def test_XIndexAccess_ReadIndex_Single_Invalid(self): doc = self.createBlankTextDocument() @@ -129,7 +129,7 @@ class TestXIndexAccess(CollectionsTestBase): self.readValuesTestFixture(doc, 0, (0, 1), TypeError) self.readValuesTestFixture(doc, 0, [0, 1], TypeError) self.readValuesTestFixture(doc, 0, {'a': 'b'}, TypeError) - doc.close(True); + doc.close(True) # Tests syntax: # val1,val2 = obj[2:4] # Access by slice @@ -143,7 +143,7 @@ class TestXIndexAccess(CollectionsTestBase): key = slice(j, k) expected = t[key] self.readValuesTestFixture(doc, i, key, expected) - doc.close(True); + doc.close(True) # Tests syntax: # val1,val2 = obj[0:3:2] # Access by extended slice @@ -158,7 +158,7 @@ class TestXIndexAccess(CollectionsTestBase): key = slice(j, k, l) expected = t[key] self.readValuesTestFixture(doc, i, key, expected) - doc.close(True); + doc.close(True) # Tests syntax: # if val in obj: ... # Test value presence @@ -179,7 +179,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertTrue(present) - doc.close(True); + doc.close(True) # Tests syntax: # if val in obj: ... # Test value presence @@ -195,7 +195,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertFalse(present) - doc.close(True); + doc.close(True) # Tests syntax: # if val in obj: ... # Test value presence @@ -211,7 +211,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertFalse(present) - doc.close(True); + doc.close(True) # Tests syntax: # if val in obj: ... # Test value presence @@ -225,7 +225,7 @@ class TestXIndexAccess(CollectionsTestBase): with self.assertRaises(TypeError): _ = {} in doc.Footnotes - doc.close(True); + doc.close(True) # Tests syntax: # for val in obj: ... # Implicit iterator (values) @@ -243,7 +243,7 @@ class TestXIndexAccess(CollectionsTestBase): # Then self.assertEqual(0, len(read_footnotes)) - doc.close(True); + doc.close(True) # Tests syntax: # for val in obj: ... # Implicit iterator (values) @@ -266,7 +266,7 @@ class TestXIndexAccess(CollectionsTestBase): self.assertEqual(1, len(read_footnotes)) self.assertEqual('foo', read_footnotes[0].Label) - doc.close(True); + doc.close(True) # Tests syntax: # for val in obj: ... # Implicit iterator (values) @@ -293,7 +293,7 @@ class TestXIndexAccess(CollectionsTestBase): self.assertEqual('foo', read_footnotes[0].Label) self.assertEqual('bar', read_footnotes[1].Label) - doc.close(True); + doc.close(True) # Tests syntax: # itr = iter(obj) # Named iterator (values) @@ -315,7 +315,7 @@ class TestXIndexAccess(CollectionsTestBase): with self.assertRaises(StopIteration): next(itr) - doc.close(True); + doc.close(True) if __name__ == '__main__': diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py index 02f901942cbb..bd389d438a5d 100644 --- a/pyuno/source/loader/pythonloader.py +++ b/pyuno/source/loader/pythonloader.py @@ -40,16 +40,16 @@ def splitUrl( url ): g_loadedComponents = {} def checkForPythonPathBesideComponent( url ): - path = unohelper.fileUrlToSystemPath( url+"/pythonpath.zip" ); + path = unohelper.fileUrlToSystemPath( url+"/pythonpath.zip" ) if DEBUG == 1: print(b"checking for existence of " + encfile( path )) - if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path: + if 1 == os.access( encfile( path ), os.F_OK) and path not in sys.path: if DEBUG == 1: print(b"adding " + encfile( path ) + b" to sys.path") sys.path.append( path ) - path = unohelper.fileUrlToSystemPath( url+"/pythonpath" ); - if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path: + path = unohelper.fileUrlToSystemPath( url+"/pythonpath" ) + if 1 == os.access( encfile( path ), os.F_OK) and path not in sys.path: if DEBUG == 1: print(b"adding " + encfile( path ) + b" to sys.path") sys.path.append( path ) @@ -107,7 +107,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ): if -1 != nSlash: path = unohelper.fileUrlToSystemPath( dependent[0:nSlash] ) dependent = dependent[nSlash+1:len(dependent)] - if not path in sys.path: + if path not in sys.path: sys.path.append( path ) mod = __import__( dependent ) path_component, dot, rest = dependent.partition('.') @@ -117,13 +117,13 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ): return mod else: if DEBUG: - print("Unknown protocol '" + protocol + "'"); + print("Unknown protocol '" + protocol + "'") raise RuntimeException( "PythonLoader: Unknown protocol " + protocol + " in url " +url, self ) except Exception as e: if DEBUG: print ("Python import exception " + str(type(e)) + - " message " + str(e) + " args " + str(e.args)); + " message " + str(e) + " args " + str(e.args)) raise RuntimeException( "Couldn't load " + url + " for reason " + str(e), None ) return None diff --git a/pyuno/source/officehelper.py b/pyuno/source/officehelper.py index 882d0f65531f..db32e2c80bd2 100644 --- a/pyuno/source/officehelper.py +++ b/pyuno/source/officehelper.py @@ -49,9 +49,16 @@ warning:: Tested platforms are Linux, Mac OS X & Windows :References: .. _ActiveState retry Python decorator: http://code.activestate.com/recipes/580745-retry-decorator-in-python/ """ -import os, random, signal, subprocess # in bootstrap() -from sys import platform # in bootstrap() -import itertools, time # in retry() decorator +# in bootstrap() +import os +import random +import signal +import subprocess +from sys import platform +# in retry() decorator +import itertools +import time + import uno from com.sun.star.connection import NoConnectException from com.sun.star.uno import Exception as UnoException