Skip to content

Commit

Permalink
feat(manager): Support poetry custom repositories.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Sep 21, 2019
1 parent 27fd0f9 commit 7b81ece
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/manager/poetry/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function extractPackageFile(
if (!deps.length) {
return null;
}
return { deps };

return { deps, registryUrls: extractRegistries(pyprojectfile) };
}

function extractFromSection(
Expand Down Expand Up @@ -84,3 +85,20 @@ function extractFromSection(
});
return deps;
}

function extractRegistries(pyprojectfile: PoetryFile): string[] {
const sources = pyprojectfile.tool.poetry.source;

if (!Array.isArray(sources)) {
return [];
}

const registryUrls: string[] = [];
for (const source of sources) {
if (source.url) {
registryUrls.push(source.url);
}
}

return registryUrls;
}
6 changes: 6 additions & 0 deletions lib/manager/poetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface PoetrySection {
dependencies: Record<string, PoetryDependency | string>;
'dev-dependencies': Record<string, PoetryDependency | string>;
extras: Record<string, PoetryDependency | string>;
source?: PoetrySource[];
}

export interface PoetryFile {
Expand All @@ -15,3 +16,8 @@ export interface PoetryDependency {
git?: string;
version?: string;
}

export interface PoetrySource {
name?: string;
url?: string;
}
7 changes: 7 additions & 0 deletions test/manager/poetry/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ Array [
]
`;

exports[`lib/manager/poetry/extract extractPackageFile() extracts registries 1`] = `
Array [
"https://foo.bar/simple/",
"https://bar.baz/+simple/",
]
`;

exports[`lib/manager/poetry/extract extractPackageFile() handles multiple constraint dependencies 1`] = `
Array [
Object {
Expand Down
16 changes: 16 additions & 0 deletions test/manager/poetry/_fixtures/pyproject.6.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "example 6"
version = "0.1.0"
description = ""
authors = ["John Doe <[email protected]>"]

[tool.poetry.dependencies]
dep0 = "0.0.0"

[[tool.poetry.source]]
name = "foo"
url = "https://foo.bar/simple/"

[[tool.poetry.source]]
name = "bar"
url = "https://bar.baz/+simple/"
10 changes: 10 additions & 0 deletions test/manager/poetry/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const pyproject5toml = readFileSync(
'utf8'
);

const pyproject6toml = readFileSync(
'test/manager/poetry/_fixtures/pyproject.6.toml',
'utf8'
);

describe('lib/manager/poetry/extract', () => {
describe('extractPackageFile()', () => {
let config;
Expand Down Expand Up @@ -57,6 +62,11 @@ describe('lib/manager/poetry/extract', () => {
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
});
it('extracts registries', () => {
const res = extractPackageFile(pyproject6toml, config);
expect(res.registryUrls).toMatchSnapshot();
expect(res.registryUrls).toHaveLength(2);
});
it('skips git dependencies', () => {
const content =
'[tool.poetry.dependencies]\r\nflask = {git = "https://github.com/pallets/flask.git"}\r\nwerkzeug = ">=0.14"';
Expand Down

0 comments on commit 7b81ece

Please sign in to comment.