10000 Detect pyproject.toml as project root · Pull Request #371 · python-versioneer/python-versioneer · GitHub
[go: up one dir, main page]

Skip to content

Detect pyproject.toml as project root #371 8000

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

Merged
merged 1 commit into from Jul 6, 2023
Merged

Detect pyproject.toml as project root #371

merged 1 commit into from Jul 6, 2023

Conversation

ghost
Copy link
@ghost ghost commented Jun 18, 2023

Sometimes I use some package build tools which doesn't require setup.py, for example, pdm.backend. It doesn't need a setup.py, instead, it'll build wheel directly.
So with this pr, I can do this:

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

Then when I run pdm build, pdm will read version from 'versioneer.get_version()'.
However, this doesn't work now because versioneer requires setup.py or versioneer.py to detect project root. It cannot find project root without setup.py or versioneer.py. When I using build-time dependency mode and "setup.py-less" build backend, either setup.py or versioneer.py doesn't exist, but the project root is still here! So this pull request made versioneer able to detect project root by pyproject.toml.

@effigies
Copy link
Contributor
effigies commented Jul 4, 2023

Huh, I had no idea it was possible to use this outside setuptools. Would you mind contributing docs showing how to do this?

@Callek Any interest in shepherding this one in?

@ghost
Copy link
Author
ghost commented Jul 4, 2023

Only PDM (build-backend: pdm.backend) can read version by call function now (I'm not sure if hatchling works because it seem use regex to get the version). Config for pdm.backend included in the first comment.

Copy link
Collaborator
@Callek Callek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for the delay here - had a bunch of things going on that made this take me longer than I wanted to.

But I'm happy to have this merge in. Thank you for the patch!

Comment on lines 64 to +67
# allow 'python path/to/setup.py COMMAND'
root = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
setup_py = os.path.join(root, "setup.py")
pyproject_toml = os.path.join(root, "pyproject.toml")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily think doing the path translation is necessary here, but happy to keep it for consistency. (I actually suspect we should rewrite some of this logic a bit, since it defaults to cwd() rather than the actual target of the package.)

@Callek Callek merged commit 6caeee1 into python-versioneer:master Jul 6, 2023
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 this pull request may close these issues.

2 participants
0