joha2 / pyrate

This is my pyrate fork. Goal is for me to provide a useful FreeCAD interface.
GNU General Public License v2.0
3 stars 1 forks source link

setup.py should have a entry for the freecad package #37

Closed looooo closed 5 years ago

looooo commented 6 years ago

the setup.py must have an entry for the freecad package. Similar to this one here: https://github.com/FreeCAD/Workbench-Starterkit/blob/master/setup.py#L8L9

Also the requirements/dependencies are not installed in an automatic way. I did it manually with pip install -r requirements.in Launching freecad with py3 gives me this error:

During initialization the error cannot import name 'material_isotropic' occurred in freecad.PyrateWorkbench

so I guess this still doesn't work with py3?

edit.: would be nice to make this work. Also to have another example for proper packaging for FreeCAD.

joha2 commented 6 years ago

Hey @looooo yeah I would really like to get the interface running. Unfortunately the API is not stabilized and therefore the FreeCAD interface code will not work, yet. We also did some effort to port the whole package to Py3 (we've accepted the PR just a few days ago.). So it should work with Py3 (except the ZMX parser because of this strange UTF16 files.)

Independent from that, I added the freecad and freecad/PyrateWorkbench to the setup.py and would like to know how the requirements.in can be used to automatically load the packages from pip?

edit: updated setup.py according to your specifications.

looooo commented 6 years ago

https://packaging.python.org/discussions/install-requires-vs-requirements/#requirements-files

Whereas install_requires defines the dependencies for a single project, Requirements Files are often used to define the requirements for a complete Python environment.

So I guess you have to add the dependencies directly in the setup.py file. You can also have a look here: https://github.com/booya-at/OpenGlider/blob/develop/setup.py#L75L81

joha2 commented 6 years ago

Thanks for the clarification. Is there a fast way to setup FreeCAD with python3 under linux? Such that I can test the workbench?

joha2 commented 6 years ago

@looooo I just updated the imports in the PyrateWorkbench code. In Py27 it initializes at least without errors. If I load the workbench, the Log command is not found.

looooo commented 6 years ago

@joha2 the simplest way I know is conda. But conda also has it's difficulties. In case you want to try it:

`alias initConda='export PATH="/home/lo/conda/bin:$PATH"'

for ubuntu18.04 you will also need to add a hack to get a useable freecad: alias initConda='export QT_STYLE_OVERRIDE=gtk2&&export PATH="/home/lo/conda/bin:$PATH"'

then start a new terminal and type: initConda

and create a new environment with freecad: conda create -n freecad freecad scipy sympy pyyaml -c conda-forge

(as you can see, you can add several packages which should be part of the environment. This can be done also later with pip, but conda is the saver way to get more difficult dependencies installed)

once that is done the commands to activate that environment are printed. Once the freecad-env is actiavted start freecad with FreeCAD. I guess this should be all.

to install and try pyrate, best install it with pip pip works for conda-environments like it does for your system. So you won't touch the system installed python-packages... you can also install scipy, sympy,


I also tested with py3 and found some obvious problems. Maybe you can have a look: https://github.com/joha2/pyrate/pull/38

joha2 commented 6 years ago

@looooo thanks for cleaning up our mess for Py3 usability :-) I will try your description for setting up a mini conda environment for FreeCAD with Py3 support. Maybe this is also worth to be mentioned in our README.md file or in the wiki, isn't it?

The FreeCAD interface itself for pyrateoptics has to be rewritten completely, I think. So maybe these import problems vanish anyway in the future. For debugging the workbench it is really a pity that the errors do not come with a regular traceback (at least in the Py27 version). Is this fixed in the Py3 version? I spent a few minutes figuring out where the import problems have their origin.

btw. I merged your PR.

looooo commented 6 years ago

For debugging the workbench it is really a pity that the errors do not come with a regular traceback (at least in the Py27 version). Is this fixed in the Py3 version? I spent a few minutes figuring out where the import problems have their origin.

Yes, this is really a problem and it is even worse in py3. The best is to create a forum-topic for this issue. I will have a look in the next week

joha2 commented 6 years ago

Yeah I will open the topic in the forum immediately. I think this traceback problem is persistent for years, there has to be a reason for it. But anyways: Big thanks for your efforts!

-> https://forum.freecadweb.org/viewtopic.php?f=10&p=254055#p254055

looooo commented 5 years ago

I do not know if this is the right place, but there are still some problems with py3: the first gui-command () fails with:

Running the Python command 'CreateSystemCommand' failed:
Traceback (most recent call last):
  File "/home/lo/.local/lib/python3.6/site-packages/freecad/PyrateWorkbench/Commands_OpticalSystem.py", line 76, in Activated
    osobs.initFromGivenOpticalSystem(osobs.initDemoSystem())
  File "/home/lo/.local/lib/python3.6/site-packages/freecad/PyrateWorkbench/Observer_OpticalSystem.py", line 287, in initFromGivenOpticalSystem
    for (key_elem, elem) in s.elements.iteritems():

'dict' object has no attribute 'iteritems'

should be s.elements.items() I guess there are more of these...

btw.: Installing with pip now works fine. I tried with using your branch directly: pip intall https://github.com/joha2/pyrate/archive/master.zip --user

joha2 commented 5 years ago

@looooo ah nice that the pip install works. Not so fine is that there are still py3 errors. I will check with 2to3.

joha2 commented 5 years ago

@looooo now I fixed the most critical reports for 2to3. I am not sure why those files where not changed. Now 2to3 is only complaining about some list() casts which I should do.

looooo commented 5 years ago

@joha2 tested another time and the first command seems to work now. But I have to admit that I do not have any idea how the workbench works...

joha2 commented 5 years ago

@looooo big thanks for testing and support! The interface is broken, anyway. We did not adapted it to the refactored code from mid 2017. I will update the thread in the forum, but I will put a remark there that the code is still buggy and the PR have to be merged into the main repo.

joha2 commented 5 years ago

@looooo does the pip download work also for the freecad-daily version? (I.e. is it also in the Py27 version available?)

looooo commented 5 years ago

yes for linux. Windows is missing pip (and won't get support for pip because of binary incompatibility to the available py27-distributions). No idea about mac. I guess pip should be available.

joha2 commented 5 years ago

Are there ideas about a failsafe solution (i.e. pip not available) available?

looooo commented 5 years ago

you can always install with python setup.py install. But I guess the dependencies are the problem... In the end py2 will (hopefully) go away in 2020...

joha2 commented 5 years ago

And the FreeCAD part? If pip is not available and the user wants to install the plugin (i.e. pyrate) with the addonmanager, how can I make my package cover this case? May I simply create an InitGui.py file where I from init_gui import * as a wrapper? Or is there another possibility?

looooo commented 5 years ago

Simple copy the freecad dir to any path in sys.path. eg.: Ext/freecad/pyrate ...

joha2 commented 5 years ago

What about the Mod/ subdirectory? In the past the addons had to be copied there.

looooo commented 5 years ago

No, this is not supported for the new modules.

joha2 commented 5 years ago

@looooo I just realized another issue: When I installed pyrate via pip into my global python environment, FreeCADs addon manager realizes this, but cannot (obviously) uninstall the package. Is this a FreeCAD-Addon issue or do I have to take about that for myself in pyrate? Should the addon manager complain about pip installations which do not reside in the Mod directory?

looooo commented 5 years ago

Pip installable packages should not be installed with the current-add-on manager and should not be located in any Mod directory. But I am not sure if I have understood the question correctly.

joha2 commented 5 years ago

@looooo thanks for your fast answer! Yeah the problem is that pyrate is still in the addon manager available as a download such that it is downloaded into the .FreeCAD/Mod directory. But I am not sure why this works anyway.