Description: There are Python scripts for various purposes in LibreOffice: from UITests to wizards, SDK examples and other places. This task is defined to do static code checking on Python scripts to do cleanup and fix some errors as they are found. Pyflakes is a tool for checking Python files for various problems. It can be installed using pip: Pyflakes: A simple program which checks Python source files for errors https://github.com/PyCQA/pyflakes Some of the issues reported by Pyflakes are: * Unused imports * Unnecessary re-imports * Undefined variables * Name Shadowing * Syntax Errors And many other issues, some of them described here: https://github.com/PyCQA/pyflakes/issues?q=is%3Aissue+is%3Aclosed At first, you have to run pyflakes to find those issues, and then fix them one by one. If you go to a specific path, and invoke "pyflakes .", it will try finding Python scripts inside the current folder, and report the errors. Then, you have to fix them one by one. As an example, let's check a test inside "unotest" folder: $ pyflakes sw/qa/uitest/writer_tests7/tdf156900.py sw/qa/uitest/writer_tests7/tdf156900.py:18:13: local variable 'xToolkit' is assigned to but never used The output shows there are some unused local variable. To fix it, this line should be removed: xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit') Some unused imports must remain, if they are there to test if importing something is actually possible, and give error message if it is not. We have another issue for pyflakes, but it is specifically about finding unused imports in UITests: tdf#132293 - Run pyflakes on python uitest files to find unused imports https://bugs.documentfoundation.org/show_bug.cgi?id=132293 Therefore, if you are working on unused imports for UITests only, use the above issue instead. This new one is about all the other issues, and also Python scripts beyond UITests.
Chenxiong Qi committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/8b6e0dd9e47c20a79fd194f6d530d1c868911bda tdf#158803 Fix issues detected by pyflakes It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Bogdan B committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/f727a1bc203369dc33f912cbf9f0fc0e6bc67ec8 tdf#158803 Remove unused imports from desktop It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Bogdan B committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/605c2888786b02e34ab586aa462cc1e84843dad2 tdf#158803 Remove unused imports from bin It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Bogdan B committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/6e67802648356a00cdbe9e2e6770199e227a03cd tdf#158803 Remove unused imports from odk It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Bogdan B committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/4871de96cb5e31e5ab06cf97e02e09e0e04a4de8 tdf#158803 Remove unused imports from wizards It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/3f7923ebac4c87aa2966e6f19b506dfeda8fbdb8 tdf#158803 fix typo NotImplementedErrors -> NotImplementedError It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/8a92d296bee8ce3b010fab47c48d23f68c4b25a0 tdf#158803 filename is undefined, should be self.root It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/623ae0a44f55ca4bf6f99a0ea0e0dbe55a95ec67 tdf#158803 remove unused maths import It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/2db078c582fb254bc02322af41bda2a43dd91313 tdf#158803 statement ends with an unnessary semicolon It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/d305470db4fef3b497675c3f5067f74e8333c652 tdf#158803 unncessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/9f4e04b2582971759d2eabb142d4fb1293bf00cc tdf#158803 remove unused imports It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/845dbe38844d90d4313652a7b390f3715fce6d7e tdf#158803 remove unused imports It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/9d4844374395ecce6b2ff4f9a71b3c8dae23050a tdf#158803 remove some unused imports, unnecessary semicolons and related styling It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/21fc89c651a8adece2571bf2e9b25a3bf0cd4f61 tdf#158803 unncessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/b470044cbf116b825ca86c1b054aaaaea7647646 tdf#158803 test for membership should be 'not in' It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/9e424d98e5af9f6219398e02cb05c454471c237d tdf#158803 test for membership should be 'not in', unnecessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/84188d15656a8b309216d4eba2fc47787ebcdf3d tdf#158803 fix fstring It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/5e80aa818cae690c67361e85bd37124cec16c05e tdf#158803 test for membership should be 'not in', unnecessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/d4aef7fd04a1ee999b03194c01f4a792aa1846d8 tdf#158803 unncessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/07efbe8f0bb46bba81396d081c456a09c93f842a tdf#158803 colons missing for print statement, replacing basestring with str It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/12efa6c63c2bee0d74e378289dd43bbc58c01781 tdf#158803 remove unused path.convert_to_unix import It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/7397de2ec5f9f3c2b42861bbfb344c425ffba9ea tdf#158803 unnecessary semicolons It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
LeSasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/e347cff87bec2e8d802fb2dfb8abd3d7d94f8103 tdf#158803 remove unused imports It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Noel Grandin committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/147063f58c6b7898e659321f581ea9551305a574 Revert "tdf#158803 remove some unused imports, unnecessary semicolons and related styling" It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
(In reply to Hossein from comment #0) > Description: > There are Python scripts for various purposes in LibreOffice: from UITests > to wizards, SDK examples and other places. This task is defined to do static > code checking on Python scripts to do cleanup and fix some errors as they > are found. > > Pyflakes is a tool for checking Python files for various problems. It can be > installed using pip: > > Pyflakes: A simple program which checks Python source files for errors > https://github.com/PyCQA/pyflakes > > Some of the issues reported by Pyflakes are: > > * Unused imports > * Unnecessary re-imports > * Undefined variables > * Name Shadowing > * Syntax Errors > > And many other issues, some of them described here: > https://github.com/PyCQA/pyflakes/issues?q=is%3Aissue+is%3Aclosed > > At first, you have to run pyflakes to find those issues, and then fix them > one by one. If you go to a specific path, and invoke "pyflakes .", it will > try finding Python scripts inside the current folder, and report the errors. > Then, you have to fix them one by one. > > As an example, let's check a test inside "unotest" folder: > $ pyflakes sw/qa/uitest/writer_tests7/tdf156900.py > sw/qa/uitest/writer_tests7/tdf156900.py:18:13: local variable 'xToolkit' is > assigned to but never used > > The output shows there are some unused local variable. To fix it, this line > should be removed: > > xToolkit = > self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit') > > Some unused imports must remain, if they are there to test if importing > something is actually possible, and give error message if it is not. > > We have another issue for pyflakes, but it is specifically about finding > unused imports in UITests: > > tdf#132293 - Run pyflakes on python uitest files to find unused imports > https://bugs.documentfoundation.org/show_bug.cgi?id=132293 > > Therefore, if you are working on unused imports for UITests only, use the > above issue instead. This new one is about all the other issues, and also > Python scripts beyond UITests. I would propose even extending the scope of this issue and to fix issues raised by ruff: https://github.com/astral-sh/ruff ruff is a superset of multiple python linting tools and extremely fast. Even when I run it on the whole LibreOffice/core repo, it is finished checking almost instantaneously, whereas other tools such as pyflakes take quite a bit longer. This fast execution also makes ruff a good candidate to be included in the CI to make sure that these kinds of errors don't creep back into the code base.
Bogdan Buzea committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/5fa3abd3b28b7c30d015dc058f7719112003f51e tdf#158803 Remove unused imports from uitest It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
As a follow up on my previous comment about using ruff as a potential linter in the CI, it can also be used to format the python code uniformly (and checking that formatting is consistent with the standard in the CI as well). On the easy hacks page (https://wiki.documentfoundation.org/Development/EasyHacks) it is stated, that: > Please avoid larger reformatting of the code for the time being (except for the tasks listed below) - we're pondering auto/magic ways to do that mid- to long-term. Hence, I thought I would suggest this, as I have noticed that formatting in the different modules is quite inconsistent and in my opinion ruff (which can be quite nicely configured to fit the idiosyncratic needs of any given project) will be an excellent tool to ensure a consistent formatting standard.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/71f3be3bee2e8a07f85594c02a9b44627b219e95 tdf#158803 Remove E999: SyntaxError's and some other minor edits It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/52b08068c90875ec5fd55ddea5662695216611b2 tdf#158803 compilerplugins: remove semicolons; improve membership checks It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/f97944cca2f64ce8cdf1d001b6ba9c751047d45a tdf#158803 pyflakes F821: undefined name 'com' and remove bare except clauses It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/6138f19537e8fc8a1207e9f210dab4257d9c6c84 tdf#158803 F821: remove unused variables and unused imports in librelogo/ It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/6f9f643b6d7929423fc83fc7857ed70e140a96ed tdf#158803 F821: fix a number of undefined names and related issues in wizards/ It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/96ffaadbcd3010515b2465f7f87b599909db5913 tdf#158803 F821: xrange undefined, should be range in py3; remove some unused variables It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Ilmari Lauhakangas committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/4058ca814a794cc80a4ebb2089df95798b2de85e tdf#158803 related: remove unnecessary comments It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonard Sasse committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/14d15cf61437c144031d4e95e6e104a6f2969597 tdf#158803: F401 Remove unused imports. It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Evaggelou Panagiotis committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/2fec61240fed71923e5e2172e8536438df2a2432 tdf#158803 Fix issues detected by pyflakes It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.