From 94d71a1aebb325ce7d68eb37c87698fb87ef2f81 Mon Sep 17 00:00:00 2001 From: Didier SENMARTIN <didier.senmartin-ext@soitec.com> Date: Mon, 7 Mar 2022 17:39:57 +0100 Subject: [PATCH 1/3] add useFinalCopy option --- README.md | 12 ++++++++++++ index.js | 1 + lib/pip.js | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63b1a32a..ce38892f 100644 --- a/README.md +++ b/README.md @@ -428,6 +428,18 @@ functions: vendor: ./hello-vendor # The option is also available at the function level ``` +### Copy dependencies instead of linking + +Before final packaging, a link is created in .serverless folder for python dependencies. +If it is not possible to create a symbolic link, dependencies can be copied instead of linked +whith the foloowing option: + +```yaml +custom: + pythonRequirements: + useFinalCopy: true +``` + ## Manual invocations The `.requirements` and `requirements.zip`(if using zip support) files are left diff --git a/index.js b/index.js index c6577fe0..32326b6a 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,7 @@ class ServerlessPythonRequirements { pipCmdExtraArgs: [], noDeploy: [], vendor: '', + useFinalCopy: false, }, (this.serverless.service.custom && this.serverless.service.custom.pythonRequirements) || diff --git a/lib/pip.js b/lib/pip.js index 9f950664..681c07ca 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -782,7 +782,9 @@ async function installAllRequirements() { reqsInstalledAt != symlinkPath ) { // Windows can't symlink so we have to use junction on Windows - if (process.platform == 'win32') { + if (this.serverless.service.custom.pythonRequirements.useFinalCopy) { + fse.copySync(reqsInstalledAt, symlinkPath); + } else if (process.platform == 'win32') { fse.symlink(reqsInstalledAt, symlinkPath, 'junction'); } else { fse.symlink(reqsInstalledAt, symlinkPath); From 12f7ae3c285b4233e1117afb4af6570be1bbb2ef Mon Sep 17 00:00:00 2001 From: Didier SENMARTIN <didier.senmartin-ext@soitec.com> Date: Tue, 8 Mar 2022 13:26:21 +0100 Subject: [PATCH 2/3] Code review --- README.md | 6 +++--- index.js | 2 +- lib/pip.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce38892f..1d8894ce 100644 --- a/README.md +++ b/README.md @@ -431,13 +431,13 @@ functions: ### Copy dependencies instead of linking Before final packaging, a link is created in .serverless folder for python dependencies. -If it is not possible to create a symbolic link, dependencies can be copied instead of linked -whith the foloowing option: +If it is not possible for the OS to create a symbolic link, dependencies can be copied, +instead of linked, with the following option: ```yaml custom: pythonRequirements: - useFinalCopy: true + useSymlinks: false ``` ## Manual invocations diff --git a/index.js b/index.js index 32326b6a..c1bcd497 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ class ServerlessPythonRequirements { pipCmdExtraArgs: [], noDeploy: [], vendor: '', - useFinalCopy: false, + useSymlinks: true, }, (this.serverless.service.custom && this.serverless.service.custom.pythonRequirements) || diff --git a/lib/pip.js b/lib/pip.js index 681c07ca..c52f8d58 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -782,7 +782,7 @@ async function installAllRequirements() { reqsInstalledAt != symlinkPath ) { // Windows can't symlink so we have to use junction on Windows - if (this.serverless.service.custom.pythonRequirements.useFinalCopy) { + if (!this.serverless.service.custom.pythonRequirements.useSymlinks) { fse.copySync(reqsInstalledAt, symlinkPath); } else if (process.platform == 'win32') { fse.symlink(reqsInstalledAt, symlinkPath, 'junction'); From ac850444c065701e537cdc550e8b7089efd6fb0f Mon Sep 17 00:00:00 2001 From: Didier SENMARTIN <didier.senmartin-ext@soitec.com> Date: Tue, 8 Mar 2022 14:48:45 +0100 Subject: [PATCH 3/3] Prettier --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d8894ce..2daddf16 100644 --- a/README.md +++ b/README.md @@ -431,7 +431,7 @@ functions: ### Copy dependencies instead of linking Before final packaging, a link is created in .serverless folder for python dependencies. -If it is not possible for the OS to create a symbolic link, dependencies can be copied, +If it is not possible for the OS to create a symbolic link, dependencies can be copied, instead of linked, with the following option: ```yaml