Little debug tool for people to easily install pip packages graphically

BBIM is being used in companies as ways to automate various BIM processes, and it ends up being such that Blender Python becomes their dev environment.
This commit is contained in:
Dion Moult
2024-03-06 16:44:32 +11:00
parent 7f394a5807
commit e854447714
4 changed files with 45 additions and 2 deletions
@@ -28,18 +28,19 @@ classes = (
operator.InspectFromStepId, operator.InspectFromStepId,
operator.OverrideDisplayType, operator.OverrideDisplayType,
operator.ParseExpress, operator.ParseExpress,
operator.PipInstall,
operator.PrintIfcFile, operator.PrintIfcFile,
operator.PrintObjectPlacement, operator.PrintObjectPlacement,
operator.PrintUnusedElementStats,
operator.ProfileImportIFC, operator.ProfileImportIFC,
operator.PurgeHdf5Cache, operator.PurgeHdf5Cache,
operator.PurgeIfcLinks, operator.PurgeIfcLinks,
operator.PurgeUnusedElementsByClass,
operator.RewindInspector, operator.RewindInspector,
operator.SelectExpressFile, operator.SelectExpressFile,
operator.SelectHighPolygonMeshes, operator.SelectHighPolygonMeshes,
operator.SelectHighestPolygonMeshes, operator.SelectHighestPolygonMeshes,
operator.ValidateIfcFile, operator.ValidateIfcFile,
operator.PrintUnusedElementStats,
operator.PurgeUnusedElementsByClass,
prop.BIMDebugProperties, prop.BIMDebugProperties,
ui.BIM_PT_debug, ui.BIM_PT_debug,
) )
@@ -17,6 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os import os
import sys
import bpy import bpy
import time import time
import logging import logging
@@ -623,3 +624,39 @@ class PurgeUnusedElementsByClass(bpy.types.Operator, tool.Ifc.Operator):
print("Finished 20 batches. Manually stopping in case of infinite loop.") print("Finished 20 batches. Manually stopping in case of infinite loop.")
self.report({"INFO"}, f"Auto purged {total_purged} orphaned elements") self.report({"INFO"}, f"Auto purged {total_purged} orphaned elements")
tool.Ifc.get().write(self.filepath) tool.Ifc.get().write(self.filepath)
class PipInstall(bpy.types.Operator):
bl_idname = "bim.pip_install"
bl_label = "Pip Install"
bl_description = "Installs a package from PyPI"
name: bpy.props.StringProperty()
def execute(self, context):
import blenderbim.bim
target = [p for p in sys.path if p.endswith("packages") and "addons" in p][0]
py_exec = str(sys.executable)
print("Detected executable:", py_exec)
print("Installing to:", target)
subprocess.call([py_exec, "-m", "ensurepip", "--user"])
subprocess.call([py_exec, "-m", "pip", "install", "--upgrade", "pip"])
# Trusted host to make things simpler due to some enterprise network restrictions
subprocess.call(
[
py_exec,
"-m",
"pip",
"install",
f"--target={target}",
"--upgrade",
self.name,
"--trusted-host",
"pypi.org",
"--trusted-host",
"files.pythonhosted.org",
]
)
return {"FINISHED"}
@@ -51,3 +51,4 @@ class BIMDebugProperties(PropertyGroup):
default="BOUNDS", default="BOUNDS",
) )
ifc_class_purge: StringProperty(name="Unused Elements IFC Class", default="") ifc_class_purge: StringProperty(name="Unused Elements IFC Class", default="")
package_name: StringProperty(name="Package Name", default="")
@@ -44,6 +44,10 @@ class BIM_PT_debug(Panel):
row.operator("bim.parse_express", icon="IMPORT", text="") row.operator("bim.parse_express", icon="IMPORT", text="")
row.operator("bim.select_express_file", icon="FILE_FOLDER", text="") row.operator("bim.select_express_file", icon="FILE_FOLDER", text="")
row = self.layout.row(align=True)
row.prop(props, "package_name", text="")
row.operator("bim.pip_install", icon="EVENT_PAGEDOWN").name = props.package_name
row = layout.row() row = layout.row()
row.operator("bim.reload_ifc_file", text="Incrementally Reload Changes") row.operator("bim.reload_ifc_file", text="Incrementally Reload Changes")