From ab73d1b377b39dc8dd6d86bda131c215a977f8f6 Mon Sep 17 00:00:00 2001 From: lidong Date: Wed, 5 Jun 2024 00:12:11 +0800 Subject: [PATCH] fix python 3.12 regex pattern and f-string --- zipapps/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zipapps/main.py b/zipapps/main.py index b3c0a1a..fa7cae9 100644 --- a/zipapps/main.py +++ b/zipapps/main.py @@ -370,7 +370,8 @@ def prepare_active_zipapps(self): def make_runner(): if self.main: - if re.match(r"^\w+(\.\w+)?(:\w+)?$", self.main): + pattern = r"^\w+(\.\w+)?(:\w+)?$" + if re.match(pattern, self.main): module, _, function = self.main.partition(":") if module: # main may be: 'module.py:main' or 'module.submodule:main' @@ -382,12 +383,12 @@ def make_runner(): if function: runner += f"; {module}.{function}()" self._log( - f"[INFO]: -m: matches re.match(r'^\w+(\.\w+)?(:\w+)?$', self.main), add as `{runner}`." + f"[INFO]: -m: matches re.match(r'{pattern}', self.main), add as `{runner}`." ) return runner else: self._log( - f"[INFO]: -m: not matches re.match(r'^\w+(\.\w+)?(:\w+)?$', self.main), add as raw code `{self.main}`." + f"[INFO]: -m: not matches re.match(r'{pattern}', self.main), add as raw code `{self.main}`." ) return self.main return ""