From 146b170bb45e534157f7b113c506f46b327c3b7f Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Mon, 22 Apr 2024 06:47:19 +0800 Subject: [PATCH] fix: error about dynamic project version (#235) * Fixed error in document regarding `Get with a specific function` section * Fixed the error of not correctly parsing single literal parameters. --- docs/metadata.md | 4 ++-- src/pdm/backend/utils.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/metadata.md b/docs/metadata.md index cf8989f..a4f991b 100644 --- a/docs/metadata.md +++ b/docs/metadata.md @@ -87,13 +87,13 @@ def format_version(version: SCMVersion) -> str: ```toml [tool.pdm.version] source = "call" -getter = "mypackage.version.get_version" +getter = "mypackage.version:get_version" ``` You can also supply it with literal arguments: ```toml -getter = "mypackage.version.get_version('dev')" +getter = "mypackage.version:get_version('dev')" ``` ### Writing dynamic version to file diff --git a/src/pdm/backend/utils.py b/src/pdm/backend/utils.py index 6b5d71c..66d72eb 100644 --- a/src/pdm/backend/utils.py +++ b/src/pdm/backend/utils.py @@ -215,7 +215,10 @@ def evaluate_module_attribute( obj: Any = functools.reduce(getattr, attrs, module) args_group = matched.group(3) if args_group: + # make tuple + args_group = args_group.strip()[:-1] + ",)" args = ast.literal_eval(args_group) + else: args = () return obj, args