Skip to content

Commit 853da8d

Browse files
andidevrwestergrenpgrzesik
authored
fix: Adapt to support latest pipenv version (#718)
BREAKING CHANGE: Requires `pipenv` in version `2022-04-08` or higher Co-authored-by: Randy Westergren <[email protected]> Co-authored-by: Piotr Grzesik <[email protected]>
1 parent 8969fb2 commit 853da8d

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
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==2021.11.5 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==2021.11.5 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==2021.11.5 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==2021.11.5 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==2021.11.5 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==2021.11.5 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

+18-13
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@ async function pipfileToRequirements() {
2828
}
2929

3030
try {
31-
let res;
3231
try {
33-
res = await spawn(
34-
'pipenv',
35-
['lock', '--requirements', '--keep-outdated'],
36-
{
37-
cwd: this.servicePath,
38-
}
39-
);
32+
await spawn('pipenv', ['lock', '--keep-outdated'], {
33+
cwd: this.servicePath,
34+
});
4035
} catch (e) {
41-
if (
42-
e.stderrBuffer &&
43-
e.stderrBuffer.toString().includes('command not found')
44-
) {
36+
const stderrBufferContent =
37+
(e.stderrBuffer && e.stderrBuffer.toString()) || '';
38+
39+
if (stderrBufferContent.includes('must exist to use')) {
40+
// No previous Pipfile.lock, we will try to generate it here
41+
await spawn('pipenv', ['lock'], {
42+
cwd: this.servicePath,
43+
});
44+
} else if (stderrBufferContent.includes('command not found')) {
4545
throw new this.serverless.classes.Error(
4646
`pipenv not found! Install it according to the poetry docs.`,
4747
'PYTHON_REQUIREMENTS_PIPENV_NOT_FOUND'
4848
);
49+
} else {
50+
throw e;
4951
}
50-
throw e;
5152
}
53+
const res = await spawn('pipenv', ['requirements'], {
54+
cwd: this.servicePath,
55+
});
56+
5257
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
5358
fse.writeFileSync(
5459
path.join(this.servicePath, '.serverless/requirements.txt'),

tests/pipenv/Pipfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[[source]]
2-
url = "https://pypi.python.org/simple"
2+
url = "https://pypi.org/simple"
33
verify_ssl = true
4+
name = "pypi"
45

56
[packages]
67
Flask = "==2.0.3"

0 commit comments

Comments
 (0)