Skip to content
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

Provide access to the structured information about a version. #34

Closed
tomprince opened this issue Jun 18, 2015 · 5 comments
Closed

Provide access to the structured information about a version. #34

tomprince opened this issue Jun 18, 2015 · 5 comments

Comments

@tomprince
Copy link

@tomprince tomprince commented Jun 18, 2015

We have built some automation around releases and testing that involve inspecting the version, to determine what type of release something is, and where to publish it (etc.).

Currently we are using a regex to parse pre PEP-440 versions. I was planning on using packaging to replace this, but it appears that packaging doesn't expose this information in a structured way.

@tomprince
Copy link
Author

@tomprince tomprince commented Jun 18, 2015

It would also be nice to be able to construct versions from structured data.

@dstufft
Copy link
Member

@dstufft dstufft commented Jun 18, 2015

Can you be more specific about what you're looking for exactly? Is this specifically for pre-PEP440 versions?

@tomprince
Copy link
Author

@tomprince tomprince commented Jun 18, 2015

Is this specifically for pre-PEP440 versions?

No. We are currently parsing our pre-PEP440 version using this regex. We are planning on switching to PEP440 compatible versioning, and rather than update that regex to support the new versioning scheme, I'd like to use packaging to parse it.

It looks like the _Version named-tuple has all the information I want, but the interface perhaps isn't ideal.

@dstufft
Copy link
Member

@dstufft dstufft commented Jun 18, 2015

Ok, so you want access to things like the release segment, the epoch, etc?

@tomprince
Copy link
Author

@tomprince tomprince commented Jun 18, 2015

Yes. The following is a spike of what I was thinking (of usage)

def _parse_version(version):
    """
    Parse a version of Flocker.

    :return FlockerVersion: The parsed version.

    :raises UnparseableVersion: If the version can't be parsed as a Flocker
        version.
    """
    packaging_version = Version(version)._version
    major, minor, micro = packaging_version.release
    if packaging_version.pre:
        pre_l, pre_n = packaging_version.pre
        if pre_l == 'rc':
            pre_release = pre_n
            weekly_release = None
        elif pre_l == 'a':
            pre_release = None
            weekly_release = pre_n
    else:
        pre_release = None
        weekly_release = None
    if packaging_version.post:
        documentation_revision = packaging_version.post[1]
    else:
        documentation_revision = None
    if packaging_version.dev:
        commit_count = packaging_version.dev[1]
        assert packaging_version.local[0].startwith('gn')
        commit_hash = packaging_version.local[0][2:]
    else:
        commit_count = None
        commit_hash = None
    if packaging_version.local and len(packaging_version.local) > 1:
        dirty = packaging_version.local[1]
    else:
        dirty = None
    return FlockerVersion(
        major=major,
        minor=minor,
        micro=micro,
        pre_release=pre_release,
        weekly_release=weekly_release,
        documentation_revision=documentation_revision,
        commit_count=commit_count,
        commit_hash=commit_hash,
        dirty=dirty,
    )

di added a commit to di/packaging that referenced this issue Feb 26, 2018
@dstufft dstufft closed this in #125 Feb 28, 2018
dstufft added a commit that referenced this issue Feb 28, 2018
* [#34] Give Version structured info attributes
* Simplification of #109
* Add utils.canonicalize_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants