Skip to content
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

Add post-link.sh script #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gbroques
Copy link

@gbroques gbroques commented Dec 27, 2023

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
Copy link
Contributor

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.

Allows for executing python scripts which import FreeCAD modules
when activating the conda environment containing freecad.

LIMITATIONS:
Windows is not supported.

See the following FreeCAD forum discussion:
https://forum.freecad.org/viewtopic.php?p=493282#p493277
@looooo
Copy link
Contributor

looooo commented Dec 27, 2023

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

@gbroques
Copy link
Author

gbroques commented Dec 27, 2023

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
Copy link
Contributor

looooo commented Dec 28, 2023

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
Copy link
Author

gbroques commented Dec 28, 2023

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
Copy link
Contributor

looooo commented Dec 28, 2023

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

@looooo
Copy link
Contributor

looooo commented Dec 28, 2023

@gbroques
Copy link
Author

gbroques commented Dec 28, 2023

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
Copy link
Author

gbroques commented Dec 28, 2023

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
Copy link
Contributor

looooo commented Jan 2, 2024

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
Copy link
Contributor

looooo commented Jan 2, 2024

FreeCAD/FreeCAD#11885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants