Skip to content

Commit

Permalink
fix(poetry): add versioning resilience (#9838)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 4, 2021
1 parent f88529a commit 05b25d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/versioning/poetry/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ describe(getName(__filename), () => {
it('handles wildcards', () => {
expect(versionig.matches('4.2.0', '*')).toBe(true);
});
it('handles short', () => {
expect(versionig.matches('1.4', '1.4')).toBe(true);
});
});
describe('isLessThanRange()', () => {
it('handles comma', () => {
Expand Down
15 changes: 8 additions & 7 deletions lib/versioning/poetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseRange } from 'semver-utils';
import { logger } from '../../logger';
import { api as npm } from '../npm';
import { api as pep440 } from '../pep440';
import type { NewValueConfig, VersioningApi } from '../types';

export const id = 'poetry';
Expand Down Expand Up @@ -67,17 +68,16 @@ function npm2poetry(input: string): string {
return res.join(', ').replace(/\s*,?\s*\|\|\s*,?\s*/, ' || ');
}

const equals = (a: string, b: string): boolean =>
npm.equals(padZeroes(a), padZeroes(b));
const equals = (a: string, b: string): boolean => pep440.equals(a, b);

const getMajor = (version: string): number => npm.getMajor(padZeroes(version));
const getMajor = (version: string): number => pep440.getMajor(version);

const getMinor = (version: string): number => npm.getMinor(padZeroes(version));
const getMinor = (version: string): number => pep440.getMinor(version);

const getPatch = (version: string): number => npm.getPatch(padZeroes(version));
const getPatch = (version: string): number => pep440.getPatch(version);

const isGreaterThan = (a: string, b: string): boolean =>
npm.isGreaterThan(padZeroes(a), padZeroes(b));
pep440.isGreaterThan(a, b);

const isLessThanRange = (version: string, range: string): boolean =>
npm.isLessThanRange(padZeroes(version), poetry2npm(range));
Expand All @@ -90,8 +90,9 @@ const isStable = (version: string): boolean =>

const isVersion = (input: string): string | boolean =>
npm.isVersion(padZeroes(input));

const matches = (version: string, range: string): boolean =>
npm.matches(version, poetry2npm(range));
npm.matches(padZeroes(version), poetry2npm(range));

const getSatisfyingVersion = (versions: string[], range: string): string =>
npm.getSatisfyingVersion(versions, poetry2npm(range));
Expand Down

0 comments on commit 05b25d4

Please sign in to comment.