Skip to content

Commit

Permalink
replace complex regex with @renovate/pep440
Browse files Browse the repository at this point in the history
solves review #9516 (comment)
  • Loading branch information
jNullj committed Sep 5, 2023
1 parent e2ecbf5 commit b3de30f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions services/python/python-version-from-toml.tester.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Joi from 'joi'
import pep440 from '@renovate/pep440'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

const isCommaSeparatedPythonVersions = Joi.string().regex(
// This should test for PEP440
// Accepted values are one or more Version specifiers as defined at https://peps.python.org/pep-0440/#version-specifiers
// Some strings might include spaces, those are valid, values are comma seperated
// Versions should fit the version scheme https://peps.python.org/pep-0440/#version-scheme
// This is based on the example in PEP440 at https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
/^\s*(?:(?:===|!=|<=|>=|<|>)\s*)?((?:(?:\d+!)?(?:\d+(?:\.\d+)*))(?:(?:[abc]|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?)(?:\s*,\s*(?:(?:===|!=|<=|>=|<|>)\s*)?((?:(?:\d+!)?(?:\d+(?:\.\d+)*))(?:(?:[abc]|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?))*\s*$/,
)
const validatePep440 = (value, helpers) => {
if (!pep440.validRange(value)) {
return helpers.error('any.invalid')
}
return value
}

const isCommaSeparatedPythonVersions = Joi.string().custom(validatePep440)

t.create('python versions (valid)')
.get(
Expand Down

0 comments on commit b3de30f

Please sign in to comment.