-
Notifications
You must be signed in to change notification settings - Fork 122
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
Get the version from pyproject.toml [tool.poetry] section #432
Comments
Thanks for the feedback. I have updated the title of this ticket. It read to me like this is about reading the version from And maybe, pyproject.toml and So towncrier should only care about talking with poetry, and poetry can get the info from pyproject.toml, or any other source (reading the starts :) As a workaround, you can still use pyproject.toml and call I don't know Anyway, having towncrier automatically detect the version, as advertised by poetry would be nice. I would be happy to review and approve such a PR :) |
What about https://python-poetry.org/docs/cli/#version ? |
Hi @adiroiban, I shall be happy to write a PR for this: Since the aim is to get the version from |
Anything that does the job, is well documented and tested and doesn't introduce regression should be ok. I know there is importlib.metadata that AFAIK is supposted to provide a standard way to extract information for a package. and supporting this feature only on py3.8 and above should be good enough. |
Okay, so I was able to find a solution (only my initial thoughts though, but if this is right I can proceed with opening a PR) – if one can assume that def get_poetry_version(package_dir: str, package: str) -> str:
# assume poetry is installed
from subprocess import check_output
version = check_output(['poetry', 'version', '--short']).decode('utf-8')
return version and then running That being said, I am not sure if this is the best way though; I did try to use |
Regarding The nice part about using As mentioned earlier. I am not happy with calling Is there any non-CLI API for
|
@adiroiban that makes sense, in most situations a project will be installed or editable-installed. I do not think there is any non-CLI I am happy to use |
I should point out that reading from pyproject.toml or from an installed package's metadata (#502) might seem like workable approaches, they will fail in general because they don't honor PEP 517/518 designs. The consistent way to get metadata for an unbuilt package is to use PEP 517 to have whatever backend (poetry, setuptools, flit, etc) resolve the metadata (maybe from pyproject.toml, maybe dynamically generated, etc). The project_wheel_metadata function was designed to generally resolve the metadata for any PEP 517 project. It uses 'importlib.metadata' under the hood, so The downside is that it's potentially very slow (because it creates a virtualenv to do an isolated build, builds the metadata (and possibly the whole package if the build backend doesn't support just building the metadata), and then tears down that isolated build). It has another downside in that it by default depends on network access to install dependencies unless the isolated build is disabled and the (build) dependencies have been previously resolved by something else. If you can rely on the package having been built and installed (as suggested in the comment above), then yes, using My advice - adopt |
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adi Roiban <adi.roiban@chevah.com> Co-authored-by: Adi Roiban <adiroiban@gmail.com> Co-authored-by: Chris Beaven <smileychris@gmail.com>
Thanks @jaraco for the feedback and info about #502 was merged as I think that while not ideal, it's a bit better than what we had in the past. Basically, what we currently have only works if you have the project installed with I guess that we will see how people will use this functionality. I agree that doing a At the same time, if you call The solution from #502 , while not 100% looks simple, and I hope that it will alwasy work in practice ... time will tell. I am happy to have a PR that implements getting the version via |
Currently using towncrier with a project that uses poetry as package manager. The docs says that you can add towncrier's config to
pyproject.toml
, and poetry has metadata version like thisif adding towncrier metadata to the toml like this
it complains about lacking the version. Can't towncrier parse the toml looking for version instead of repeating version variables?
The text was updated successfully, but these errors were encountered: