Skip to content

Commit

Permalink
fix: error about dynamic project version (#235)
Browse files Browse the repository at this point in the history
* Fixed error in document regarding `Get with a specific function` section

* Fixed the error of not correctly parsing single literal parameters.
  • Loading branch information
cntvc authored Apr 21, 2024
1 parent 4ca42f0 commit 146b170
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/pdm/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 146b170

Please sign in to comment.