Skip to content

Commit 529b9da

Browse files
authored
Fix poetry with git dependencies (serverless#390)
Fix poetry with git dependencies
2 parents 647313c + 9981ba2 commit 529b9da

File tree

6 files changed

+80
-37
lines changed

6 files changed

+80
-37
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ custom:
110110
usePoetry: false
111111
```
112112

113+
### Poetry with git dependencies
114+
Poetry by default generates the exported requirements.txt file with `-e` and that breaks pip with `-t` parameter
115+
(used to install all requirements in a specific folder). In order to fix that we remove all `-e ` from the generated file but,
116+
for that to work you need to add the git dependencies in a specific way.
117+
118+
Instead of:
119+
```toml
120+
[tool.poetry.dependencies]
121+
bottle = {git = "[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
122+
```
123+
Use:
124+
```toml
125+
[tool.poetry.dependencies]
126+
bottle = {git = "https://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
127+
```
128+
Or, if you have an SSH key configured:
129+
```toml
130+
[tool.poetry.dependencies]
131+
bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
132+
```
113133

114134
## Dealing with Lambda's size limitations
115135
To help deal with potentially large dependencies (for example: `numpy`, `scipy`

lib/pip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function installRequirements(targetFolder, serverless, options) {
317317
throw res.error;
318318
}
319319
if (res.status !== 0) {
320-
throw new Error(res.stderr);
320+
throw new Error(`STDOUT: ${res.stdout}\n\nSTDERR: ${res.stderr}`);
321321
}
322322
});
323323
// If enabled slimming, delete files in slimPatterns

lib/poetry.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,26 @@ function pyprojectTomlToRequirements() {
3232
if (res.status !== 0) {
3333
throw new Error(res.stderr);
3434
}
35+
36+
const editableFlag = new RegExp(/^-e /gm);
37+
const sourceRequirements = path.join(this.servicePath, 'requirements.txt');
38+
const requirementsContents = fse.readFileSync(sourceRequirements, {
39+
encoding: 'utf-8'
40+
});
41+
42+
if (requirementsContents.match(editableFlag)) {
43+
this.serverless.cli.log(
44+
'The generated file contains -e lines, removing them...'
45+
);
46+
fse.writeFileSync(
47+
sourceRequirements,
48+
requirementsContents.replace(editableFlag, '')
49+
);
50+
}
51+
3552
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
3653
fse.moveSync(
37-
path.join(this.servicePath, 'requirements.txt'),
54+
sourceRequirements,
3855
path.join(this.servicePath, '.serverless', 'requirements.txt')
3956
);
4057
}

test.js

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ test('poetry py3.6 can package flask with default options', t => {
727727
sls(['package']);
728728
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
729729
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
730+
t.true(zipfiles.includes(`bottle.py`), 'bottle is packaged');
730731
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
731732
t.end();
732733
});

tests/poetry/poetry.lock

+39-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/poetry/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["Your Name <[email protected]>"]
77
[tool.poetry.dependencies]
88
python = "^3.6"
99
Flask = "^1.0"
10-
bottle = "^0.12.16"
10+
bottle = {git = "https://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
1111
boto3 = "^1.9"
1212

1313
[tool.poetry.dev-dependencies]

0 commit comments

Comments
 (0)