import * as pep440 from '@renovatebot/pep440' ; import type { VersioningApi } from '../types' ; import { getNewValue , isLessThanRange } from './range' ; export const id = 'pep440' ; export const displayName = 'PEP440' ; export const urls = [ 'https://www.python.org/dev/peps/pep-0440/' ] ; export const supportsRanges = true ; export const supportedRangeStrategies = [ 'bump' , 'extend' , 'pin' , 'replace' ] ; const { compare : sortVersions , satisfies : matches , valid , validRange , explain , gt : isGreaterThan , major : getMajor , minor : getMinor , patch : getPatch , eq , } = pep440 ; function isVersion ( input ) { return ! ! valid ( input ) ; } const isStable = ( input ) : boolean => { const version = explain ( input ) ; if ( ! version ) { return false ; } return ! version . is_prerelease ; } ; export function isValid ( input ) { return validRange ( input ) || isVersion ( input ) ; } function getSatisfyingVersion ( versions , range ) { const found = pep440 . filter ( versions , range ) . sort ( sortVersions ) ; return found . length === 0 ? null : found [ found . length - 1 ] ; } function minSatisfyingVersion ( versions , range ) { const found = pep440 . filter ( versions , range ) . sort ( sortVersions ) ; return found . length === 0 ? null : found [ 0 ] ; } export function isSingleVersion ( constraint ) { return ( isVersion ( constraint ) || ( constraint ?. startsWith ( '==' ) && isVersion ( constraint . substring ( 2 ) . trim ( ) ) ) ) ; } export { isVersion , matches } ; const equals = ( version1 , version2 ) : boolean => isVersion ( version1 ) && isVersion ( version2 ) && eq ( version1 , version2 ) ; export const api = { equals , getMajor , getMinor , getPatch , isCompatible : isVersion , isGreaterThan , isSingleVersion , isStable , isValid , isVersion , matches , getSatisfyingVersion , minSatisfyingVersion , getNewValue , sortVersions , isLessThanRange , } ; export default api ;