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

Check version bump severity or implement subtraction #102

Open
ewen-lbh opened this issue Jun 29, 2020 · 0 comments
Open

Check version bump severity or implement subtraction #102

ewen-lbh opened this issue Jun 29, 2020 · 0 comments

Comments

@ewen-lbh
Copy link

ewen-lbh commented Jun 29, 2020

I needed to check for a breaking change in my program and made the following utility function:

from semantic_version import Version

def is_change_breaking(from_version: Version, to_version: Version) -> bool:
	return from_version.major != to_version.major

And I thought that this would be an easy addition to the library, although using operators directly seems more "pure":

class Version(idk from what it inherits):
	...
    def is_change_major(self, other: 'Version') -> bool:
        return self.major != other.major
    
    def is_change_minor(self, other: 'Version') -> bool:
        return self.minor != other.minor
    
    def is_change_patch(self, other: 'Version') -> bool:
        return self.patch != other.patch
	...

And I also thought about just implementing subtraction, so you could check the difference in the number of patches, minor and/or major bumps:

>>> from semantic_version import Version
>>> Version('1.0.8') - Version('4.5.8')
VersionDifference(major=3, minor=-5, patch=0)

So that checking for breaking changes would be:

...
if (upgrade_from - upgrade_to).major:
	print("Warning: breaking change(s) ahead!")
...

I haven't though about how to handle prereleases/build versions but I think it may be a nice addition (especially the second solution, which feels more "pythonic" to me) but of course using v_a.major != v_b.major is plenty enough too.

Just wanted to throw this idea here :)

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

No branches or pull requests

1 participant