-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
making python-modules work #3217
Conversation
Totally support from here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow nice job! 👍 from my side to!
This is a very nice feature! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments abt things that I am not sure are working yet
Also I think currently if there is a __init__.py
in AppName/python_scripts
I think it would not be executed
=> also this I think could be solved if we want this feature
@@ -196,4 +196,6 @@ install(TARGETS KratosStructuralMechanicsCore DESTINATION libs ) | |||
install(TARGETS KratosStructuralMechanicsApplication DESTINATION libs ) | |||
|
|||
# Add to the KratosMultiphisics Python module | |||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/StructuralMechanicsApplication.py" DESTINATION KratosMultiphysics ) | |||
install(DIRECTORY DESTINATION "KratosMultiphysics/StructuralMechanicsApplication") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this works in Win (using /
for separating the path)
=> if not I think it can be easily fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you are safe with "/". It is also a valid separator for windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is not any longer in
KratosMultiphysics/applications/StructuralMechanicsApplication?
this means that you can only make installation outside of where you compile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t understand, can you please explain in more detail what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now on my computer i normally keep the python files in the same directory as they normally are. This is useful since when i change a file i do not need to reinstall.
I am asking if this will change after this PR or if the python files will be left where they are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clarifying on my point, it may even be good if this is changed, since it may be the first step towards propoer python packaging of Kratos...however the need of installing every time a python file is modified is a little annoying, which is the reason for which i ask
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah now I understand
Answer: the current behavior is NOT changed, i.e. you DON'T have to reinstall after changing python files
Only the folder-structure changes a bit in the KratosMultiphysics
folder
from:
KratosMultiphysics
- __init__.py
- StructuralMechanicsApplication.py
- FluidDynamicsApplication.py
to:
KratosMultiphysics
- __init__.py
- StructuralMechanicsApplication
__init__.py # this is the "StructuralMechanics.py"-file
- FluidDynamicsApplication.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, i see.
thx!
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/StructuralMechanicsApplication.py" DESTINATION KratosMultiphysics ) | ||
install(DIRECTORY DESTINATION "KratosMultiphysics/StructuralMechanicsApplication") | ||
|
||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/StructuralMechanicsApplication.py" DESTINATION "KratosMultiphysics/StructuralMechanicsApplication" RENAME "__init__.py") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, I am not sure if this works in Win (using /
for separating the path)
=> if not I think it can be easily fixed
@@ -4,7 +4,7 @@ | |||
application_folder = "StructuralMechanicsApplication" | |||
|
|||
# The following lines are common for all applications | |||
from . import application_importer | |||
from .. import application_importer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this also works in python2
=> if not I think it can be fixed with little effort
Nice work! Can I also import stuff from the native (C++) module inside my python script? |
I guess ... I will also test it again |
@KratosMultiphysics/technical-committee I played with this some more, for me it works as intended
from:
to:
What is left to do: Testing in other environments => for this I pushed some "pseudo-submodules", ofc they will be removed again I think we should test it on WIndows (@oberbichler @roigcarlo ) and with python2 (@maceligueta @adityaghantasala ) |
I am working and using this branch extensively as I write here. I will soon summarize my experience here. As of now for me it looks ok. except for a few points (supporting recursively including of subfolders ). |
Does it work with python 2.7? |
Works on Windows 10/Python 3.6 |
@maceligueta could you please try with python 2.7? |
@philbucher I get an error with python2.7 .. I think it not related to the imports but some other ...
|
We checked in personl, seems like @adityaghantasala currently cannot get his python2 installation running (unrelated to this PR) @maceligueta it would be great if you (or someone else that has python2) can try this out 👍 |
I just compiled the branch and tested it. I tried the tests, by doing
The same for the Fluid Dynamics:
Solid Mechanics:
A different one from Structural Mechanics:
Constitutive Models Application:
After this, the tests hang up during PfemApplication tests. :( Sorry if some of these errors are my bad! |
@maceligueta yes it is possible that you had to import these apps, I didn't think abt that at the time. Iit seems to work for the configurations we are having |
ping @KratosMultiphysics/technical-committee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The technical committee approves. We still need to decide how to treat subfolders, but that is a separate discussion.
Attention everyone: there may be some runtime issues when switching between branches that have/don't have this change. If python complains about being unable to import some application, please delete the KratosMultiphysics folder and reinstall.
After merging this PR all the applications should be changed to adapt the CMakeLists file or ? |
@adityaghantasala please leave this PR clean, I will merge it tmr |
@philbucher sure we can discuss in person ! But ya I wanted to know about other applications as (StructuralMechanicsApplciation) is changed here ... |
@philbucher probably it would be smart to write a short how-to (here or on the wiki) so that people can port their applications on their own. |
sure, will do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approving.
I will merge this now I suggest to wait one or two days until using this in other places, just to see if it has some unwanted side-effects NOTE the structuring of subfolders was not yet discussed, I suggest to wait a bit more and let the @KratosMultiphysics/technical-committee decide how the subfolders should look like |
FYI @KratosMultiphysics/altair |
1 similar comment
FYI @KratosMultiphysics/altair |
With this modification the python-scripts can be subdivided into subfolders
=> now they behave as real python modules!
=> the changes necessary are very small and can be done app-by-app without breaking anything
i.e. these changes do NOT break the current mechanism, it is fully backwards compatible and can be adapted slowly
e.g. now one can do:
solves #2655
I will discuss this with @jcotela in the next days, afterwards you can discuss it in the comittee
I think this also works in python2, but I have not tried it
FYI @adityaghantasala @oberbichler