@vercel/python 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +137 -126
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ var require_windows = __commonJS({
48
48
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module2) {
49
49
  module2.exports = isexe;
50
50
  isexe.sync = sync;
51
- var fs5 = require("fs");
51
+ var fs4 = require("fs");
52
52
  function checkPathExt(path, options) {
53
53
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
54
54
  if (!pathext) {
@@ -73,12 +73,12 @@ var require_windows = __commonJS({
73
73
  return checkPathExt(path, options);
74
74
  }
75
75
  function isexe(path, options, cb) {
76
- fs5.stat(path, function(er, stat) {
76
+ fs4.stat(path, function(er, stat) {
77
77
  cb(er, er ? false : checkStat(stat, path, options));
78
78
  });
79
79
  }
80
80
  function sync(path, options) {
81
- return checkStat(fs5.statSync(path), path, options);
81
+ return checkStat(fs4.statSync(path), path, options);
82
82
  }
83
83
  }
84
84
  });
@@ -88,14 +88,14 @@ var require_mode = __commonJS({
88
88
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module2) {
89
89
  module2.exports = isexe;
90
90
  isexe.sync = sync;
91
- var fs5 = require("fs");
91
+ var fs4 = require("fs");
92
92
  function isexe(path, options, cb) {
93
- fs5.stat(path, function(er, stat) {
93
+ fs4.stat(path, function(er, stat) {
94
94
  cb(er, er ? false : checkStat(stat, options));
95
95
  });
96
96
  }
97
97
  function sync(path, options) {
98
- return checkStat(fs5.statSync(path), options);
98
+ return checkStat(fs4.statSync(path), options);
99
99
  }
100
100
  function checkStat(stat, options) {
101
101
  return stat.isFile() && checkMode(stat, options);
@@ -119,7 +119,7 @@ var require_mode = __commonJS({
119
119
  // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
120
120
  var require_isexe = __commonJS({
121
121
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module2) {
122
- var fs5 = require("fs");
122
+ var fs4 = require("fs");
123
123
  var core;
124
124
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
125
125
  core = require_windows();
@@ -395,7 +395,7 @@ var require_shebang_command = __commonJS({
395
395
  var require_readShebang = __commonJS({
396
396
  "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
397
397
  "use strict";
398
- var fs5 = require("fs");
398
+ var fs4 = require("fs");
399
399
  var shebangCommand = require_shebang_command();
400
400
  function readShebang(command) {
401
401
  const size = 150;
@@ -408,9 +408,9 @@ var require_readShebang = __commonJS({
408
408
  }
409
409
  let fd;
410
410
  try {
411
- fd = fs5.openSync(command, "r");
412
- fs5.readSync(fd, buffer, 0, size, 0);
413
- fs5.closeSync(fd);
411
+ fd = fs4.openSync(command, "r");
412
+ fs4.readSync(fd, buffer, 0, size, 0);
413
+ fs4.closeSync(fd);
414
414
  } catch (e) {
415
415
  }
416
416
  return shebangCommand(buffer.toString());
@@ -1895,9 +1895,9 @@ var require_pump = __commonJS({
1895
1895
  "../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js"(exports, module2) {
1896
1896
  var once = require_once();
1897
1897
  var eos = require_end_of_stream();
1898
- var fs5;
1898
+ var fs4;
1899
1899
  try {
1900
- fs5 = require("fs");
1900
+ fs4 = require("fs");
1901
1901
  } catch (e) {
1902
1902
  }
1903
1903
  var noop = function() {
@@ -1909,9 +1909,9 @@ var require_pump = __commonJS({
1909
1909
  var isFS = function(stream) {
1910
1910
  if (!ancient)
1911
1911
  return false;
1912
- if (!fs5)
1912
+ if (!fs4)
1913
1913
  return false;
1914
- return (stream instanceof (fs5.ReadStream || noop) || stream instanceof (fs5.WriteStream || noop)) && isFn(stream.close);
1914
+ return (stream instanceof (fs4.ReadStream || noop) || stream instanceof (fs4.WriteStream || noop)) && isFn(stream.close);
1915
1915
  };
1916
1916
  var isRequest = function(stream) {
1917
1917
  return stream.setHeader && isFn(stream.abort);
@@ -2748,7 +2748,7 @@ __export(src_exports, {
2748
2748
  version: () => version
2749
2749
  });
2750
2750
  module.exports = __toCommonJS(src_exports);
2751
- var import_fs5 = __toESM(require("fs"));
2751
+ var import_fs4 = __toESM(require("fs"));
2752
2752
  var import_util = require("util");
2753
2753
  var import_path5 = require("path");
2754
2754
  var import_build_utils7 = require("@vercel/build-utils");
@@ -2767,6 +2767,7 @@ var import_path = require("path");
2767
2767
  var import_build_utils = require("@vercel/build-utils");
2768
2768
  var import_execa = __toESM(require_execa());
2769
2769
  var isWin = process.platform === "win32";
2770
+ var UV_PYTHON_DOWNLOADS_MODE = "automatic";
2770
2771
  var isInVirtualEnv = () => {
2771
2772
  return process.env.VIRTUAL_ENV;
2772
2773
  };
@@ -2793,9 +2794,7 @@ function useVirtualEnv(workPath, env, systemPython) {
2793
2794
  function getProtectedUvEnv(baseEnv = process.env) {
2794
2795
  return {
2795
2796
  ...baseEnv,
2796
- // Prevent uv from downloading Python interpreters at build time.
2797
- // The build environment must use the pre-installed system Python.
2798
- UV_PYTHON_DOWNLOADS: "never"
2797
+ UV_PYTHON_DOWNLOADS: UV_PYTHON_DOWNLOADS_MODE
2799
2798
  };
2800
2799
  }
2801
2800
  function createVenvEnv(venvPath, baseEnv = process.env) {
@@ -3780,97 +3779,28 @@ function isInstalled2({ pipPath, pythonPath }) {
3780
3779
 
3781
3780
  // src/start-dev-server.ts
3782
3781
  var import_child_process = require("child_process");
3783
- var import_fs4 = require("fs");
3782
+ var import_fs3 = require("fs");
3784
3783
  var import_path4 = require("path");
3785
3784
  var import_build_utils6 = require("@vercel/build-utils");
3786
3785
 
3787
3786
  // src/entrypoint.ts
3788
- var import_fs3 = __toESM(require("fs"));
3789
3787
  var import_path3 = require("path");
3790
3788
  var import_build_utils4 = require("@vercel/build-utils");
3791
3789
  var import_build_utils5 = require("@vercel/build-utils");
3792
- var FASTAPI_ENTRYPOINT_FILENAMES = ["app", "index", "server", "main"];
3793
- var FASTAPI_ENTRYPOINT_DIRS = ["", "src", "app", "api"];
3794
- var FASTAPI_CONTENT_REGEX = /(from\s+fastapi\s+import\s+FastAPI|import\s+fastapi|FastAPI\s*\()/;
3795
- var FASTAPI_CANDIDATE_ENTRYPOINTS = FASTAPI_ENTRYPOINT_FILENAMES.flatMap(
3796
- (filename) => FASTAPI_ENTRYPOINT_DIRS.map(
3797
- (dir) => import_path3.posix.join(dir, `${filename}.py`)
3798
- )
3799
- );
3800
- function isFastapiEntrypoint(file) {
3801
- try {
3802
- const fsPath = file.fsPath;
3803
- if (!fsPath)
3804
- return false;
3805
- const contents = import_fs3.default.readFileSync(fsPath, "utf8");
3806
- return FASTAPI_CONTENT_REGEX.test(contents);
3807
- } catch {
3808
- return false;
3809
- }
3810
- }
3811
- var FLASK_ENTRYPOINT_FILENAMES = ["app", "index", "server", "main"];
3812
- var FLASK_ENTRYPOINT_DIRS = ["", "src", "app", "api"];
3813
- var FLASK_CONTENT_REGEX = /(from\s+flask\s+import\s+Flask|import\s+flask|Flask\s*\()/;
3814
- var FLASK_CANDIDATE_ENTRYPOINTS = FLASK_ENTRYPOINT_FILENAMES.flatMap(
3815
- (filename) => FLASK_ENTRYPOINT_DIRS.map(
3790
+ var PYTHON_ENTRYPOINT_FILENAMES = [
3791
+ "app",
3792
+ "index",
3793
+ "server",
3794
+ "main",
3795
+ "wsgi",
3796
+ "asgi"
3797
+ ];
3798
+ var PYTHON_ENTRYPOINT_DIRS = ["", "src", "app", "api"];
3799
+ var PYTHON_CANDIDATE_ENTRYPOINTS = PYTHON_ENTRYPOINT_FILENAMES.flatMap(
3800
+ (filename) => PYTHON_ENTRYPOINT_DIRS.map(
3816
3801
  (dir) => import_path3.posix.join(dir, `${filename}.py`)
3817
3802
  )
3818
3803
  );
3819
- function isFlaskEntrypoint(file) {
3820
- try {
3821
- const fsPath = file.fsPath;
3822
- if (!fsPath)
3823
- return false;
3824
- const contents = import_fs3.default.readFileSync(fsPath, "utf8");
3825
- return FLASK_CONTENT_REGEX.test(contents);
3826
- } catch {
3827
- return false;
3828
- }
3829
- }
3830
- async function detectFlaskEntrypoint(workPath, configuredEntrypoint) {
3831
- const entry = configuredEntrypoint.endsWith(".py") ? configuredEntrypoint : `${configuredEntrypoint}.py`;
3832
- try {
3833
- const fsFiles = await (0, import_build_utils4.glob)("**", workPath);
3834
- if (fsFiles[entry])
3835
- return entry;
3836
- const candidates = FLASK_CANDIDATE_ENTRYPOINTS.filter(
3837
- (c) => !!fsFiles[c]
3838
- );
3839
- if (candidates.length > 0) {
3840
- const flaskEntrypoint = candidates.find(
3841
- (c) => isFlaskEntrypoint(fsFiles[c])
3842
- ) || candidates[0];
3843
- (0, import_build_utils4.debug)(`Detected Flask entrypoint: ${flaskEntrypoint}`);
3844
- return flaskEntrypoint;
3845
- }
3846
- return null;
3847
- } catch {
3848
- (0, import_build_utils4.debug)("Failed to discover entrypoint for Flask");
3849
- return null;
3850
- }
3851
- }
3852
- async function detectFastapiEntrypoint(workPath, configuredEntrypoint) {
3853
- const entry = configuredEntrypoint.endsWith(".py") ? configuredEntrypoint : `${configuredEntrypoint}.py`;
3854
- try {
3855
- const fsFiles = await (0, import_build_utils4.glob)("**", workPath);
3856
- if (fsFiles[entry])
3857
- return entry;
3858
- const candidates = FASTAPI_CANDIDATE_ENTRYPOINTS.filter(
3859
- (c) => !!fsFiles[c]
3860
- );
3861
- if (candidates.length > 0) {
3862
- const fastapiEntrypoint = candidates.find(
3863
- (c) => isFastapiEntrypoint(fsFiles[c])
3864
- ) || candidates[0];
3865
- (0, import_build_utils4.debug)(`Detected FastAPI entrypoint: ${fastapiEntrypoint}`);
3866
- return fastapiEntrypoint;
3867
- }
3868
- return null;
3869
- } catch {
3870
- (0, import_build_utils4.debug)("Failed to discover entrypoint for FastAPI");
3871
- return null;
3872
- }
3873
- }
3874
3804
  async function getPyprojectEntrypoint(workPath) {
3875
3805
  const pyprojectData = await (0, import_build_utils5.readConfigFile)((0, import_path3.join)(workPath, "pyproject.toml"));
3876
3806
  if (!pyprojectData)
@@ -3897,13 +3827,38 @@ async function getPyprojectEntrypoint(workPath) {
3897
3827
  return null;
3898
3828
  }
3899
3829
  }
3900
- async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint) {
3901
- let entrypoint = null;
3902
- if (framework === "fastapi") {
3903
- entrypoint = await detectFastapiEntrypoint(workPath, configuredEntrypoint);
3904
- } else if (framework === "flask") {
3905
- entrypoint = await detectFlaskEntrypoint(workPath, configuredEntrypoint);
3830
+ async function detectGenericPythonEntrypoint(workPath, configuredEntrypoint) {
3831
+ const entry = configuredEntrypoint.endsWith(".py") ? configuredEntrypoint : `${configuredEntrypoint}.py`;
3832
+ try {
3833
+ const fsFiles = await (0, import_build_utils4.glob)("**", workPath);
3834
+ if (fsFiles[entry]) {
3835
+ const isValid = await (0, import_build_utils4.isPythonEntrypoint)(fsFiles[entry]);
3836
+ if (isValid) {
3837
+ (0, import_build_utils4.debug)(`Using configured Python entrypoint: ${entry}`);
3838
+ return entry;
3839
+ }
3840
+ }
3841
+ const candidates = PYTHON_CANDIDATE_ENTRYPOINTS.filter(
3842
+ (c) => !!fsFiles[c]
3843
+ );
3844
+ for (const candidate of candidates) {
3845
+ const isValid = await (0, import_build_utils4.isPythonEntrypoint)(fsFiles[candidate]);
3846
+ if (isValid) {
3847
+ (0, import_build_utils4.debug)(`Detected Python entrypoint: ${candidate}`);
3848
+ return candidate;
3849
+ }
3850
+ }
3851
+ return null;
3852
+ } catch {
3853
+ (0, import_build_utils4.debug)("Failed to discover Python entrypoint");
3854
+ return null;
3906
3855
  }
3856
+ }
3857
+ async function detectPythonEntrypoint(_framework, workPath, configuredEntrypoint) {
3858
+ const entrypoint = await detectGenericPythonEntrypoint(
3859
+ workPath,
3860
+ configuredEntrypoint
3861
+ );
3907
3862
  if (entrypoint)
3908
3863
  return entrypoint;
3909
3864
  return await getPyprojectEntrypoint(workPath);
@@ -3985,12 +3940,12 @@ function installGlobalCleanupHandlers() {
3985
3940
  function createDevAsgiShim(workPath, modulePath) {
3986
3941
  try {
3987
3942
  const vercelPythonDir = (0, import_path4.join)(workPath, ".vercel", "python");
3988
- (0, import_fs4.mkdirSync)(vercelPythonDir, { recursive: true });
3943
+ (0, import_fs3.mkdirSync)(vercelPythonDir, { recursive: true });
3989
3944
  const shimPath = (0, import_path4.join)(vercelPythonDir, `${ASGI_SHIM_MODULE}.py`);
3990
3945
  const templatePath = (0, import_path4.join)(__dirname, "..", `${ASGI_SHIM_MODULE}.py`);
3991
- const template = (0, import_fs4.readFileSync)(templatePath, "utf8");
3946
+ const template = (0, import_fs3.readFileSync)(templatePath, "utf8");
3992
3947
  const shimSource = template.replace(/__VC_DEV_MODULE_PATH__/g, modulePath);
3993
- (0, import_fs4.writeFileSync)(shimPath, shimSource, "utf8");
3948
+ (0, import_fs3.writeFileSync)(shimPath, shimSource, "utf8");
3994
3949
  (0, import_build_utils6.debug)(`Prepared Python dev static shim at ${shimPath}`);
3995
3950
  return ASGI_SHIM_MODULE;
3996
3951
  } catch (err) {
@@ -4001,12 +3956,12 @@ function createDevAsgiShim(workPath, modulePath) {
4001
3956
  function createDevWsgiShim(workPath, modulePath) {
4002
3957
  try {
4003
3958
  const vercelPythonDir = (0, import_path4.join)(workPath, ".vercel", "python");
4004
- (0, import_fs4.mkdirSync)(vercelPythonDir, { recursive: true });
3959
+ (0, import_fs3.mkdirSync)(vercelPythonDir, { recursive: true });
4005
3960
  const shimPath = (0, import_path4.join)(vercelPythonDir, `${WSGI_SHIM_MODULE}.py`);
4006
3961
  const templatePath = (0, import_path4.join)(__dirname, "..", `${WSGI_SHIM_MODULE}.py`);
4007
- const template = (0, import_fs4.readFileSync)(templatePath, "utf8");
3962
+ const template = (0, import_fs3.readFileSync)(templatePath, "utf8");
4008
3963
  const shimSource = template.replace(/__VC_DEV_MODULE_PATH__/g, modulePath);
4009
- (0, import_fs4.writeFileSync)(shimPath, shimSource, "utf8");
3964
+ (0, import_fs3.writeFileSync)(shimPath, shimSource, "utf8");
4010
3965
  (0, import_build_utils6.debug)(`Prepared Python dev WSGI shim at ${shimPath}`);
4011
3966
  return WSGI_SHIM_MODULE;
4012
3967
  } catch (err) {
@@ -4029,7 +3984,7 @@ var startDevServer = async (opts) => {
4029
3984
  rawEntrypoint
4030
3985
  );
4031
3986
  if (!entry) {
4032
- const searched = framework === "fastapi" ? FASTAPI_CANDIDATE_ENTRYPOINTS.join(", ") : FLASK_CANDIDATE_ENTRYPOINTS.join(", ");
3987
+ const searched = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
4033
3988
  throw new import_build_utils6.NowBuildError({
4034
3989
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
4035
3990
  message: `No ${framework} entrypoint found. Add an 'app' script in pyproject.toml or define an entrypoint in one of: ${searched}.`,
@@ -4105,7 +4060,7 @@ If you are using a virtual environment, activate it before running "vercel dev",
4105
4060
  }
4106
4061
  }
4107
4062
  }
4108
- if (framework === "fastapi") {
4063
+ if (framework !== "flask") {
4109
4064
  const devShimModule = createDevAsgiShim(workPath, modulePath);
4110
4065
  if (devShimModule) {
4111
4066
  const vercelPythonDir = (0, import_path4.join)(workPath, ".vercel", "python");
@@ -4114,7 +4069,9 @@ If you are using a virtual environment, activate it before running "vercel dev",
4114
4069
  }
4115
4070
  const moduleToRun = devShimModule || modulePath;
4116
4071
  const argv = ["-u", "-m", moduleToRun];
4117
- (0, import_build_utils6.debug)(`Starting ASGI dev server: ${pythonCmd} ${argv.join(" ")}`);
4072
+ (0, import_build_utils6.debug)(
4073
+ `Starting ASGI dev server (${framework}): ${pythonCmd} ${argv.join(" ")}`
4074
+ );
4118
4075
  const child = (0, import_child_process.spawn)(pythonCmd, argv, {
4119
4076
  cwd: workPath,
4120
4077
  env,
@@ -4279,8 +4236,8 @@ If you are using a virtual environment, activate it before running "vercel dev",
4279
4236
  };
4280
4237
 
4281
4238
  // src/index.ts
4282
- var readFile = (0, import_util.promisify)(import_fs5.default.readFile);
4283
- var writeFile = (0, import_util.promisify)(import_fs5.default.writeFile);
4239
+ var readFile = (0, import_util.promisify)(import_fs4.default.readFile);
4240
+ var writeFile = (0, import_util.promisify)(import_fs4.default.writeFile);
4284
4241
  var version = 3;
4285
4242
  async function downloadFilesInWorkPath({
4286
4243
  entrypoint,
@@ -4325,7 +4282,7 @@ var build = async ({
4325
4282
  console.log('Failed to create "setup.cfg" file');
4326
4283
  throw err;
4327
4284
  }
4328
- if (framework === "fastapi" || framework === "flask") {
4285
+ if ((0, import_build_utils7.isPythonFramework)(framework)) {
4329
4286
  const {
4330
4287
  cliType,
4331
4288
  lockfileVersion,
@@ -4366,7 +4323,7 @@ var build = async ({
4366
4323
  }
4367
4324
  }
4368
4325
  let fsFiles = await (0, import_build_utils7.glob)("**", workPath);
4369
- if ((framework === "fastapi" || framework === "flask") && (!fsFiles[entrypoint] || !entrypoint.endsWith(".py"))) {
4326
+ if ((0, import_build_utils7.isPythonFramework)(framework) && (!fsFiles[entrypoint] || !entrypoint.endsWith(".py"))) {
4370
4327
  const detected = await detectPythonEntrypoint(
4371
4328
  config.framework,
4372
4329
  workPath,
@@ -4378,7 +4335,7 @@ var build = async ({
4378
4335
  );
4379
4336
  entrypoint = detected;
4380
4337
  } else {
4381
- const searchedList = framework === "fastapi" ? FASTAPI_CANDIDATE_ENTRYPOINTS.join(", ") : FLASK_CANDIDATE_ENTRYPOINTS.join(", ");
4338
+ const searchedList = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
4382
4339
  throw new import_build_utils7.NowBuildError({
4383
4340
  code: `${framework.toUpperCase()}_ENTRYPOINT_NOT_FOUND`,
4384
4341
  message: `No ${framework} entrypoint found. Add an 'app' script in pyproject.toml or define an entrypoint in one of: ${searchedList}.`,
@@ -4443,7 +4400,8 @@ var build = async ({
4443
4400
  pythonPath: pythonVersion.pythonPath,
4444
4401
  venvPath
4445
4402
  });
4446
- const hasCustomInstallCommand = (framework === "fastapi" || framework === "flask") && !!projectInstallCommand;
4403
+ const hasCustomInstallCommand = (0, import_build_utils7.isPythonFramework)(framework) && !!projectInstallCommand;
4404
+ let useRuntime = false;
4447
4405
  if (hasCustomInstallCommand) {
4448
4406
  const baseEnv = spawnEnv || process.env;
4449
4407
  const pythonEnv = createVenvEnv(venvPath, baseEnv);
@@ -4456,7 +4414,7 @@ var build = async ({
4456
4414
  });
4457
4415
  } else {
4458
4416
  let ranPyprojectInstall = false;
4459
- if (framework === "fastapi" || framework === "flask") {
4417
+ if ((0, import_build_utils7.isPythonFramework)(framework)) {
4460
4418
  const baseEnv = spawnEnv || process.env;
4461
4419
  const pythonEnv = createVenvEnv(venvPath, baseEnv);
4462
4420
  pythonEnv.VERCEL_PYTHON_VENV_PATH = venvPath;
@@ -4479,7 +4437,18 @@ var build = async ({
4479
4437
  `uv is required for this project but failed to install: ${err instanceof Error ? err.message : String(err)}`
4480
4438
  );
4481
4439
  }
4482
- const runtimeDependencies = framework === "flask" ? ["werkzeug>=1.0.1"] : ["werkzeug>=1.0.1", "uvicorn>=0.24"];
4440
+ const baseEnv = spawnEnv || process.env;
4441
+ useRuntime = !!baseEnv.VERCEL_RUNTIME_PYTHON_ENABLED;
4442
+ const runtimeDependencies = [];
4443
+ if (useRuntime) {
4444
+ runtimeDependencies.push(
4445
+ baseEnv.VERCEL_RUNTIME_PYTHON || "vercel-runtime==0.1.0"
4446
+ );
4447
+ }
4448
+ runtimeDependencies.push("werkzeug>=1.0.1");
4449
+ if (framework !== "flask") {
4450
+ runtimeDependencies.push("uvicorn>=0.24");
4451
+ }
4483
4452
  const { projectDir } = await ensureUvProject({
4484
4453
  workPath,
4485
4454
  entryDirectory,
@@ -4500,15 +4469,57 @@ var build = async ({
4500
4469
  });
4501
4470
  }
4502
4471
  }
4503
- const originalPyPath = (0, import_path5.join)(__dirname, "..", "vc_init.py");
4504
- const originalHandlerPyContents = await readFile(originalPyPath, "utf8");
4505
4472
  (0, import_build_utils7.debug)("Entrypoint is", entrypoint);
4506
4473
  const moduleName = entrypoint.replace(/\//g, ".").replace(/\.py$/i, "");
4507
4474
  const vendorDir = resolveVendorDir();
4508
4475
  const suffix = meta.isDev && !entrypoint.endsWith(".py") ? ".py" : "";
4509
4476
  const entrypointWithSuffix = `${entrypoint}${suffix}`;
4510
4477
  (0, import_build_utils7.debug)("Entrypoint with suffix is", entrypointWithSuffix);
4511
- const handlerPyContents = originalHandlerPyContents.replace(/__VC_HANDLER_MODULE_NAME/g, moduleName).replace(/__VC_HANDLER_ENTRYPOINT/g, entrypointWithSuffix).replace(/__VC_HANDLER_VENDOR_DIR/g, vendorDir);
4478
+ let handlerPyContents;
4479
+ if (useRuntime) {
4480
+ handlerPyContents = `
4481
+ import importlib
4482
+ import os
4483
+ import os.path
4484
+ import site
4485
+ import sys
4486
+
4487
+ _here = os.path.dirname(__file__)
4488
+
4489
+ os.environ.update({
4490
+ "__VC_HANDLER_MODULE_NAME": "${moduleName}",
4491
+ "__VC_HANDLER_ENTRYPOINT": "${entrypointWithSuffix}",
4492
+ "__VC_HANDLER_ENTRYPOINT_ABS": os.path.join(_here, "${entrypointWithSuffix}"),
4493
+ "__VC_HANDLER_VENDOR_DIR": "${vendorDir}",
4494
+ })
4495
+
4496
+ _vendor_rel = '${vendorDir}'
4497
+ _vendor = os.path.normpath(os.path.join(_here, _vendor_rel))
4498
+
4499
+ if os.path.isdir(_vendor):
4500
+ # Process .pth files like a real site-packages dir
4501
+ site.addsitedir(_vendor)
4502
+
4503
+ # Move _vendor to the front (after script dir if present)
4504
+ try:
4505
+ while _vendor in sys.path:
4506
+ sys.path.remove(_vendor)
4507
+ except ValueError:
4508
+ pass
4509
+
4510
+ # Put vendored deps ahead of site-packages but after the script dir
4511
+ idx = 1 if (sys.path and sys.path[0] in ('', _here)) else 0
4512
+ sys.path.insert(idx, _vendor)
4513
+
4514
+ importlib.invalidate_caches()
4515
+
4516
+ from vercel_runtime.vc_init import vc_handler
4517
+ `;
4518
+ } else {
4519
+ const originalPyPath = (0, import_path5.join)(__dirname, "..", "vc_init.py");
4520
+ const originalHandlerPyContents = await readFile(originalPyPath, "utf8");
4521
+ handlerPyContents = originalHandlerPyContents.replace(/__VC_HANDLER_MODULE_NAME/g, moduleName).replace(/__VC_HANDLER_ENTRYPOINT/g, entrypointWithSuffix).replace(/__VC_HANDLER_VENDOR_DIR/g, vendorDir);
4522
+ }
4512
4523
  const predefinedExcludes = [
4513
4524
  ".git/**",
4514
4525
  ".gitignore",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
@@ -20,7 +20,7 @@
20
20
  "@types/execa": "^0.9.0",
21
21
  "@types/fs-extra": "11.0.2",
22
22
  "@types/jest": "27.4.1",
23
- "@types/node": "14.18.33",
23
+ "@types/node": "20.11.0",
24
24
  "@types/which": "3.0.0",
25
25
  "cross-env": "7.0.3",
26
26
  "execa": "^1.0.0",
@@ -30,7 +30,7 @@
30
30
  "pip-requirements-js": "1.0.2",
31
31
  "smol-toml": "1.5.2",
32
32
  "which": "3.0.0",
33
- "@vercel/build-utils": "13.2.12",
33
+ "@vercel/build-utils": "13.2.14",
34
34
  "@vercel/error-utils": "2.0.3"
35
35
  },
36
36
  "scripts": {