Feature Request: Python virtual env variable editing

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Feature Request: Python virtual env variable editing

Post by Joel_graff »

So I've been thinking, it'd be nice to have the ability to specify additional paths from within FreeCAD to append to it's Python virtual environment. I realize it's probably a bit superfluous for the average dev, but I can see use cases where it might come in handy - for example, being able to specify python libraries for testing purposes (just a one-off test to add / remove), as well as a convenient way to see and edit what's currently in the environment.

Even something as horribly clunky as Window's environment variable editor would be nice to have, here.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Feature Request: Python virtual env variable editing

Post by ezzieyguywuf »

Does something like this not get the job done?

Code: Select all

import sys
sys.path.insert(0, “/my/custom/lib/location”)
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Feature Request: Python virtual env variable editing

Post by Joel_graff »

It does, but I'm already doing that with macros that I run every time I run FreeCAD. And it's fine.

But... wouldn't it be nice to be able to see exactly what's in the environment? and not just as a text string dumped to the console?

Really, in my mind, the virtual environment is a big enough part of FreeCAD it deserves a little UI love.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Feature Request: Python virtual env variable editing

Post by vocx »

Joel_graff wrote: Tue Sep 10, 2019 5:21 pm ...
But... wouldn't it be nice to be able to see exactly what's in the environment? and not just as a text string dumped to the console?
...
If I get your idea right, what you want is similar to Spyder's "PYTHONPATH manager". Basically adding paths to PYTHONPATH is the easiest way to get more directories into your environment from which to import modules.

In the terminal it would be

Code: Select all

PYTHONPATH=/usr/lib/freecad/Mod    FreecAD
Spyder3_Pathmanager.png
Spyder3_Pathmanager.png (18.01 KiB) Viewed 1217 times
It seems that the Path manager is a single widget used in Spyder, https://github.com/spyder-ide/spyder/bl ... manager.py

The Spyder source code is MIT licensed, which is pretty compatible with the LGPL 2 of FreeCAD. So we could just copy its code and modify it to our needs without much problem.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Feature Request: Python virtual env variable editing

Post by Joel_graff »

vocx wrote: Tue Sep 10, 2019 5:35 pm If I get your idea right, what you want is similar to Spyder's "PYTHONPATH manager". Basically adding paths to PYTHONPATH is the easiest way to get more directories into your environment from which to import modules.
That looks like a good starting point. If nothing else, just a manager for python path changes made by the user. Sort of like a user-level list of paths applied after the system level paths.

Obviously, it'd be nice to be able to see everything and manage the entire path, but that might be more trouble than it's worth, lol
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Feature Request: Python virtual env variable editing

Post by vocx »

Joel_graff wrote: Tue Sep 10, 2019 5:41 pm ...
Obviously, it'd be nice to be able to see everything and manage the entire path, but that might be more trouble than it's worth, lol
Yes, I'm not really sure about you have in mind, but allowing the user to modify the system path sounds kinda wild. In my mind, this is the better approach, adding to their user path, on top of the system one.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Feature Request: Python virtual env variable editing

Post by Joel_graff »

vocx wrote: Tue Sep 10, 2019 5:47 pm Yes, I'm not really sure about what you have in mind, but allowing the user to modify the system path sounds kinda wild. In my mind, this is the better approach, adding to their user path, on top of the system ones.
Right... I think the system-level information might be useful, at least as read-only, but really, I only had in mind to use it to manage one-off libraries that aren't installed in the system paths - maybe just testing a new library or something. Anyway, having something that persists across FreeCAD sessions without having to specify a command line parameter, write a macro, or add it in the console would be nice.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Feature Request: Python virtual env variable editing

Post by vocx »

Joel_graff wrote: Tue Sep 10, 2019 5:52 pm ... Anyway, having something that persists across FreeCAD sessions without having to specify a command line parameter, write a macro, or add it in the console would be nice.
That would be the parameter database, that just adds the respective parameter to the user.cfg file. So the Spyder-based widget would just

Code: Select all

ParamGet("User preferences").GetParam("PYTHONPATH") to add additional directories.
However, I'm not sure if adding or removing a path would require a restart of FreeCAD, or if there is a way to handle this on the fly. I'm not sure how Spyder handles it.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Feature Request: Python virtual env variable editing

Post by Joel_graff »

vocx wrote: Tue Sep 10, 2019 6:00 pm However, I'm not sure if adding or removing a path would require a restart of FreeCAD, or if there is a way to handle this on the fly. I'm not sure how Spyder handles it.
Using sys.path.append() makes the path immediately available, so I would be a little concerned if using Spyder required restarting FreeCAD...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Post Reply