Skip to content

Commit 6576dbc

Browse files
committedOct 23, 2022
feat: Ensure support when Pipfile.lock missing
1 parent ef4f0cc commit 6576dbc

File tree

4 files changed

+27
-296
lines changed

4 files changed

+27
-296
lines changed
 

‎.github/workflows/integrate.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: python -m pip install --force setuptools wheel
4949

5050
- name: Install pipenv / poetry
51-
run: python -m pip install pipenv==2022.9.24 poetry
51+
run: python -m pip install pipenv poetry
5252

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

101101
- name: Install pipenv / poetry
102-
run: python -m pip install pipenv==2022.9.24 poetry
102+
run: python -m pip install pipenv poetry
103103

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

149149
- name: Install pipenv / poetry
150-
run: python -m pip install pipenv==2022.9.24 poetry
150+
run: python -m pip install pipenv poetry
151151

152152
- name: Install serverless
153153
run: npm install -g serverless@${{ matrix.sls-version }}

‎.github/workflows/validate.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: python -m pip install --force setuptools wheel
6262

6363
- name: Install pipenv / poetry
64-
run: python -m pip install pipenv==2022.9.24 poetry
64+
run: python -m pip install pipenv poetry
6565

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

130130
- name: Install pipenv / poetry
131-
run: python -m pip install pipenv==2022.9.24 poetry
131+
run: python -m pip install pipenv poetry
132132

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

183183
- name: Install pipenv / poetry
184-
run: python -m pip install pipenv==2022.9.24 poetry
184+
run: python -m pip install pipenv poetry
185185

186186
- name: Install serverless
187187
run: npm install -g serverless@${{ matrix.sls-version }}

‎lib/pipenv.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,38 @@ async function pipfileToRequirements() {
2828
}
2929

3030
try {
31-
let res;
3231
try {
33-
res = await spawn('pipenv', ['lock', '--keep-outdated'], {
34-
cwd: this.servicePath,
35-
});
36-
res = await spawn('pipenv', ['requirements', '--hash'], {
32+
await spawn('pipenv', ['lock', '--keep-outdated'], {
3733
cwd: this.servicePath,
3834
});
3935
} catch (e) {
40-
if (
41-
e.stderrBuffer &&
42-
e.stderrBuffer.toString().includes('command not found')
43-
) {
36+
const stderrBufferContent =
37+
(e.stderrBuffer && e.stderrBuffer.toString()) || '';
38+
if (stderrBufferContent.includes('must exist to use')) {
39+
// No previous Pipfile.lock, we will try to generate it here
40+
try {
41+
await spawn('pipenv', ['lock'], {
42+
cwd: this.servicePath,
43+
});
44+
} catch (e) {
45+
console.log('weird', e.stderrBuffer.toString());
46+
throw e;
47+
}
48+
}
49+
50+
if (stderrBufferContent.includes('command not found')) {
4451
throw new this.serverless.classes.Error(
4552
`pipenv not found! Install it according to the poetry docs.`,
4653
'PYTHON_REQUIREMENTS_PIPENV_NOT_FOUND'
4754
);
4855
}
56+
4957
throw e;
5058
}
59+
const res = await spawn('pipenv', ['requirements'], {
60+
cwd: this.servicePath,
61+
});
62+
5163
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
5264
fse.writeFileSync(
5365
path.join(this.servicePath, '.serverless/requirements.txt'),

‎tests/pipenv/Pipfile.lock

-281
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.