Bug 355616 - Generated python code does not have attributes or a constructor
Summary: Generated python code does not have attributes or a constructor
Status: REPORTED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: 2.17.0 (KDE Applications 15.08.0)
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 2.18 (KDE Applications 15.12)
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-19 23:33 UTC by Sean Engelhardt
Modified: 2021-03-09 07:00 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
test case (9.25 KB, text/x-xmi)
2015-12-20 13:35 UTC, Ralf Habacker
Details
Test Case with inheritance in Umbrello (12.47 KB, text/x-xmi)
2015-12-21 15:03 UTC, Sean Engelhardt
Details
Test case as image (29.09 KB, image/png)
2015-12-21 15:03 UTC, Sean Engelhardt
Details
The human-class generated by umbrello (459 bytes, text/x-python)
2015-12-21 15:05 UTC, Sean Engelhardt
Details
Test Case with inheritance in Umbrello (CORRECTED version. Cannot delete the old one) (12.57 KB, text/x-xmi)
2015-12-21 15:17 UTC, Sean Engelhardt
Details
Test case as image (CORRECTED version) (30.00 KB, image/png)
2015-12-21 15:18 UTC, Sean Engelhardt
Details
The human-class generated by umbrello (CORRECTED version) (517 bytes, text/x-python)
2015-12-21 15:33 UTC, Sean Engelhardt
Details
The human-class I expected (CORRECTED version) (594 bytes, text/x-python)
2015-12-21 15:40 UTC, Sean Engelhardt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Engelhardt 2015-11-19 23:33:13 UTC
When making a UML2 Class diagram and generating python-code, the generated code will have classes and all proper inheritences, but no attributes what so ever.

The constructor is also missing.

Reproducible: Always

Steps to Reproduce:
1. Start Umbrello
2. Create a class diagram
3. Add some classes, inheritances, etc.
4. Add an attribute to a class
5. Use the Code -> Code Generation-wizzard co create python code
6. Watch the generated code

Actual Results:  
Code does not contain any attributes nor a constructor or anything useful except from opperations.

Expected Results:  
Code does have attributes and constructor and like

class MyClass:

    def __init__(self):
        self.my_attribute = "some value"


one cannot chose the python-version to use.
Comment 1 Felix Zesch 2015-12-16 10:35:48 UTC
I can confirm this behaviour. The software is not usable for Python developers right now, unfortunately.
Comment 2 Ralf Habacker 2015-12-20 13:35:48 UTC
Created attachment 96216 [details]
test case
Comment 3 Ralf Habacker 2015-12-20 13:43:55 UTC
From the appended test case I get the following generated python code:
---------------------------------------------
from new_class_1 import *

class MyClass(object):

  """
   

  :version:
  :author:
  """

  """ ATTRIBUTES

   

  my_attribute  (private)

  """

  def __init__(self):
    """
     

    @return  :
    @author
    """
    pass
---------------------------------------------

I can see an __init__() method and a doc string refering to the attribute  'my_attribute  (private)'.

From the initial comment I guess you want to say, that 

1. non-static attributes having an initial value should be initialized in the constructor. 
2. If there is no constructor defined in the model, the generator should add a constructor, in which non-static attributes could be initialized.
3. static attributes having an initial value should be initialized in the class scope
Comment 4 Sean Engelhardt 2015-12-21 15:01:22 UTC
Hello.

> 1. non-static attributes having an initial value should be initialized in the constructor. 
> 2. If there is no constructor defined in the model, the generator should add a constructor, 
> in which non-static attributes could be initialized.
> 3. static attributes having an initial value should be initialized in the class scope

This is quite accurate. Besides, it must not be necessary to define the __init__ in UML. This would not be a PIM (Platform indipendant model) anymore. 

I will attach my Testcase, the code I get and the code I expected.
Comment 5 Sean Engelhardt 2015-12-21 15:03:25 UTC
Created attachment 96230 [details]
Test Case with inheritance in Umbrello
Comment 6 Sean Engelhardt 2015-12-21 15:03:56 UTC
Created attachment 96231 [details]
Test case as image
Comment 7 Sean Engelhardt 2015-12-21 15:05:02 UTC
Created attachment 96232 [details]
The human-class generated by umbrello
Comment 8 Sean Engelhardt 2015-12-21 15:17:29 UTC
Created attachment 96233 [details]
Test Case with inheritance in Umbrello (CORRECTED version. Cannot delete the old one)
Comment 9 Sean Engelhardt 2015-12-21 15:18:20 UTC
Created attachment 96234 [details]
Test case as image (CORRECTED version)
Comment 10 Ralf Habacker 2015-12-21 15:26:33 UTC
(In reply to Sean Engelhardt from comment #8)
> Created attachment 96233 [details]
> Test Case with inheritance in Umbrello (CORRECTED version. Cannot delete the
> old one)

In the bugtracker upload page, you will find the following text: 
Obsoletes: 	(optional) Check each existing attachment made obsolete by your new attachment.
Comment 11 Sean Engelhardt 2015-12-21 15:31:15 UTC
Added the Code again in paste.kde.org for 1 yr. Sorry for spamming with the attachments, cannot add multiple attachments at once.

Human Generated:
https://paste.kde.org/p9kdujmqu

Human Expected:
https://paste.kde.org/poe1nlco8

As Mentioned before, it is basically the constructor which is quite a problem. Its the same when you try to import your code, but this is the topic for another ticket.
(Nobody wants to see a __init__ in the PIM)
Comment 12 Sean Engelhardt 2015-12-21 15:33:05 UTC
Created attachment 96235 [details]
The human-class generated by umbrello (CORRECTED version)
Comment 13 Ralf Habacker 2015-12-21 15:39:03 UTC
In case you are able to compile umbrello from git: here (https://gitlab.com/umbrello/test/commits/272972-python-attribute-code-generator) is a branch based on Applications/15.12 containing some related patches, which may fix your issues or could be used as a starting point. 
Please give it a try.
Comment 14 Sean Engelhardt 2015-12-21 15:40:46 UTC
Created attachment 96236 [details]
The human-class I expected (CORRECTED version)

This is what I expected, but this is maybe not the ideal case. 
The ideal case would be following the pep8 guidelines

see https://www.python.org/dev/peps/pep-0008/ for details
Comment 15 Sean Engelhardt 2015-12-21 15:44:01 UTC
> In case you are able to compile umbrello from git:

This is currently not that easy. I still struggle to compile QT since they threw out QtWebKit from GIT. But I will give that a try after the Xmas season.
Comment 16 Ralf Habacker 2015-12-21 16:26:35 UTC
(In reply to Sean Engelhardt from comment #4)
> Hello.
> 
> > 1. non-static attributes having an initial value should be initialized in the constructor. 
> > 2. If there is no constructor defined in the model, the generator should add a constructor, 
> > in which non-static attributes could be initialized.
> > 3. static attributes having an initial value should be initialized in the class scope
> 
> This is quite accurate. Besides, it must not be necessary to define the
> __init__ in UML. This would not be a PIM (Platform indipendant model)
> anymore. 
Umbrello in the current state only supports class attributes and operations. If a class is name MyClass, the constructor has to be modeled by adding a method named MyClass().
Comment 17 Ralf Habacker 2016-01-04 08:15:03 UTC
(In reply to Ralf Habacker from comment #13)
> In case you are able to compile umbrello from git: here
> (https://gitlab.com/umbrello/test/commits/272972-python-attribute-code-
> generator) is a branch based on Applications/15.12 containing some related
> patches, which may fix your issues or could be used as a starting point. 
> Please give it a try.
Did you find any time to take a look ? To have the fixes in 2.18.1 (KDE Applications 15.12.1) it is required to get this into 2016 Jan 6 (see https://techbase.kde.org/Schedules/Applications/15.12_Release_Schedule#Thursday.2C_January_7.2C_2016:_KDE_Applications_15.12.1_tagging)
Comment 18 Sean Engelhardt 2016-01-05 15:18:08 UTC
Hi. 

> Did you find any time to take a look ? 
> To have the fixes in 2.18.1 (KDE Applications 15.12.1) it is required to get this into 2016 
> Jan 6 (see ... )

unfortunately I will be pretty busy until 2016-01-15.

I need to finish my paper for "Model Driven Architecture" (master program) until Feb. 15, so I will Definitly take a look at this again before KDE Applications 15.12.2 tagging.
Comment 19 Ralf Habacker 2016-01-06 08:22:41 UTC
(In reply to Sean Engelhardt from comment #14)
> The ideal case would be following the pep8 guidelines
> 
> see https://www.python.org/dev/peps/pep-0008/ for details
This is better handled by a different bug covering generated code style
Comment 20 Sean Engelhardt 2016-01-14 20:19:56 UTC
Hi.

Unfortunately I cannot manage to Build Umbrello on my Arch Linux machine. Umbrello depends too much on KDE4 librarys, which are not available on Arch anymore.

what I did:

git clone https://gitlab.com/umbrello/test.git

and then like the INSTALL told,

cd umbrello
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$HOME/umbrello -DCMAKE_BUILD_TYPE=Debug  ../


The error is:
---
CMake Error at pics/global/CMakeLists.txt:2 (kde4_install_icons):
  Unknown CMake command "kde4_install_icons".


CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.4)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
Comment 21 Ralf Habacker 2016-01-15 06:31:46 UTC
(In reply to Sean Engelhardt from comment #20)
> Hi.
> 
> Unfortunately I cannot manage to Build Umbrello on my Arch Linux machine.
> Umbrello depends too much on KDE4 librarys, which are not available on Arch
> anymore.
You can build this branch also for KF5 with
cmake -DBUILD_KF5=1 <umbrello-source-dir>
Comment 22 Justin Zobel 2021-03-09 07:00:29 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.