mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
607 stars 35 forks source link

Importing Local Project #142

Closed fu050409 closed 1 year ago

fu050409 commented 1 year ago

How can I use format-jinja-imports to import pkg from the current project? My version is located at dicergirl.utils.utils.__version__, but it seems to be importing pkg from the site-packages by default.

fu050409 commented 1 year ago

Alternatively, is there a method to extract __version__ from a specific .py file within my project for packaging?

mtkennerly commented 1 year ago

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?

fu050409 commented 1 year ago

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.

fu050409 commented 1 year ago

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.

mtkennerly commented 1 year ago

The plugin does support the end result that you want to achieve, just not by using imports :)

All you need to do is:

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.

fu050409 commented 1 year ago

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.

mtkennerly commented 1 year ago

No worries :)