conda-forge / freecad-feedstock

A conda-smithy repository for freecad.
BSD 3-Clause "New" or "Revised" License
7 stars 22 forks source link

Add post-link.sh script #118

Open gbroques opened 11 months ago

gbroques commented 11 months ago

Motivation: Allows for executing python scripts which import FreeCAD modules when the conda environment containing freecad is activated.

LIMITATIONS: Windows is not supported, but could be added easily if someone can test it.

See the following FreeCAD forum discussion for context: https://forum.freecad.org/viewtopic.php?p=493282#p493277

@looooo said this was a good idea and would try to integrate it a few years ago, but never did: https://forum.freecad.org/viewtopic.php?p=493282#p493688

The script should support all major shells: bash, zsh, and fish.

If someone could verify this works before merging, then that would be appreiciated!

conda-forge-webservices[bot] commented 11 months ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

looooo commented 11 months ago

have you tried using import freecad in a conda env. This normally does the Path modifications.

gbroques commented 11 months ago

have you tried using import freecad in a conda env. This normally does the Path modifications.

That works too, but requires every script to import freecad before import FreeCAD, import FreeCADGui, etc.

I don't think that's ideal as this solution which doesn't require any special modifications to scripts like import freecad or modifying sys.path.

looooo commented 11 months ago

My idea was to switch over to things like from freecad import App instead of import FreeCAD as App. This change would resolve name-clashes (which can occur when you use freecad with other python modules) But this is a big change and maybe should happen after a FreeCAD 1.0 release (forcing this new way of importing freecad libraries).

gbroques commented 11 months ago

My idea was to switch over to things like from freecad import App instead of import FreeCAD as App. This change would resolve name-clashes (which can occur when you use freecad with other python modules) But this is a big change and maybe should happen after a FreeCAD 1.0 release (forcing this new way of importing freecad libraries).

I think that would cause confusion for developers since freecad isn't available unless you use the conda environment.

Unless, you're talking about making freecad available for all of FreeCAD regardless of the user's installation method?

I think Python packages and modules that depend on FreeCAD should run without modification in all environments regardless of installation method.

looooo commented 11 months ago

Normally it should work also with other installations (not only conda)

looooo commented 11 months ago

Maybe its good to set this to on as default.

https://github.com/FreeCAD/FreeCAD/blob/888dcb574396af5c5943b858929ab3b8ab9f3630/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake#L17

gbroques commented 11 months ago

Maybe its good to set this to on as default.

https://github.com/FreeCAD/FreeCAD/blob/888dcb574396af5c5943b858929ab3b8ab9f3630/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake#L17

Interesting. Yes, maybe that's a sensible default.

I didn't realize this could be an option for everyone, regardless of whether they use conda.

I think it's a good idea to enable that as a default, and socialize the following imports:

from freecad import app as App
from freecad import gui as Gui

Then people wouldn't have any problems with Python not being able to find the freecad module.

gbroques commented 11 months ago

As an aside, with FreeCAD, you can do the following imports:

from FreeCAD import Console, Placement, Vector  # ✔️ works

It would be nice if we could also import these directly from freecad.app like:

from freecad.app import Console, Placement, Vector  # ❌ doesn't work currently

To work around that, we'd have to:

from freecad import app
Console = app.Console
# Placement = ...
looooo commented 10 months ago

hmm I guess it would be best to find a consensus about the future of freecad imports. Because in the end all python relevant modules should be installed into site-packages/freecad (imho).

Actually I just refactored a workbench and I used from freecad import gui, and this works, but I have no idea how. If you try this in a python console vs freecad python console you get different results:

from freecad import gui
FreeCADGui == gui
looooo commented 10 months ago

https://github.com/FreeCAD/FreeCAD/pull/11885