Skip to content

Commit

Permalink
feat: Ensure support when Pipfile.lock missing
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 23, 2022
1 parent ef4f0cc commit 6576dbc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 296 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
run: python -m pip install --force setuptools wheel

- name: Install pipenv / poetry
run: python -m pip install pipenv==2022.9.24 poetry
run: python -m pip install pipenv poetry

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down
30 changes: 21 additions & 9 deletions lib/pipenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,38 @@ async function pipfileToRequirements() {
}

try {
let res;
try {
res = await spawn('pipenv', ['lock', '--keep-outdated'], {
cwd: this.servicePath,
});
res = await spawn('pipenv', ['requirements', '--hash'], {
await spawn('pipenv', ['lock', '--keep-outdated'], {
cwd: this.servicePath,
});
} catch (e) {
if (
e.stderrBuffer &&
e.stderrBuffer.toString().includes('command not found')
) {
const stderrBufferContent =
(e.stderrBuffer && e.stderrBuffer.toString()) || '';
if (stderrBufferContent.includes('must exist to use')) {
// No previous Pipfile.lock, we will try to generate it here
try {
await spawn('pipenv', ['lock'], {
cwd: this.servicePath,
});
} catch (e) {
console.log('weird', e.stderrBuffer.toString());
throw e;
}
}

if (stderrBufferContent.includes('command not found')) {
throw new this.serverless.classes.Error(
`pipenv not found! Install it according to the poetry docs.`,
'PYTHON_REQUIREMENTS_PIPENV_NOT_FOUND'
);
}

throw e;
}
const res = await spawn('pipenv', ['requirements'], {
cwd: this.servicePath,
});

fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
fse.writeFileSync(
path.join(this.servicePath, '.serverless/requirements.txt'),
Expand Down
281 changes: 0 additions & 281 deletions tests/pipenv/Pipfile.lock

This file was deleted.

0 comments on commit 6576dbc

Please sign in to comment.