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

Make hyphen optional for prerelease suffix #130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jtcohen6
Copy link
Contributor

resolves #129

Not sure how to test this! It's been a little while since I did anything in this repo :)

Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to work on #131 (and #132) so that we can try to add some tests here before merging.

@dbeatty10 dbeatty10 mentioned this pull request Jul 23, 2022
@dbeatty10
Copy link
Contributor

Testing framework

#133 adds some simple regex tests and instructions for running them. Currently, they are crafted strictly towards SemVer 2.0, so the unit tests would need to be adjusted slightly to accommodate an optional hyphen for prerelease suffix.

Can we have it all?

Is there any way we could achieve consistency between Hubcap + db-core and have strict SemVer for dbt packages and follow PEP 440 version strings for dbt adapters?

Converting versions between PyPI and semver provides some useful commentary and code. You can see how the semver project's git tags compare to their PyPI releases:

git tag PyPI release
3.0.0-dev.3 3.0.0.dev3
3.0.0-dev.2 3.0.0.dev2
3.0.0-dev.1 3.0.0.dev1
2.13.0 2.13.0
2.12.0 2.12.0
2.11.0 2.11.0

@@ -12,7 +12,7 @@
def parse_semver_tag(tag):
'''use regexes to parse the semver tag into groups'''
# regex taken from official SEMVER documentation site
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this regex now slightly deviate from the official site? Or had it moved forward and we hadn't moved with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex in the main branch currently matches the "named groups" regular expression in SemVer 2.0.0 precisely:
^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

That regex has not changed (and probably will not change within SemVer 2.x).

This PR just adds a single character change that allows for the dash prefix for pre-releases to be optional:
Screen Shot 2022-07-26 at 9 08 31 AM

This would to allow for dbt package versions to have greater overlap with PEP 440 even though SemVer 2.0.0 doesn't allow it to be optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so my point is that if it's no longer the official SEMVER regex, we should update the comment to say something like "based on the SEMVER regex but with tweaks for PEP compatibility"

@jtcohen6
Copy link
Contributor Author

Converting versions between PyPI and semver provides some useful commentary and code.

It also makes me wonder if we should be using these packages, rather than our own regex:

from semver import Version as SemVersion
from packaging.version import Version as PyPIVersion

def parse_semver_tag(tag):
    version = SemVersion(tag) or PyPIVersion(tag) # probably needs to be try/except
    return str(version)

That's a bigger lift than what we're trying to unblock in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support prerelease identifiers without hyphens
3 participants