Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fallback_version for source = "call" #262

Closed
nokados opened this issue Sep 26, 2024 · 1 comment · Fixed by #264
Closed

Use fallback_version for source = "call" #262

nokados opened this issue Sep 26, 2024 · 1 comment · Fixed by #264
Assignees

Comments

@nokados
Copy link

nokados commented Sep 26, 2024

I am migrating from setuptools to pdm-backend. I want to use a dynamic version extracted from a VERSION file, which only contains the version without any Python syntax. For example:

1.0.0

So, I choose this setting for dynamic versioning:

[tool.pdm.version]
source = "call"
getter = "get_version:get_version"

And my get_version.py is:

"""Read version from setuptools compatible VERSION file."""

def get_version():
    try:
        with open("VERSION") as f:
            return f.read().strip()
    except FileNotFoundError:
        return "0.0.0"

I would like to have a fallback_version in the .toml file for two reasons:

  1. To handle exceptions from the script, allowing me to avoid the except FileNotFoundError: return "0.0.0" block.
  2. To handle an invalid version, for example, if the VERSION file contains a branch+commit string.
@frostming frostming self-assigned this Oct 8, 2024
frostming added a commit that referenced this issue Oct 8, 2024
Fixes #262

Signed-off-by: Frost Ming <me@frostming.com>
frostming added a commit that referenced this issue Oct 8, 2024
Fixes #262

Signed-off-by: Frost Ming <me@frostming.com>
@nokados
Copy link
Author

nokados commented Oct 8, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants