Fix run time errors with python3.12 and pyside6 (#13337)

* Change pyopen=open expression to from builtins import open as pyopen

---------

Co-authored-by: Adrián Insaurralde Avalos <36372335+adrianinsaval@users.noreply.github.com>
This commit is contained in:
Dov Grobgeld
2024-04-30 06:28:01 +02:00
committed by GitHub
parent cc8794a611
commit ff11cd25ee
56 changed files with 161 additions and 213 deletions

View File

@@ -40,6 +40,7 @@ import datetime
import shlex
from PathScripts import PathUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -137,9 +138,7 @@ POST_OPERATION = """"""
TOOL_CHANGE = """M05
M09"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -279,7 +278,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -30,6 +30,7 @@ import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
import datetime
import Path
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -126,9 +127,7 @@ POST_OPERATION = """"""
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -242,7 +241,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -24,6 +24,7 @@
import datetime
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
Dumper is an extremely simple postprocessor file for the Path workbench. It is used
@@ -35,9 +36,7 @@ shows the dialog so you can see it. Useful for debugging, but not much else.
now = datetime.datetime.now()
SHOW_EDITOR = True
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def export(objectslist, filename, argstring):

View File

@@ -27,6 +27,7 @@ import Path
import PathScripts.PathUtils as PathUtils
import datetime
import importDXF
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -58,9 +59,7 @@ else:
Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule())
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):

View File

@@ -33,6 +33,7 @@ import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a post processor file for the FreeCAD Path workbench. It is used to
@@ -151,9 +152,7 @@ M30
# Create following variable for use with the 2nd reference plane.
clearanceHeight = None
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -346,7 +345,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -38,6 +38,7 @@ import PathScripts.PathUtils as PathUtils
import argparse
import datetime
import shlex
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -153,9 +154,7 @@ POST_OPERATION = """"""
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -284,7 +283,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -35,6 +35,7 @@ import argparse
import datetime
import shlex
import re
from builtins import open as pyopen
TOOLTIP = """
@@ -156,13 +157,6 @@ CURRENT_X = 0
CURRENT_Y = 0
CURRENT_Z = 0
# ***************************************************************************
# * to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
global OUTPUT_HEADER
@@ -346,7 +340,7 @@ def export(objectslist, filename, argstring):
print("Done postprocessing.")
# write the file
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -22,6 +22,7 @@
# ***************************************************************************
import datetime
from builtins import open as pyopen
TOOLTIP = """
This is an example postprocessor file for the Path workbench. It is used
@@ -33,9 +34,7 @@ to GCode.
now = datetime.datetime.now()
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def export(objectslist, filename, argstring):
@@ -48,7 +47,7 @@ def export(objectslist, filename, argstring):
print("the given object is not a path")
gcode = obj.Path.toGCode()
gcode = parse(gcode)
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(gcode)
gfile.close()

View File

@@ -35,6 +35,7 @@ from GCode.
import FreeCAD
import Path
import os
from builtins import open as pyopen
# LEVEL = Path.Log.Level.DEBUG
LEVEL = Path.Log.Level.INFO
@@ -44,9 +45,7 @@ if LEVEL == Path.Log.Level.DEBUG:
Path.Log.trackModule(Path.Log.thisModule())
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def open(filename):
@@ -60,7 +59,7 @@ def open(filename):
def insert(filename, docname):
"called when freecad imports a file"
Path.Log.track(filename)
gfile = pythonopen(filename)
gfile = pyopen(filename)
gcode = gfile.read()
gfile.close()
gcode = parse(gcode)

View File

@@ -27,6 +27,7 @@
import datetime
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
now = datetime.datetime.now()
@@ -90,9 +91,7 @@ POST_OPERATION = """"""
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -205,7 +204,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -39,6 +39,7 @@ import shlex
#from PathScripts import PostUtils
import Path.Post.Utils as PostUtils
from PathScripts import PathUtils
from builtins import open as pyopen
TOOLTIP = '''
This is a postprocessor file for the Path workbench. It is used to
@@ -111,9 +112,7 @@ POST_OPERATION = ''''''
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = ''''''
# to distinguish python built-in open function from the one declared below
if open.__module__ in ['__builtin__','io']:
pythonopen = open
def processArguments(argstring):
@@ -428,7 +427,7 @@ def parse(pathobj):
def writeFile(filename, final):
if not filename == '-':
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -31,6 +31,7 @@ import shlex
import os.path
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -137,9 +138,7 @@ POST_OPERATION = """"""
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -311,7 +310,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -48,6 +48,7 @@ import PathScripts.PathUtils as PathUtils
import os
import re
from PySide.QtCore import QT_TRANSLATE_NOOP
from builtins import open as pyopen
if FreeCAD.GuiUp:
import Path.Op.Gui.Custom as PathCustomGui
@@ -80,9 +81,7 @@ class PathNoJobException(Exception):
super().__init__("No job object")
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def open(filename):
@@ -186,7 +185,7 @@ def _identifygcodeByToolNumberList(filename):
Path.Log.track(filename)
gcodeByToolNumberList = []
gfile = pythonopen(filename)
gfile = pyopen(filename)
gcode = gfile.read()
gfile.close()

14
src/Mod/CAM/Path/Post/scripts/grbl_post.py Executable file → Normal file
View File

@@ -34,6 +34,7 @@ import argparse
import datetime
import shlex
import re
from builtins import open as pyopen
TOOLTIP = """
@@ -182,12 +183,6 @@ CURRENT_Y = 0
CURRENT_Z = 0
# ***************************************************************************
# * to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
global OUTPUT_HEADER
@@ -405,10 +400,9 @@ def export(objectslist, filename, argstring):
print("Done postprocessing.")
# write the file
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile.write(final)
gfile.close()
if filename != "-":
with pyopen(filename, "w") as gfile:
gfile.write(final)
return final

View File

@@ -27,6 +27,7 @@ import Path
import PathScripts
import shlex
import math
from builtins import open as pyopen
# **************************************************************************#
# USER EDITABLE STUFF HERE #
@@ -246,8 +247,7 @@ parser.add_argument(
TOOLTIP_ARGS = parser.format_help()
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -540,7 +540,7 @@ def export(objectslist, filename, argstring):
if SHOW_EDITOR:
PostUtils.editor(Program_Out)
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(Program_Out)
gfile.close()

View File

@@ -29,6 +29,7 @@ import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -135,9 +136,7 @@ TOOL_CHANGE = """"""
POWER_ON_DELAY = 0
# to distinguish python built-in open function from the one declared below
if open.__module__ == "__builtin__":
pythonopen = open
def processArguments(argstring):
@@ -253,7 +252,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "wb")
gfile = pyopen(filename, "wb")
gfile.write(final)
gfile.close()

View File

@@ -29,6 +29,7 @@ import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -128,9 +129,7 @@ POST_OPERATION = """"""
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -290,7 +289,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -29,6 +29,7 @@ import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -128,9 +129,7 @@ POST_OPERATION = """"""
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -291,7 +290,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -24,6 +24,7 @@
import datetime
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
@@ -79,9 +80,7 @@ POST_OPERATION = """"""
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
CurrentState = {}
@@ -183,7 +182,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
# Write the output
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -52,6 +52,7 @@ import FreeCAD
import Path
import os
import Path
from builtins import open as pyopen
AXIS = (
"X",
@@ -62,9 +63,7 @@ AXIS = (
) # OpenSBP always puts multiaxis move parameters in this order
SPEEDS = "XY", "Z", "A", "B"
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def open(filename):
@@ -78,7 +77,7 @@ def insert(filename, docname):
"""called when freecad imports a file
This insert expects parse to return a list of strings
each string will become a separate path"""
gfile = pythonopen(filename)
gfile = pyopen(filename)
gcode = gfile.read()
gfile.close()
gcode = parse(gcode)

View File

@@ -30,6 +30,7 @@ import time
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
import math
from builtins import open as pyopen
TOOLTIP = """Post processor for Maho M 600E mill
@@ -296,8 +297,7 @@ GCODE_FOOTER = "M30"
linenr = 0 # variable has to be global because it is used by linenumberify and export
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def angleUnder180(command, lastX, lastY, x, y, i, j):
@@ -623,6 +623,6 @@ def export(objectslist, filename, argstring):
gcode += linenumberify(GCODE_FOOTER)
if SHOW_EDITOR:
PostUtils.editor(gcode)
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(gcode)
gfile.close()

View File

@@ -37,10 +37,9 @@ http://paulbourke.net/dataformats/hpgl/
import FreeCAD
import Part
import Path.Post.Utils as PostUtils
from builtins import open as pyopen
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
# Entrypoint used by FreeCAD
@@ -51,7 +50,7 @@ def export(objectslist, filename, argstring):
for obj in objectslist:
code += convertobject(obj)
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(code)
gfile.close()

View File

@@ -28,10 +28,9 @@ This is an preprocessor to read gcode files produced from slic3r.
import os
import Path
import FreeCAD
from builtins import open as pyopen
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def open(filename):
@@ -43,7 +42,7 @@ def open(filename):
def insert(filename, docname):
"called when freecad imports a file"
gfile = pythonopen(filename)
gfile = pyopen(filename)
gcode = gfile.read()
gfile.close()
gcode = parse(gcode)

View File

@@ -29,6 +29,7 @@ import PathScripts.PathUtils as PathUtils
import FreeCAD
from FreeCAD import Units
import shlex
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -140,9 +141,7 @@ TOOL_CHANGE = """"""
# Number of digits after the decimal point
PRECISION = 5
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -280,7 +279,7 @@ def export(objectslist, filename, argstring):
else:
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -39,6 +39,7 @@ import datetime
# import shlex
import Path.Post.Utils as PostUtils
from builtins import open as pyopen
VERSION = "0.0.4"
@@ -280,13 +281,6 @@ parser.add_argument(
parser.add_argument("--repeat", action="store_true", help="repeat axis arguments")
TOOLTIP_ARGS = parser.format_help()
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
# to distinguish python built-in open function from the one declared below
if open.__module__ == "__builtin__":
pythonopen = open
# debug option, trace to screen while processing to see where things break up.
trace_gcode = False
@@ -538,7 +532,7 @@ def export(objectslist, filename, argstring):
if not filename == "-":
print("export: writing to '{}'".format(filename))
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()

View File

@@ -32,6 +32,7 @@ import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils
from builtins import open as pyopen
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
@@ -184,9 +185,7 @@ POST_OPERATION = """"""
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = """"""
# to distinguish python built-in open function from the one declared below
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
def processArguments(argstring):
@@ -401,7 +400,7 @@ def export(objectslist, filename, argstring):
print("done postprocessing.")
if not filename == "-":
gfile = pythonopen(filename, "w")
gfile = pyopen(filename, "w")
gfile.write(final)
gfile.close()