Skip to content

Conversation

PlayerIUnknown
Copy link

Overview

This pull request introduces support for Swift's native version ranges within the Univers project. Swift utilizes semantic versioning, and this update enables the handling of Swift package manager's specific version range declarations effectively. The update includes parsing logic for Swift version ranges and corresponding unit tests to ensure functionality adheres to Swift's versioning specifications.

Details

Swift's package manager allows specifying dependencies with various version range formats. This implementation supports the following native Swift version range specifications:

  • Exact Version: Specified using exact: "X.Y.Z", where the dependency must match an exact version.
  • From Version: Specified using from: "X.Y.Z", indicating a minimum version up to the next major version but not including.
  • Range with Upper Bound:
    • Exclusive Upper Bound: Using "X.Y.Z"..<"A.B.C" to specify a range including the lower bound but excluding the upper bound.
    • Inclusive Upper Bound: Using "X.Y.Z"..."A.B.C" to specify a range including both the lower and upper bounds.

Modifications

  • SwiftVersionRange Class: A new class to parse and handle Swift version ranges, integrated into the Univers versioning system.
  • Unit Tests: Comprehensive tests are added in tests/test_swift_versions.py to verify parsing and handling of all supported version range specifications.

Example Usage

The SwiftVersionRange can be instantiated with a Swift version range string:

vr = SwiftVersionRange('from: "1.2.3"')

This will parse and prepare constraints that ensure compatibility checks against provided Swift package versions.

Testing

Unit tests cover:

  • Exact version match
  • Version ranges starting from a specific version up to but not including the next major version
  • Exclusive and inclusive upper bounds in version ranges

Impact

This update allows developers using the Univers project to integrate Swift packages more seamlessly, adhering to Swift's native versioning schemes. It enhances the versatility of the Univers version range handling and ensures better cross-platform package management compatibility.

@PlayerIUnknown
Copy link
Author

This solves the issue : "Add support for swift vers range" #132. Urging maintainers to review it.

Copy link
Member

@keshav-space keshav-space left a comment

Choose a reason for hiding this comment

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

Thanks @PlayerIUnknown, see some suggestions below. Also make sure to go through the base VersionRange definition and take a look at other version range implementations like ConanVersionRange and NpmVersionRange.

Copy link
Member

Choose a reason for hiding this comment

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

This should not be here, it belongs in version_range.py.

class SwiftVersionRange(VersionRange):
expression: str
scheme: str = "swift"
version_class: type = SwiftVersion
Copy link
Member

Choose a reason for hiding this comment

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

How about using SemverVersion, if that's what the Swift version is?

Suggested change
version_class: type = SwiftVersion
version_class: type = versions.SemverVersion

Comment on lines +15 to +16
def __attrs_post_init__(self):
object.__setattr__(self, "constraints", self.parse(self.expression))
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Aren’t we already taking care of it in the base VersionRange class?

Comment on lines +18 to +19
@staticmethod
def parse(expression):
Copy link
Member

Choose a reason for hiding this comment

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

This isn’t correct, you need to implement from_native.

Comment on lines +56 to +57
def __str__(self):
return f"vers:swift/{'|'.join([c.to_string() for c in self.constraints])}"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason why we need to override the base str for swift?

@@ -0,0 +1,38 @@
import unittest
Copy link
Member

Choose a reason for hiding this comment

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

Do you links to actual example of these version ranges seen in the wild?

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.

3 participants