From fc6f754ec5a7a82b29322cf4b37c8251dde24ecb Mon Sep 17 00:00:00 2001 From: DivingDuck Date: Sat, 16 Nov 2024 20:53:29 +0100 Subject: [PATCH] Add support for Python 3.12 and 3.13 --- .github/workflows/buildpackage-win.yml | 7 ++-- CleanCacheFiles.bat | 40 ++++++++++++++++++++ printrun/device.py | 2 +- printrun/gcodeplater.py | 4 +- printrun/gcoder.py | 8 ++-- printrun/pronsole.py | 6 +-- printrun/pronterface.py | 2 +- release_windows.bat | 51 +++++++++++++++++++------- requirements.txt | 2 +- 9 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 CleanCacheFiles.bat diff --git a/.github/workflows/buildpackage-win.yml b/.github/workflows/buildpackage-win.yml index 4eb24d9f5..9f7e7d147 100644 --- a/.github/workflows/buildpackage-win.yml +++ b/.github/workflows/buildpackage-win.yml @@ -16,9 +16,10 @@ jobs: os: [windows-latest] # supported architecture: [x64, x86] architecture: [x86, x64] - # supported versions: ['3.8', '3.9', '3.10', '3.11'] - # for x86 only Python 3.9 to 3.11 is supported - python-version: ['3.10'] + # supported versions: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] + # for x86 only Python 3.9 to 3.13 is supported + # Python 3.13 is experimental + python-version: ['3.10', '3.11', '3.12', '3.13'] steps: - name: Checkout diff --git a/CleanCacheFiles.bat b/CleanCacheFiles.bat new file mode 100644 index 000000000..f5d99c2b3 --- /dev/null +++ b/CleanCacheFiles.bat @@ -0,0 +1,40 @@ +echo off +rem ************************************************************** +rem *** This batch file will clean up all __pycache__ folders, *** +rem *** *.pyd files and left over gcoder_line files from *** +rem *** previous builds. For Windows only. *** +rem *** *** +rem *** This is helpful when you switch between Python *** +rem *** versions or you have problems with incompatible *** +rem *** library files. *** +rem *** *** +rem *** Don't forget to delete the virtual environment v3 *** +rem *** if you switch between Python versions. *** +rem *** *** +rem *** Author: DivingDuck, 2024-11-16, Status: working *** +rem ************************************************************** + +echo *** Clean pip cache *** +if exist v3 ( + call v3\Scripts\activate + echo *** Activate virtual environment v3 *** + ) + +pip cache purge + +echo *** Clean all __pycache__ folders *** + +for /d /r . %%d in (__pycache__) do @if exist "%%d" echo "%%d" && rd /s/q "%%d" + +if exist v3 ( + call v3\Scripts\deactivate + echo *** Deactivate virtual environment v3 *** + ) + +echo *** clean gcoder_line files *** +if exist printrun\gcoder_line.c del printrun\gcoder_line.c && echo *** delete printrun\gcoder_line.c deleted *** +if exist printrun\gcoder_line.cp???-win_amd??.pyd del printrun\gcoder_line.cp???-win_amd??.pyd && echo *** printrun\gcoder_line.cp???-win_amd??.pyd deleted *** +if exist printrun\gcoder_line.cp???-win??.pyd del printrun\gcoder_line.cp???-win??.pyd && echo *** printrun\gcoder_line.cp???-win??.pyd deleted *** +if exist printrun\gcoder_line.cp??-win_amd??.pyd del printrun\gcoder_line.cp??-win_amd??.pyd && echo *** printrun\gcoder_line.cp??-win_amd??.pyd deleted *** +if exist printrun\gcoder_line.cp??-win??.pyd del printrun\gcoder_line.cp??-win??.pyd && echo *** printrun\gcoder_line.cp??-win??.pyd deleted *** +pause diff --git a/printrun/device.py b/printrun/device.py index 1657d0c36..0428f5484 100644 --- a/printrun/device.py +++ b/printrun/device.py @@ -206,7 +206,7 @@ def _parse_type(self): def _is_url(self, text): # TODO: Rearrange to avoid long line - host_regexp = re.compile("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$") + host_regexp = re.compile(r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$") if ':' in text: bits = text.split(":") if len(bits) == 2: diff --git a/printrun/gcodeplater.py b/printrun/gcodeplater.py index c511c5e68..23c0db6a2 100755 --- a/printrun/gcodeplater.py +++ b/printrun/gcodeplater.py @@ -45,8 +45,8 @@ def gcoder_write(self, f, line, store = False): self.append(line, store = store) -rewrite_exp = re.compile("(%s)" % "|".join(["X([-+]?[0-9]*\.?[0-9]*)", - "Y([-+]?[0-9]*\.?[0-9]*)"])) +rewrite_exp = re.compile("(%s)" % "|".join([r"X([-+]?[0-9]*\.?[0-9]*)", + r"Y([-+]?[0-9]*\.?[0-9]*)"])) def rewrite_gline(centeroffset, gline, cosr, sinr): if gline.is_move and (gline.x is not None or gline.y is not None): diff --git a/printrun/gcoder.py b/printrun/gcoder.py index 6fbc5f410..099cd8428 100755 --- a/printrun/gcoder.py +++ b/printrun/gcoder.py @@ -25,10 +25,10 @@ gcode_parsed_args = ["x", "y", "e", "f", "z", "i", "j"] gcode_parsed_nonargs = 'gtmnd' to_parse = "".join(gcode_parsed_args) + gcode_parsed_nonargs -gcode_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n|([%s])\s*([-+]?[0-9]*\.?[0-9]*)" % to_parse) -gcode_strip_comment_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n") -m114_exp = re.compile("\([^\(\)]*\)|[/\*].*\n|([XYZ]):?([-+]?[0-9]*\.?[0-9]*)") -specific_exp = "(?:\([^\(\)]*\))|(?:;.*)|(?:[/\*].*\n)|(%s[-+]?[0-9]*\.?[0-9]*)" +gcode_exp = re.compile(r"\([^\(\)]*\)|;.*|[/\*].*\n|([%s])\s*([-+]?[0-9]*\.?[0-9]*)" % to_parse) +gcode_strip_comment_exp = re.compile(r"\([^\(\)]*\)|;.*|[/\*].*\n") +m114_exp = re.compile(r"\([^\(\)]*\)|[/\*].*\n|([XYZ]):?([-+]?[0-9]*\.?[0-9]*)") +specific_exp = r"(?:\([^\(\)]*\))|(?:;.*)|(?:[/\*].*\n)|(%s[-+]?[0-9]*\.?[0-9]*)" move_gcodes = ["G0", "G1", "G2", "G3"] class PyLine: diff --git a/printrun/pronsole.py b/printrun/pronsole.py index 0fee067fa..e39a03d14 100644 --- a/printrun/pronsole.py +++ b/printrun/pronsole.py @@ -58,7 +58,7 @@ except ImportError: READLINE = False # neither readline module is available -tempreading_exp = re.compile('\\bT\d*:') +tempreading_exp = re.compile(r'\\bT\d*:') REPORT_NONE = 0 REPORT_POS = 1 @@ -198,7 +198,7 @@ def __init__(self): self.history_file = os.path.join(self.cache_dir,"history") self.config_dir = os.path.join(user_config_dir("Printrun")) self.data_dir = os.path.join(user_data_dir("Printrun")) - self.lineignorepattern=re.compile("ok ?\d*$|.*busy: ?processing|.*busy: ?heating|.*Active Extruder: ?\d*$") + self.lineignorepattern = re.compile(r"ok ?\d*$|.*busy: ?processing|.*busy: ?heating|.*Active Extruder: ?\d*$") # -------------------------------------------------------------- # General console handling @@ -1137,7 +1137,7 @@ def listfiles(self, line): self.log(_("Files on SD card:")) self.log("\n".join(self.sdfiles)) elif self.sdlisting: - self.sdfiles.append(re.sub(" \d+$","",line.strip().lower())) + self.sdfiles.append(re.sub(r" \d+$","",line.strip().lower())) def _do_ls(self, echo): # FIXME: this was 2, but I think it should rather be 0 as in do_upload diff --git a/printrun/pronterface.py b/printrun/pronterface.py index 29e6be180..d37b8d051 100644 --- a/printrun/pronterface.py +++ b/printrun/pronterface.py @@ -2096,7 +2096,7 @@ def listfiles(self, line, ignored = False): self.recvlisteners.remove(self.listfiles) wx.CallAfter(self.filesloaded) elif self.sdlisting: - self.sdfiles.append(re.sub(" \d+$", "", line.strip().lower())) # NOQA + self.sdfiles.append(re.sub(r" \d+$", "", line.strip().lower())) # NOQA def waitforsdresponse(self, l): if "file.open failed" in l: diff --git a/release_windows.bat b/release_windows.bat index 44fbaa163..51c40dc1b 100644 --- a/release_windows.bat +++ b/release_windows.bat @@ -28,19 +28,23 @@ rem ** rem ** 1. Install python 64-bit (3.10.x 64-bit is actually preferred ** rem ** and standard version for Windows 10) ** rem ** https://www.python.org/downloads/release ** -rem ** In case you use an other Python version: Check line 73 to 77 and adjust ** +rem ** In case you use an other Python version: Check line 77 to 82 and adjust ** rem ** the parameter accordingly to build your virtual environment. ** rem ** 2. Install C-compiler environment ** rem ** https://wiki.python.org/moin/WindowsCompilers ** +rem ** (Microsoft Visual Studio 2022 Community version is proofed to work fine) ** rem ** 3. Check for latest repository updates at: ** rem ** http://github.com/kliment/Printrun.git ** -rem ** ** +rem ** 4. It is recommended to delete an existing virtual environment (v3) when you ** +rem ** switch between -x32/-x64 or different Python versions. There is a second ** +rem ** batch script called CleanCacheFiles.bat available for cleaning ** +rem ** former compiling- and __pycache__ artifacts . Run it as often you need. ** rem ** ** rem ** Remark: Plater stand alone application is experimental only. GUI code need an ** rem ** update for closing plater window and running processes. For now you ** rem ** need to terminate the process manually via Task manager. ** rem ** ** -rem ** Author: DivingDuck, 2023-12-15, Status: working ** +rem ** Author: DivingDuck, 2024-11-16, Status: working ** rem ** ** rem ************************************************************************************ rem ************************************************************************************ @@ -52,6 +56,13 @@ if exist dist ( DEL /F/Q/S dist > NUL RMDIR /Q/S dist ) +echo *************************************************** +echo ****** Delete files and directory of .\build ****** +echo *************************************************** +if exist build ( + DEL /F/Q/S build > NUL + RMDIR /Q/S build + ) echo ********************************************* echo ****** Activate virtual environment v3 ****** echo ********************************************* @@ -67,17 +78,22 @@ if exist v3 ( rem for your Python version of choice and add 'rem' for all other versions. rem Attention: rem Minimum version for wxPython is >= 4.2.1. With this version - rem Python x64 (version 3.7 up to 3.11) and - rem Python x86 (version 3.9 up to 3.11) is supported. + rem Python x64 (version 3.8 up to 3.12) and + rem Python x86 (version 3.9 up to 3.12) is supported. - rem py -3.7 -m venv v3 rem py -3.8 -m venv v3 rem py -3.9-32 -m venv v3 rem py -3.9 -m venv v3 rem py -3.10-32 -m venv v3 - py -3.10 -m venv v3 + rem py -3.10 -m venv v3 rem py -3.11-32 -m venv v3 rem py -3.11 -m venv v3 + rem py -3.12-32 -m venv v3 + rem py -3.12 -m venv v3 + + rem Attention: Python 3.13 support is experimental, no 3D view available for now. + rem py -3.13-32 -m venv v3 + py -3.13 -m venv v3 echo ********************************************* echo ****** Activate virtual environment v3 ****** @@ -102,6 +118,7 @@ if exist v3 ( pip install pyinstaller pip install pypiwin32 pip install polygon3 + pip install pytest ) echo ******************************************** @@ -120,15 +137,15 @@ echo ****** pyglet workaround, needs to be below 2.0 (isn't compatible) ****** echo ************************************************************************* rem # 2022-11-01 pip uninstall pyglet -y -pip install pyglet==1.5.27 +pip install pyglet==1.5.29 -echo ************************************************************************** -echo ****** pillow workaround, needs to be below 10.0 (isn't compatible) ****** -echo ************************************************************************** +rem echo ************************************************************************** +rem echo ****** pillow workaround, needs to be below 10.0 (isn't compatible) ****** +rem echo ************************************************************************** rem # 2023-12-15 rem building wxPython 4.2.1 for x86 needs pillow <10.0 -pip uninstall pillow -y -pip install pillow==9.5.0 +rem *** pip uninstall pillow -y +rem *** pip install pillow==9.5.0 echo ****************************************************************** echo ****** Compile G-Code parser gcoder_line.cp??-win_amd??.pyd ****** @@ -140,6 +157,14 @@ if exist printrun\gcoder_line.cp??-win_amd??.pyd ( echo ****** found versions of printrun\gcoder_line.cp??-win_amd??.pyd, deleted ****** echo ******************************************************************************** ) +rem In addition check for 3 digit Python versions +if exist printrun\gcoder_line.cp???-win_amd??.pyd ( + del printrun\gcoder_line.cp???-win_amd??.pyd + echo ***********************************************************************++********* + echo ****** found versions of printrun\gcoder_line.cp???-win_amd??.pyd, deleted ****** + echo ********************************************************************************** + ) + python setup.py build_ext --inplace echo **************************************** diff --git a/requirements.txt b/requirements.txt index 12146cfe7..1d179dda8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pyserial (>= 3.0) -pillow < 10.0; sys_platform == 'win32' +pillow ; sys_platform == 'win32' wxPython >= 4.2.0 numpy (>= 1.8.2) pyglet >= 1.1, < 2.0