Closed fu050409 closed 1 year ago
Alternatively, is there a method to extract __version__
from a specific .py
file within my project for packaging?
Hi! This is sort of backward from how the plugin is designed. The intended use case is that you would create a Git tag like v0.1.2
and then let the plugin inject the __version__ = "0.1.2"
into your code during poetry build
(it can also inject into other files, like documentation). The resulting wheel/sdist would then contain a static copy of the version. Is that something you're open to?
Thank you for your response!
In my project, the version
parameter is needed when the plugin is functioning (it's a bot project, for instance, informing users about its version and updates). At the same time, I also wish to have the version
parameter imported from the project and injected into the documentation, which is the purpose of the plugin's design.
So, I'm looking to achieve a scenario where I can use format-jinja-imports
to import the version
parameter from my local project as the version information used during packaging, along with whether it's currently stable
or beta
(which the plugin supports inherently). Additionally, I want to inject this version information into the documentation.
The issue I've encountered in my GitHub ticket is that the plugin doesn't import the project as a library, but only retrieves from the site-packages
.
Since it's a dynamic version control plugin for poetry
and provides methods like format-jinja-imports
, why not include a feature that allows importing the version information from the project? I believe this could enhance the versatility of the plugin as well. Haha, of course, this is just my suggestion and thought.
The plugin does support the end result that you want to achieve, just not by using imports :)
All you need to do is:
tool.poetry-dynamic-versioning.substitution
to inject the dynamic version into your utils.py file. Example:
[tool.poetry-dynamic-versioning.substitution]
folders = [
{ path = "dicergirl/utils", files = ["utils.py"] }
]
There's also a patterns
option for using different regexes for the substitution (you'd need this if the variable is not named __version__
).
v0.1.2
), and remember to push the tag as well (git push --tags
)poetry build
, the plugin will replace __version__ = "..."
in the wheel/sdist with the version from the tagpoetry build
, they can import the version from that module like normal. Within the wheel/sdist, it will just be a simple string, without any need for the user to have the plugin.why not include a feature that allows importing the version information from the project?
The plugin has to be available at build/packaging time, where the project and its dependencies are not necessarily installed. For example, someone could clone your repository and run pip install .
(using Pip's PEP 517 support to read pyproject.toml). Pip would first create a wheel, then install the wheel. While creating the wheel, Pip will only install the minimal dependencies specified in build-system.requires
from pyproject.toml, and it will install them in an isolated environment by default. If you tried to import your project in that environment, it would probably fail due to missing dependencies.
Oh, thank you for your response. It seems like I didn't read the documentation carefully enough. Haha, I hope you don't mind my carelessness.
No worries :)
How can I use
format-jinja-imports
to import pkg from the current project? Myversion
is located atdicergirl.utils.utils.__version__
, but it seems to be importing pkg from thesite-packages
by default.