2

so similar to question in link I want to specify version within pyproject.toml and use that within code (eg for package var _version__)

I wanted to use solution as specified like below to

import importlib.metadata

__version__ = importlib_metadata.version(__package__ or __name__)

one issue I seem to be running into though is that if editable install (ie pip install -e .) and update the pyproject.toml project.version this wont be automatically reflected in __version__. is there way to get such behavior?

kamster
  • 139
  • 6
  • 1
    I would argue that there is no need for this `__version__` at all. If a 3rd party library (or application) needs to know at run-time the version string for your own library, then it is the responsibility of this 3rd party library to retrieve this value. -- And to answer your question, as far as I know, no it is not possible to for and editable installation to automatically get its version updated. It is necessary to re-trigger the editable install process after each modification of the version string in `pyproject.toml`. – sinoroc Nov 16 '22 at 09:43
  • @sinoroc so actually this is for library i am making (wanting to add as part of the library, helpful for command line interfaces, etc to display what version, and just ideally i'd specify in the pyproject.toml and inheret here). – kamster Nov 16 '22 at 14:12
  • with that from research i have done seeing what you are saying "necessary to re-trigger the editable install process after each modification of the version string in pyproject.toml" so if i desire what i want seems i may just need to maintain in two places (or just accept it wont be updated unless re-install), hoping not case but seeming like it – kamster Nov 16 '22 at 14:13
  • If the metadata of the library changes (this includes the version string), then the project needs to be installed again, even for editable installations. -- If library (or application) `A` needs to know the version string of library `B` (your library), then `A` needs to call `importlib.metadata.version('A')`. That's it, simple, no need to rely on a `__version__` variable that may or may not be there. – sinoroc Nov 16 '22 at 17:15
  • sorry my question perhaps wasnt specific on this but this is for library/package i am creating, the setting of `__version__` is more for convience (but question still holds), which think how you answered basically answer question, the importlib.metadata.version(...) will pull the meta data of installed so if editable installed and what latest version that i may define for my package in pyproject.toml must re-install. thanks for help! – kamster Nov 16 '22 at 21:00

0 Answers0