diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 6d5f57ac..1f979b0a 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -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 + run: python -m pip install pipenv poetry - name: Install serverless run: npm install -g serverless@${{ matrix.sls-version }} @@ -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 }} @@ -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 }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 801b7194..31052279 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -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 }} @@ -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 }} @@ -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 }} diff --git a/lib/pipenv.js b/lib/pipenv.js index 5856d47b..11331ee3 100644 --- a/lib/pipenv.js +++ b/lib/pipenv.js @@ -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'), diff --git a/tests/pipenv/Pipfile b/tests/pipenv/Pipfile index 6770a12a..30e51dda 100644 --- a/tests/pipenv/Pipfile +++ b/tests/pipenv/Pipfile @@ -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"