Skip to content

Fix poetry with git dependencies #362

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ custom:
usePoetry: false
```

### Poetry with git dependencies
Poetry by default generates the exported requirements.txt file with `-e` and that breaks pip with `-t` parameter
(used to install all requirements in a specific folder). In order to fix that we remove all `-e ` from the generated file but,
for that to work you need to add the git dependencies in a specific way.

Instead of:
```toml
[tool.poetry.dependencies]
bottle = {git = "[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
```
it has to be:
```toml
[tool.poetry.dependencies]
bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
```

## Dealing with Lambda's size limitations
To help deal with potentially large dependencies (for example: `numpy`, `scipy`
Expand Down
2 changes: 1 addition & 1 deletion lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function installRequirements(targetFolder, serverless, options) {
throw res.error;
}
if (res.status !== 0) {
throw new Error(res.stderr);
throw new Error(`STDOUT: ${res.stdout}\n\nSTDERR: ${res.stderr}`);
}
});
// If enabled slimming, delete files in slimPatterns
Expand Down
19 changes: 18 additions & 1 deletion lib/poetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ function pyprojectTomlToRequirements() {
if (res.status !== 0) {
throw new Error(res.stderr);
}

const editableFlag = new RegExp(/^-e /gm);
const sourceRequirements = path.join(this.servicePath, 'requirements.txt');
const requirementsContents = fse.readFileSync(sourceRequirements, {
encoding: 'utf-8'
});

if (requirementsContents.match(editableFlag)) {
this.serverless.cli.log(
'The generated file contains -e lines, removing them...'
);
fse.writeFileSync(
sourceRequirements,
requirementsContents.replace(editableFlag, '')
);
}

fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
fse.moveSync(
path.join(this.servicePath, 'requirements.txt'),
sourceRequirements,
path.join(this.servicePath, '.serverless', 'requirements.txt')
);
}
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ test('poetry py3.6 can package flask with default options', t => {
sls(['package']);
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
t.true(zipfiles.includes(`bottle.py`), 'bottle is packaged');
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
t.end();
});
Expand Down
54 changes: 29 additions & 25 deletions tests/poetry/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/poetry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Your Name <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.6"
Flask = "^1.0"
bottle = "^0.12.16"
bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
boto3 = "^1.9"

[tool.poetry.dev-dependencies]
Expand Down