Skip to content
Snippets Groups Projects
Unverified Commit d3a7afde authored by Samuel FORESTIER's avatar Samuel FORESTIER Committed by GitHub
Browse files

[PyPI] Fixes Python versions order by using proper Semver comparison (#6000)


* [PyPI] Fixes Python versions order by using proper Semver comparison

* [PyPI] Adds a proper specification file for Python versions service

Co-authored-by: default avatarrepo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
parent 79ff8255
No related branches found
No related tags found
No related merge requests found
'use strict'
const semver = require('semver')
const PypiBase = require('./pypi-base')
const { parseClassifiers } = require('./pypi-helpers')
......@@ -30,7 +31,11 @@ module.exports = class PypiPythonVersions extends PypiBase {
})
if (versionSet.size) {
return {
message: Array.from(versionSet).sort().join(' | '),
message: Array.from(versionSet)
.sort((v1, v2) =>
semver.compare(semver.coerce(v1), semver.coerce(v2))
)
.join(' | '),
color: 'blue',
}
} else {
......
'use strict'
const { test, given } = require('sazerac')
const { render } = require('./pypi-python-versions.service')
describe('PyPI Python Version', function () {
test(render, function () {
// Major versions are hidden if minor are present.
given({ versions: ['3', '3.4', '3.5', '3.6', '2', '2.7'] }).expect({
message: '2.7 | 3.4 | 3.5 | 3.6',
color: 'blue',
})
// Major versions are shown when minor are missing.
given({ versions: ['2', '3'] }).expect({
message: '2 | 3',
color: 'blue',
})
// Versions are properly sorted according to their Semver segments.
given({ versions: ['3.10', '3.9', '3.8', '3.7', '3.6'] }).expect({
message: '3.6 | 3.7 | 3.8 | 3.9 | 3.10',
color: 'blue',
})
// Only "one" version works too.
given({ versions: ['3', '3.9'] }).expect({
message: '3.9',
color: 'blue',
})
// Versions are missing...
given({ versions: [] }).expect({
message: 'missing',
color: 'red',
})
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment