You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have a simple text file in my repo, named "version", which contains only the semantic version number of the project. This could then be consumed by every place in the code that needs to know the package number.
For example, I may need it for the version attribute of the package, again for the documentation, and again for the Pip or Conda packaging configuration. Having all these share a single, simple source for the version number would make it easy to update the version number. It would also make it easy to get the version number for tools and packages written in other languages since it is stored as a simple text file that almost all languages can read. Especially since you have a CLI that would make it easy to use with other languages also.
Possible Solution/Idea
I propose adding a static or class method "open" which takes a string or path object pointing to the version file. The version file will only contain the semantic version. The method will read in the file and return a Version object.
Additional context
While it seems easy enough to open the file and pass it to the Version constructor as a string, this would require adding scripts or modules to each project to add this basic functionality. Python is all about "batteries included", right?
It should be as simple as the following first draft of the function. It would need to be converted to a static or class method of the Version class.
fromsemver.versionimportVersiondefget_version(file_path: str="./version") ->Version:
""" Construct a Version from a file Args: file_path: A text file only containing the semantic version Returns: A Version object containing the semantic version from the file. """withopen(file_path,"r") asfile:
version=file.read()
returnVersion.parse(version)
I'm not sure if this specific use case is appropriate for the Version class. It sounds a bit too special for my taste. I would prefer to keep the class as small as possible.
From my gut feelings, this would be an example of a customization by a user. I'd add it to the documentation of how to customize the class.
However, that's my taste and I could be wrong. Maybe you have some convincing arguments why this could be useful for more people?
Activity
curtisma commentedon Aug 27, 2021
It should be as simple as the following first draft of the function. It would need to be converted to a static or class method of the Version class.
tomschr commentedon Aug 31, 2021
Thanks @curtisma for your idea!
I'm not sure if this specific use case is appropriate for the
Versionclass. It sounds a bit too special for my taste. I would prefer to keep the class as small as possible.From my gut feelings, this would be an example of a customization by a user. I'd add it to the documentation of how to customize the class.
However, that's my taste and I could be wrong. Maybe you have some convincing arguments why this could be useful for more people?
@tlaferriere What do you think?
Add topic to read version from file
curtisma commentedon Feb 26, 2022
Awesome, thanks!