Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(poetry): add versioning resilience #9838

Merged
merged 3 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(), () => {
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