question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use case: Introduce VersionInfo.coerce

See original GitHub issue

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:

@classmethod
def coerce(cls, version):
    """
    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.

    :param str version: the version string to convert
    :return: a tuple with a :class:`VersionInfo` instance (or ``None``
        if it's not a version) and the rest of the string which doesn't
        belong to a basic version.
    :rtype: tuple(:class:`VersionInfo` | None, str)
    """

I’ve chosen coerce as it is a common function name in other semver implementations, for example, node-semver.

An example session:

>>> import semver
>>> semver.VersionInfo.coerce("v1.2")
(VersionInfo(major=1, minor=2, patch=0, prerelease=None, build=None), '')
>>> semver.VersionInfo.coerce("3.5rc1")
(VersionInfo(major=3, minor=5, patch=0, prerelease=None, build=None), 'rc1')

Questions:

  • Do you you think such a function could be useful?
  • Should the coerce function accept an integer value (=major)? So coerce(2) would be the same as coerce("2") which would return VersionInfo(major=2, minor=0, patch=0, prerelease=None, build=None).
  • Anything else you miss, would change, …?

See also

This issue is related to #137

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
scls19frcommented, Jan 19, 2020

I think that’s enough for now. Thanks @tomschr for your contribution.

0reactions
tomschrcommented, Jan 19, 2020

@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 coerce() function as an example.

It’s a start, I’m not sure if this is enough. What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

XML Query Use Cases - W3C
1.9 Use Case "STRONG" - queries that exploit strongly typed data ... The use cases listed below were created by the XML Query...
Read more >
Version Control: A Good Practice Guide - University of Glasgow
Version control is the process by which different drafts and versions of a document or record are managed. It is a tool which...
Read more >
Coercion Theory: A Basic Introduction for Practitioners
While coercion theory may be well understood in the academy, it is less well understood by practitioners, especially in the military.
Read more >
An Introduction to Convert2RHEL: Now officially supported to ...
Flexibility- Convert2RHEL can now access RHEL content via multiple methods depending on your use case.
Read more >
Extract/Introduce variable | IntelliJ IDEA Documentation
You can use the Introduce Variable refactoring to extract variadic arguments into a new slice variable. In the editor, select an expression or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found