From 8e786a72ac8d86d03d2f9ec0335579b25cda3bce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mathieu=20D=C3=A9fosse?= Date: Sat, 17 Jun 2023 13:46:08 -0400 Subject: [PATCH] Fixed CLI output when running post_write hooks Fixes: #1261 ### Description Just fixed badly written Python string interpolation. Used the `%` operator just like the lines above. ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #1262 Pull-request: https://github.com/sqlalchemy/alembic/pull/1262 Pull-request-sha: 19d17f5d061319bbf142b45a593081da5fc1dda8 Change-Id: I89ef873935d7206a61f78a09139cd5ab192a2275 --- alembic/script/write_hooks.py | 14 ++++++++------ docs/build/unreleased/1261.rst | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 docs/build/unreleased/1261.rst diff --git a/alembic/script/write_hooks.py b/alembic/script/write_hooks.py index 0e9ec40a..5f53dc20 100644 --- a/alembic/script/write_hooks.py +++ b/alembic/script/write_hooks.py @@ -56,7 +56,7 @@ def _invoke( hook = _registry[name] except KeyError as ke: raise util.CommandError( - "No formatter with name '%s' registered" % name + f"No formatter with name '{name}' registered" ) from ke else: return hook(revision, options) @@ -82,10 +82,12 @@ def _run_hooks(path: str, hook_config: Mapping[str, str]) -> None: type_ = opts["type"] except KeyError as ke: raise util.CommandError( - "Key %s.type is required for post write hook %r" % (name, name) + f"Key {name}.type is required for post write hook {name!r}" ) from ke else: - with util.status("Running post write hook {name!r}", newline=True): + with util.status( + f"Running post write hook {name!r}", newline=True + ): _invoke(type_, path, opts) @@ -118,8 +120,8 @@ def console_scripts( entrypoint_name = options["entrypoint"] except KeyError as ke: raise util.CommandError( - "Key %s.entrypoint is required for post write hook %r" - % (options["_hook_name"], options["_hook_name"]) + f"Key {options['_hook_name']}.entrypoint is required for post " + f"write hook {options['_hook_name']!r}" ) from ke for entry in compat.importlib_metadata_get("console_scripts"): if entry.name == entrypoint_name: @@ -141,7 +143,7 @@ def console_scripts( [ sys.executable, "-c", - "import %s; %s.%s()" % (impl.module, impl.module, impl.attr), + f"import {impl.module}; {impl.module}.{impl.attr}()", ] + cmdline_options_list, cwd=cwd, diff --git a/docs/build/unreleased/1261.rst b/docs/build/unreleased/1261.rst new file mode 100644 index 00000000..b8e483c9 --- /dev/null +++ b/docs/build/unreleased/1261.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug + :tickets: 1261 + + Fixed format string logged when running a post write hook + Pull request curtesy of Mathieu Défosse. -- 2.47.2