Skip to content

fix: Adapt to support latest pipenv version #718

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

Merged
merged 4 commits into from
Oct 23, 2022
Merged
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
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==2021.11.5 poetry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe at this point we could remove the pinned pipenv version here - I added it temporarily to stabilize tests and be able to merge other PRs

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==2021.11.5 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==2021.11.5 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==2021.11.5 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==2021.11.5 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==2021.11.5 poetry
run: python -m pip install pipenv poetry

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

try {
let res;
try {
res = await spawn(
'pipenv',
['lock', '--requirements', '--keep-outdated'],
{
cwd: this.servicePath,
}
);
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
await spawn('pipenv', ['lock'], {
cwd: this.servicePath,
});
} else 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'
);
} else {
throw e;
}
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
3 changes: 2 additions & 1 deletion tests/pipenv/Pipfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[[source]]
url = "https://pypi.python.org/simple"
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
Flask = "==2.0.3"
Expand Down