Skip to content
Snippets Groups Projects
Select Git revision
  • ee1f70841c2979ee5fe080fbedfe7b8428f77bb6
  • main default protected
  • release/v2.6.x
  • dependabot/github_actions/ci-3649212e03
  • conform-k8s-1.33
  • rfc-external-artifact
  • release/v2.5.x
  • release/v2.4.x
  • remove-notation-validation
  • release/v2.3.x
  • release/v2.2.x
  • RFC
  • fix-commit-log
  • flux-audit
  • release/v2.1.x
  • context-ns
  • ksm-dashboard
  • rfc-passwordless-git-auth
  • release/v2.0.x
  • rfc-gating
  • release/v0.27.4
  • v2.6.2 protected
  • v2.6.1 protected
  • v2.6.0 protected
  • v2.5.1 protected
  • v2.5.0 protected
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.3 protected
  • v2.2.2 protected
  • v2.2.1 protected
  • v2.2.0 protected
  • v2.1.2 protected
  • v2.1.1 protected
  • v2.1.0 protected
  • v2.0.1 protected
  • v2.0.0 protected
  • v2.0.0-rc.5 protected
  • v2.0.0-rc.4 protected
  • v2.0.0-rc.3 protected
  • v2.0.0-rc.2 protected
41 results

manifests.go

Blame
  • index.ts 2.39 KiB
    import * as pep440 from '@renovatebot/pep440';
    import type { RangeStrategy } from '../../../types/versioning';
    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: RangeStrategy[] = [
      'bump',
      'widen',
      'pin',
      'replace',
    ];
    
    const {
      compare: sortVersions,
      satisfies,
      valid,
      validRange,
      explain,
      gt: isGreaterThan,
      major: getMajor,
      minor: getMinor,
      patch: getPatch,
      eq,
    } = pep440;
    
    function isVersion(input: string | undefined | null): boolean {
      // @renovatebot/pep440 isn't strict null save
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
      return !!valid(input!);
    }
    
    const isStable = (input: string): boolean => {
      const version = explain(input);
      if (!version) {
        return false;
      }
      return !version.is_prerelease;
    };
    
    // If this is left as an alias, inputs like "17.04.0" throw errors
    export function isValid(input: string): boolean {
      return validRange(input) || isVersion(input);
    }
    
    function getSatisfyingVersion(
      versions: string[],
      range: string,
    ): string | null {
      const found = pep440.filter(versions, range).sort(sortVersions);
      return found.length === 0 ? null : found[found.length - 1];
    }
    
    function minSatisfyingVersion(
      versions: string[],
      range: string,
    ): string | null {
      const found = pep440.filter(versions, range).sort(sortVersions);
      return found.length === 0 ? null : found[0];
    }
    
    export function isSingleVersion(constraint: string): boolean {
      return (
        isVersion(constraint) ||
        (constraint?.startsWith('==') && isVersion(constraint.substring(2).trim()))
      );
    }
    
    export { isVersion, matches };
    
    const equals = (version1: string, version2: string): boolean =>
      isVersion(version1) && isVersion(version2) && eq(version1, version2);
    
    function matches(version: string, range: string): boolean {
      return isVersion(version) && isValid(range) && satisfies(version, range);
    }
    
    export const api: VersioningApi = {
      equals,
      getMajor,
      getMinor,
      getPatch,
      isCompatible: isVersion,
      isGreaterThan,
      isSingleVersion,
      isStable,
      isValid,
      isVersion,
      matches,
      getSatisfyingVersion,
      minSatisfyingVersion,
      getNewValue,
      sortVersions,
      isLessThanRange,
    };
    
    export default api;