Skip to content

fix: use serviceDir while injecting requirements to ensure compatibility with v4 Compose #854

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 17 commits into from
Feb 11, 2025
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
2 changes: 1 addition & 1 deletion .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 poetry
run: python -m pip install pipenv poetry && poetry self add poetry-plugin-export

- name: Install serverless
run: npm install -g serverless@${{ matrix.sls-version }}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ServerlessPythonRequirements {
options.pythonBin = 'python';
}
if (/python3[0-9]+/.test(options.pythonBin)) {
// "google" and "scaleway" providers' runtimes uses python3XX
// "google" and "scaleway" providers' runtimes use python3XX
options.pythonBin = options.pythonBin.replace(/3([0-9]+)/, '3.$1');
}
if (options.dockerizePip === 'non-linux') {
Expand Down
9 changes: 7 additions & 2 deletions lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,20 @@ async function injectAllRequirements(funcArtifact) {
return this.options.zip
? func
: injectRequirements(
path.join('.serverless', func.module, 'requirements'),
path.join(
this.serverless.serviceDir,
'.serverless',
func.module,
'requirements'
),
func.package.artifact,
injectionRelativePath,
this.options
);
});
} else if (!this.options.zip) {
await injectRequirements(
path.join('.serverless', 'requirements'),
path.join(this.serverless.serviceDir, '.serverless', 'requirements'),
this.serverless.service.package.artifact || funcArtifact,
injectionRelativePath,
this.options
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
"sha256-file": "1.0.0",
"shell-quote": "^1.8.1"
},
"peerDependencies": {
"serverless": ">=2.32"
},
"lint-staged": {
"*.js": [
"eslint"
Expand Down
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ test(
process.chdir('tests/base');
const { stdout: path } = npm(['pack', '../..']);
npm(['i', path]);
const { stderr } = sls(['package'], {
const { stdout } = sls(['package'], {
noThrow: true,
env: {
dockerizePip: true,
Expand All @@ -216,7 +216,7 @@ test(
},
});
t.true(
stderr.includes(
stdout.includes(
`-v ${__dirname}${sep}tests${sep}base${sep}custom_ssh:/root/.ssh/custom_ssh:z`
),
'docker command properly resolved'
Expand Down Expand Up @@ -1742,12 +1742,12 @@ test('poetry py3.9 fails packaging if poetry.lock is missing and flag requirePoe

const { stdout: path } = npm(['pack', '../..']);
npm(['i', path]);
const { stderr } = sls(['package'], {
const { stdout } = sls(['package'], {
env: { requirePoetryLockFile: 'true', slim: 'true' },
noThrow: true,
});
t.true(
stderr.includes(
stdout.includes(
'poetry.lock file not found - set requirePoetryLockFile to false to disable this error'
),
'flag works and error is properly reported'
Expand Down