From 7b81ece2ce976432b9132fce13b15475e58745e7 Mon Sep 17 00:00:00 2001 From: Gilbert Gilb's Date: Sat, 21 Sep 2019 16:49:59 +0200 Subject: [PATCH] feat(manager): Support poetry custom repositories. See https://poetry.eustace.io/docs/repositories/#install-dependencies-from-a-private-repository Closes #4523 --- lib/manager/poetry/extract.ts | 20 ++++++++++++++++++- lib/manager/poetry/types.ts | 6 ++++++ .../poetry/__snapshots__/extract.spec.ts.snap | 7 +++++++ .../manager/poetry/_fixtures/pyproject.6.toml | 16 +++++++++++++++ test/manager/poetry/extract.spec.ts | 10 ++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/manager/poetry/_fixtures/pyproject.6.toml diff --git a/lib/manager/poetry/extract.ts b/lib/manager/poetry/extract.ts index 6461754b6fc245..b091e24e631754 100644 --- a/lib/manager/poetry/extract.ts +++ b/lib/manager/poetry/extract.ts @@ -28,7 +28,8 @@ export function extractPackageFile( if (!deps.length) { return null; } - return { deps }; + + return { deps, registryUrls: extractRegistries(pyprojectfile) }; } function extractFromSection( @@ -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; +} diff --git a/lib/manager/poetry/types.ts b/lib/manager/poetry/types.ts index e409718d83cdfe..1e8189433ab510 100644 --- a/lib/manager/poetry/types.ts +++ b/lib/manager/poetry/types.ts @@ -2,6 +2,7 @@ export interface PoetrySection { dependencies: Record; 'dev-dependencies': Record; extras: Record; + source?: PoetrySource[]; } export interface PoetryFile { @@ -15,3 +16,8 @@ export interface PoetryDependency { git?: string; version?: string; } + +export interface PoetrySource { + name?: string; + url?: string; +} diff --git a/test/manager/poetry/__snapshots__/extract.spec.ts.snap b/test/manager/poetry/__snapshots__/extract.spec.ts.snap index dae3171c559d1a..494fbfa96e991a 100644 --- a/test/manager/poetry/__snapshots__/extract.spec.ts.snap +++ b/test/manager/poetry/__snapshots__/extract.spec.ts.snap @@ -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 { diff --git a/test/manager/poetry/_fixtures/pyproject.6.toml b/test/manager/poetry/_fixtures/pyproject.6.toml new file mode 100644 index 00000000000000..40d18d467eac47 --- /dev/null +++ b/test/manager/poetry/_fixtures/pyproject.6.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "example 6" +version = "0.1.0" +description = "" +authors = ["John Doe "] + +[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/" \ No newline at end of file diff --git a/test/manager/poetry/extract.spec.ts b/test/manager/poetry/extract.spec.ts index 17b792c08edff6..a583212575c538 100644 --- a/test/manager/poetry/extract.spec.ts +++ b/test/manager/poetry/extract.spec.ts @@ -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; @@ -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"';