FEM Python coding standard

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Python coding standad [WORK IN PROGRESS]

Post by PrzemoF »

bernd wrote:
PrzemoF wrote:...
My proposition:
1. Fem* for general python modules,
2. ccx* for CalculiX related stuff
3. _Command* for GUI commands (underscore suggest internal use only).

Most of FEM python modules match this convention already
I'm with you here.

How about Python ui files? Should they be moved together with cpp ui files in a separate directory like the icons ?
It makes no difference for me to be honest and moving them might cause some problems in CMake files and downstream for package maintaners. I'd leave them for now unless someone is willing to move them :-)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by bernd »

microelly2 wrote:I had some requirements for handling macros and want remember this here
A macro should have at least theese meta information for autogeneration
No Licence ?
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Python coding standad [WORK IN PROGRESS]

Post by bernd »

bernd wrote:... How about Python ui files? Should they be moved together with cpp ui files in a separate directory like the icons ?
It makes no difference for me to be honest and moving them might cause some problems in CMake files and downstream for package maintaners. I'd leave them for now unless someone is willing to move them :-)
ok
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by PrzemoF »

microelly2 wrote:I had some requirements for handling macros and want remember this here
A macro should have at least theese meta information for autogeneration

Code: Select all

__Comment__ = 'Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)'
__Web__ = "http://forum.freecadweb.org/viewtopic.php?f=22&t=5554"
__Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_Airfoil_Import_%26_Scale"
__Icon__  = "/usr/lib/freecad/Mod/plugins/icons/airfoil.png"
__Help__ = "start the macro and follow the instructions"
__Author__ = "quick61"
__Version__ = '2.1'
__Status__ = 'stable'
__Requires__ = 'freecad 0.14.3706'
__Communication__ = 'your email adress or yourgit or something else'
backref: viewtopic.php?f=21&t=10905&start=20#p91086
The macro manager is/will be in the master branch of FreeCAD or it's a separate piece of code?
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by microelly2 »

the plugin manager is still standalone. I want to have some standards for community plugins to improve the possibility to integrate them.
Until now it needs still extra work to integrate the macros,
so some conventions must be accepted to simplify and automate the process.
After this the plugin manager can become integrated and a standard plugin database can hold the information about community macros and workbenches.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by PrzemoF »

OK, I'll add id in a separate section with macro requirements to the opening post.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by microelly2 »

bernd wrote:
microelly2 wrote:I had some requirements for handling macros and want remember this here
A macro should have at least theese meta information for autogeneration
No Licence ?
Macros are stored in gits and have a Licence file inside (until now ;) ).
My focus was:
If there is a published macro I can support the installation and updates for freecad users.
Mostly the licence is in the header of the file with the meta info and can be displayed.
But of course a link to the licence file/message can be integrated into the install dialog.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by wmayer »

The general rule is to follow PEP8 [1] and use flake8 [2] (or anything that allows PEP8 checks) to enforce it.
Is there also a way to make code Python 3 ready, i.e. to force e.g. write print ("test") instead of print "test" ?
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by PrzemoF »

wmayer wrote:
The general rule is to follow PEP8 [1] and use flake8 [2] (or anything that allows PEP8 checks) to enforce it.
Is there also a way to make code Python 3 ready, i.e. to force e.g. write print ("test") instead of print "test" ?
In a way yes, but flake8 has to be run with python3 [1]:

Code: Select all

$fedora:/home/przemo/software/FreeCAD/freecad
$ python /usr/bin/flake8 --ignore=E265,E501 src/Mod/Fem/FemTools.py <-- clean run on python2
fedora:/home/przemo/software/FreeCAD/freecad
$ python3 /usr/bin/flake8 --ignore=E265,E501 src/Mod/Fem/FemTools.py 
src/Mod/Fem/FemTools.py:242:71: E901 SyntaxError: invalid syntax <-- error on python3
The line 242 is python2 compatible, but not python3 compatible:

Code: Select all

            print "Unexpected error when writing CalculiX input file:", sys.exc_info()[0]
--ignore=E265,E501 is to ignore line length and invalid style of comments

P.S. For fedora users there is a package python3-flake8, so it's enough to run:

Code: Select all

fedora:/home/przemo/software/FreeCAD/freecad
$ python3-flake8 --ignore=E265,E501 src/Mod/Fem/FemTools.py 
src/Mod/Fem/FemTools.py:242:71: E901 SyntaxError: invalid syntax
[1] http://stackoverflow.com/questions/2360 ... r-python-3

For those experimenting with phabricator: arc lint config for python2/3 checks:

Code: Select all

$ cat .arclint 
{
    "linters": {
        "flake8-python2.7": {
            "type": "flake8",
            "bin": "/usr/bin/flake8",
            "include": "(\\.py$)",
            "exclude": "(^src/3rdParty/)",
            "severity": {
                "E265": "disabled",
                "E501": "disabled"
            }
        },
        "flake8-python3": {
            "type": "flake8",
            "bin": "/usr/bin/python3-flake8",
            "include": "(\\.py$)",
            "exclude": "(^src/3rdParty/)",
            "severity": {
                "E265": "disabled",
                "E501": "disabled"
            }
        }
    }
}

User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Python coding standard [WORK IN PROGRESS]

Post by makkemal »

How about Python ui files? Should they be moved together with cpp ui files in a separate directory like the icons ?
I think the ui and icon files should be in a separate subdirectory /Mod/Fem/ and not the same location as the CPP files. It makes development easier for a beginner.
Post Reply