pylint as part of build ?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
reox
Posts: 874
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: pylint as part of build ?

Post by reox » Sun Jul 07, 2019 3:53 pm

What you could also do: there are tools for github which check the code style and can disable merging if the code style does not match.
That is the easiest solution to force everyone to write in the same style.

There seems to be also tools which will create new commits with linted code.
mlampert
Posts: 1463
Joined: Fri Sep 16, 2016 9:28 pm

Re: pylint as part of build ?

Post by mlampert » Sun Jul 07, 2019 7:40 pm

All these are great solutions and suggestions. In truth though I'm not that much concerned about _style_ (as in there must be a space ...), what I really would like to catch are bugs, or potential bugs. Basically what a compiler/linker does for C++, making sure that all the code that can be exercised is at least syntactically correct and free of typos - the latter being a vivid companion of mine.

AFAICT there are two options, lgtm or pylint. lgtm's integration into github's PR system is a brand new feature and currently being explored elsewhere or use pylint locally and run it as part of the unit tests.

TBH I do not advocate shipping pylint with FC - every developer on *nix can install it quite easily and the same is true for Windows. If the build for your PR fails you can install it if the logs from the build aren't conclusive, but that is not a requirement - or it shouldn't be.
User avatar
vanuan
Posts: 152
Joined: Wed Oct 24, 2018 9:49 pm

Re: pylint as part of build ?

Post by vanuan » Sun Aug 02, 2020 7:39 pm

Has anyone actually tried to run it?

P.S. Please move this to Developers corner.
User avatar
vanuan
Posts: 152
Joined: Wed Oct 24, 2018 9:49 pm

Re: pylint as part of build ?

Post by vanuan » Sun Aug 02, 2020 7:42 pm

User avatar
vanuan
Posts: 152
Joined: Wed Oct 24, 2018 9:49 pm

Re: pylint as part of build ?

Post by vanuan » Sun Aug 02, 2020 9:01 pm

saso wrote:
Thu Jul 04, 2019 8:00 am
Is flake8 that we are already running basically not the same thing ? https://travis-ci.org/FreeCAD/FreeCAD/jobs/554080767
Apparently, flake8 doesn't verify signatures. It only verifies syntax and formatting. So if you import a module which doesn't exist or call a module without importing it, it won't complain. Pylint, OTOH will throw an error if you use a function or module incorrectly.

Still, flake8 is useful if you want to enforce snake_case naming. For that, you just need to install pep8-naming.
User avatar
vanuan
Posts: 152
Joined: Wed Oct 24, 2018 9:49 pm

Re: pylint as part of build ?

Post by vanuan » Sun Aug 02, 2020 11:04 pm

Among other options are mypy and pyright. Those better support python stubs (pyi) which are required for C++ modules.
User avatar
vanuan
Posts: 152
Joined: Wed Oct 24, 2018 9:49 pm

Re: pylint as part of build ?

Post by vanuan » Mon Aug 03, 2020 6:14 am

Ok, here's a proof of concept to enforce snake_case in just one file (src/Mod/Draft/draftguitools/gui_snapper.py):
https://github.com/FreeCAD/FreeCAD/pull/3772

Code: Select all

src/python-stubs/BimProject/__init__.pyi:1:6: N802 function name 'getHuman' should be lowercase
src/python-stubs/ArchSketchObject/__init__.py:3:6: N802 function name 'sortSketchWidth' should be lowercase
src/python-stubs/ArchSketchObject/__init__.py:3:30: N803 argument name 'edgeAlignList' should be lowercase
src/python-stubs/pivy/coin/__init__.pyi:1:6: N802 function name 'SoMaterial' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:7:6: N802 function name 'activateWorkbench' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:8:6: N802 function name 'addWorkbench' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:9:6: N802 function name 'removeWorkbench' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:10:6: N802 function name 'getWorkbench' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:11:6: N802 function name 'listWorkbenches' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:12:6: N802 function name 'activeWorkbench' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:13:6: N802 function name 'addResourcePath' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:14:6: N802 function name 'addLanguagePath' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:15:6: N802 function name 'addIconPath' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:16:6: N802 function name 'addIcon' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:17:6: N802 function name 'getIcon' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:18:6: N802 function name 'isIconCached' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:19:6: N802 function name 'getMainWindow' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:20:6: N802 function name 'updateGui' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:21:6: N802 function name 'updateLocale' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:22:6: N802 function name 'getLocale' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:23:6: N802 function name 'setLocale' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:24:6: N802 function name 'supportedLocales' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:25:6: N802 function name 'createDialog' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:26:6: N802 function name 'addCommand' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:26:28: N803 argument name 'commandObject' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:27:6: N802 function name 'runCommand' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:28:6: N802 function name 'SendMsgToActiveView' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:29:6: N802 function name 'sendMsgToFocusView' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:32:6: N802 function name 'hideObject' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:33:6: N802 function name 'showObject' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:37:6: N802 function name 'activeDocument' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:38:6: N802 function name 'activeView' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:39:6: N802 function name 'activateView' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:40:6: N802 function name 'editDocument' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:41:6: N802 function name 'getDocument' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:42:6: N802 function name 'doCommand' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:43:6: N802 function name 'doCommandGui' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:44:6: N802 function name 'addModule' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:45:6: N802 function name 'showDownloads' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:46:6: N802 function name 'showPreferences' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:47:6: N802 function name 'createViewer' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:48:6: N802 function name 'getMarkerIndex' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:49:6: N802 function name 'addDocumentObserver' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:50:6: N802 function name 'removeDocumentObserver' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:52:6: N802 function name 'loadFile' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:53:6: N802 function name 'coinRemoveAllChildren' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:56:10: N802 function name 'GetCommands' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:59:10: N802 function name 'GetResources' should be lowercase
src/python-stubs/FreeCADGui/__init__.pyi:64:2: N816 variable 'draftToolBar' in global scope should not be mixedCase
src/python-stubs/FreeCAD/__init__.pyi:6:2: N816 variable 'activeDraftCommand' in global scope should not be mixedCase
src/python-stubs/FreeCAD/__init__.pyi:9:6: N802 function name 'ParamGet' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:13:6: N802 function name 'saveParameter' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:17:6: N802 function name 'Version' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:19:6: N802 function name 'Vector' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:21:6: N802 function name 'Units' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:23:6: N802 function name 'getResourceDir' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:24:6: N802 function name 'getUserAppDataDir' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:27:10: N802 function name 'GetString' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:28:10: N802 function name 'GetInt' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:29:10: N802 function name 'GetFloat' should be lowercase
src/python-stubs/FreeCAD/__init__.pyi:30:10: N802 function name 'GetBool' should be lowercase
Next steps: provide snake_case aliases for all the internal C++ modules, add ignore pragmas for third-party modules, add deprecation warnings for camelCase versions, get everything to use snake_case.
User avatar
PrzemoF
Posts: 3027
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: pylint as part of build ?

Post by PrzemoF » Mon Aug 03, 2020 6:42 pm

vanuan wrote:
Sun Aug 02, 2020 7:39 pm
Has anyone actually tried to run it?

P.S. Please move this to Developers corner.
Moved
Post Reply

Who is online

Users browsing this forum: wmayer and 4 guests