Skip to content

Commit 6f32988

Browse files
committed
Compare Scala versions of MavenCoordinates
This is to ensure that artifacts that have a newer Scala version encoded in the artifact name are considered newer. This takes precedence over whether the artifact version numbers match. Extracted `__compare_versions` from `is_newer_than` to reuse the same code for comparing Scala versions and artifact versions. Properly reversed the use of `lhs` and `rhs` in the process.
1 parent 8cb8279 commit 6f32988

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

scripts/create_repository.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class MavenCoordinates:
168168
# The `artifact` with the Scala version suffix stripped
169169
unversioned_artifact: str
170170

171+
# The Scala version suffix stripped from `unversioned_artifact`
172+
scala_version: str
173+
171174
# Canonical name for comparing new and existing artifacts
172175
artifact_name: str
173176

@@ -195,6 +198,7 @@ def new(coords) -> Self:
195198
# the same, causing one version to replace the other on consecutive
196199
# runs.
197200
artifact_parts = artifact.rsplit('_', 1)
201+
scala_version = ''
198202

199203
if len(artifact_parts) != 1:
200204
version_suffix = artifact_parts[-1]
@@ -203,12 +207,19 @@ def new(coords) -> Self:
203207
# "Nobody knows."
204208
# See: https://youtu.be/JYqfVE-fykk (couldn't resist!)
205209
if version_suffix.split('.')[0].isdigit():
210+
scala_version = version_suffix
206211
del artifact_parts[-1]
207212

208213
unversioned_artifact = '_'.join(artifact_parts)
209214
artifact_name = f'{group}:{unversioned_artifact}'
210215
return MavenCoordinates(
211-
group, artifact, vers, coords, unversioned_artifact, artifact_name
216+
group,
217+
artifact,
218+
vers,
219+
coords,
220+
unversioned_artifact,
221+
scala_version,
222+
artifact_name,
212223
)
213224

214225
def is_newer_than(self, other):
@@ -233,18 +244,23 @@ def is_newer_than(self, other):
233244
f'Expected {self.group}:{self.artifact}, ' +
234245
f'got {other.group}:{other.artifact}'
235246
)
247+
return (
248+
self.__compare_versions(other.scala_version, self.scala_version) or
249+
self.__compare_versions(other.version, self.version)
250+
)
236251

237-
lhs_parts = self.version.split(".")
238-
rhs_parts = other.version.split(".")
252+
def __compare_versions(self, lhs, rhs):
253+
lhs_parts = lhs.split('.')
254+
rhs_parts = rhs.split('.')
239255

240256
for lhs_part, rhs_part in zip(lhs_parts, rhs_parts):
241257
if lhs_part == rhs_part:
242258
continue
243259
if lhs_part.isdecimal() and rhs_part.isdecimal():
244-
return int(rhs_part) < int(lhs_part)
245-
return rhs_part < lhs_part
260+
return int(lhs_part) < int(rhs_part)
261+
return lhs_part < rhs_part
246262

247-
return len(rhs_parts) < len(lhs_parts)
263+
return len(lhs_parts) < len(rhs_parts)
248264

249265

250266
@dataclass

0 commit comments

Comments
 (0)