diff --git a/changelog.md b/changelog.md index 7390144..f4f21b7 100644 --- a/changelog.md +++ b/changelog.md @@ -4,9 +4,10 @@ - 2022.08.28 - add `-q` for quiet mode - `-qqqqq` to mute all the logs - - `-m` support source code with ';' like python -c + - `-m` support source code mode while not matched `module.submodule:function` format + - like `python -c "python code"` - demo: `python -m zipapps -m "import six; print(six.__file__)"` - - WARN: source code should contains `;` + - WARN: only when `-m` not matched regex `r'^\w+(\.\w+)?(:\w+)?$'` - 2022.04.27 - handle PermissionError for chmod diff --git a/zipapps/main.py b/zipapps/main.py index d0feac6..7c2570f 100644 --- a/zipapps/main.py +++ b/zipapps/main.py @@ -324,9 +324,7 @@ def prepare_active_zipapps(self): def make_runner(): if self.main: - if ';' in self.main: - return self.main - else: + if re.match(r'^\w+(\.\w+)?(:\w+)?$', self.main): module, _, function = self.main.partition(':') if module: # main may be: 'module.py:main' or 'module.submodule:main' @@ -337,7 +335,15 @@ def make_runner(): runner = f'import {module}' if function: runner += f'; {module}.{function}()' + self._log( + f"[INFO]: -m: matches re.match(r'^\w+(\.\w+)?(:\w+)?$', 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}`." + ) + return self.main return '' kwargs = {