-
Notifications
You must be signed in to change notification settings - Fork 97
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
Use case: Introduce VersionInfo.coerce #210
Comments
Signature: VersionInfo.coerce(cls, version:str) -> tuple Convert an incomplete version string into a semver-compatible VersionInfo object - Tries to detect a "basic" version string (``major.minor.patch``). - If not enough components can be found, missing components are set to zero to obtain a valid semver version.
Signature: * VersionInfo.coerce(cls, version:str) -> tuple Convert an incomplete version string into a semver-compatible VersionInfo object - Tries to detect a "basic" version string (``major.minor.patch``). - If not enough components can be found, missing components are set to zero to obtain a valid semver version. * Update CHANGELOG.rst
To be honest - I'm not sure about this. Generally speaking it's a quite nice feature, but it's for someone who doesn't use semver correctly and I wonder if we should support such "non-semver" behavior. Parsing versions in non-trivial task and there are a lot of problems with different version formats :) |
Thanks Karl for your feedback! 👍 I agree, parsing a version can be difficult. However, when I've created this idea, I had one use case in my mind: what does a developer do when he has to deal with a invalid version string that he or she doesn't control? How do we convert such invalid version into a valid semver version? Currently, we don't have a solution. Sure, the developer could do some "manual massaging" of the version string, but is that a good idea? Isn't that the task for a library (in this specific case: semver)? With this PR we have an idea to discuss. 😉 I see this Additionally, this function focuses on one very narrow definition of a version string: major and optional minor and/or patch. There are no prereleases or build and that's on purpose. If there are further information, this is returned as the second item. If it turns out that it is actually not needed, I'm absolutely fine with closing this PR. Hope that clarifies it a bit. |
@tomschr I see your point and I didn't mean to sound negative in my previous post - I only wanted to raise my concerns. If we are going to use such "lenient" approach (like in mentioned in #137) it would be a very nice feature. I'm a bit worried, however, that we may run into supporting some different and weird version formats (like mentioned in PEP 386 |
@ppkt I see your point Karol. Don't worry, you didn't sound negative. 😄 👍 I agree, we shouldn't support "weird" version formats (well, what's "weird" is probably open for discussion). We can't support them all. On the other hand, should we "support" the conversion of some common ones at least (like the mentioned My concern is that we leave our developers in the dark when someone has to deal with "invalid" versions. What would be your solution when dealing with such versions? I'm totally fine if we close this PR, but then we should clearly document the scope of this project and library. Additionally, we should give some recommendations what the developer could do in such a case. Does this makes sense? 😉 |
@ppkt I just had another idea, similar to my last comment: 💡 If you fear we support "weird" versions when we merge this PR, why not just document how to deal with invalid/weird versions? For example, we could introduce a new section "Dealing with Invalid Versions" in our documentation where we could add this Would that be an option? @scls19fr What do you think? Which one would you prefer? 😉 |
Signature: * VersionInfo.coerce(cls, version:str) -> tuple Convert an incomplete version string into a semver-compatible VersionInfo object - Tries to detect a "basic" version string (``major.minor.patch``). - If not enough components can be found, missing components are set to zero to obtain a valid semver version. * Update CHANGELOG.rst
@python-semver/reviewers Any new opinions on this issue? Just to summarize the two alternative approaches: a. use the |
+1 about documenting |
* Document how to deal with invalid versions * Use coerce(version) as an example
@scls19fr Ok, let's document this. 👍 I've opened PR #215 and introduced a new section "Dealing with Invalid Versions". There I've used a modified It's a start, I'm not sure if this is enough. What do you think? |
* Document how to deal with invalid versions * Use coerce(version) as an example * Update CHANGELOG.rst
I think that's enough for now. |
Situation
Currently, if you parse a version string into a valid semver version, the version string has to consist of at least the major, minor, and patch parts.
However, in some use cases some parts could be missing, for example the patch part.
Proposed Solution
I propose a classmethod
VersionInfo.coerce
with the following signature:I've chosen
coerce
as it is a common function name in other semver implementations, for example, node-semver.An example session:
Questions:
coerce
function accept an integer value (=major)? Socoerce(2)
would be the same ascoerce("2")
which would returnVersionInfo(major=2, minor=0, patch=0, prerelease=None, build=None)
.See also
This issue is related to #137
The text was updated successfully, but these errors were encountered: