@vercel/python 6.20.2 → 6.22.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.
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 fs8 = require("fs");
51
+ var fs9 = 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
- fs8.stat(path, function(er, stat) {
76
+ fs9.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(fs8.statSync(path), path, options);
81
+ return checkStat(fs9.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 fs8 = require("fs");
91
+ var fs9 = require("fs");
92
92
  function isexe(path, options, cb) {
93
- fs8.stat(path, function(er, stat) {
93
+ fs9.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(fs8.statSync(path), options);
98
+ return checkStat(fs9.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 fs8 = require("fs");
122
+ var fs9 = 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 fs8 = require("fs");
398
+ var fs9 = 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 = fs8.openSync(command, "r");
412
- fs8.readSync(fd, buffer, 0, size, 0);
413
- fs8.closeSync(fd);
411
+ fd = fs9.openSync(command, "r");
412
+ fs9.readSync(fd, buffer, 0, size, 0);
413
+ fs9.closeSync(fd);
414
414
  } catch (e) {
415
415
  }
416
416
  return shebangCommand(buffer.toString());
@@ -423,15 +423,15 @@ var require_readShebang = __commonJS({
423
423
  var require_semver = __commonJS({
424
424
  "../../node_modules/.pnpm/semver@5.7.2/node_modules/semver/semver.js"(exports, module2) {
425
425
  exports = module2.exports = SemVer;
426
- var debug10;
426
+ var debug11;
427
427
  if (typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
428
- debug10 = function() {
428
+ debug11 = function() {
429
429
  var args = Array.prototype.slice.call(arguments, 0);
430
430
  args.unshift("SEMVER");
431
431
  console.log.apply(console, args);
432
432
  };
433
433
  } else {
434
- debug10 = function() {
434
+ debug11 = function() {
435
435
  };
436
436
  }
437
437
  exports.SEMVER_SPEC_VERSION = "2.0.0";
@@ -540,7 +540,7 @@ var require_semver = __commonJS({
540
540
  var STAR = R++;
541
541
  src[STAR] = "(<|>)?=?\\s*\\*";
542
542
  for (i = 0; i < R; i++) {
543
- debug10(i, src[i]);
543
+ debug11(i, src[i]);
544
544
  if (!re[i]) {
545
545
  re[i] = new RegExp(src[i]);
546
546
  safeRe[i] = new RegExp(makeSafeRe(src[i]));
@@ -607,7 +607,7 @@ var require_semver = __commonJS({
607
607
  if (!(this instanceof SemVer)) {
608
608
  return new SemVer(version2, options);
609
609
  }
610
- debug10("SemVer", version2, options);
610
+ debug11("SemVer", version2, options);
611
611
  this.options = options;
612
612
  this.loose = !!options.loose;
613
613
  var m = version2.trim().match(options.loose ? safeRe[LOOSE] : safeRe[FULL]);
@@ -654,7 +654,7 @@ var require_semver = __commonJS({
654
654
  return this.version;
655
655
  };
656
656
  SemVer.prototype.compare = function(other) {
657
- debug10("SemVer.compare", this.version, this.options, other);
657
+ debug11("SemVer.compare", this.version, this.options, other);
658
658
  if (!(other instanceof SemVer)) {
659
659
  other = new SemVer(other, this.options);
660
660
  }
@@ -681,7 +681,7 @@ var require_semver = __commonJS({
681
681
  do {
682
682
  var a = this.prerelease[i2];
683
683
  var b = other.prerelease[i2];
684
- debug10("prerelease compare", i2, a, b);
684
+ debug11("prerelease compare", i2, a, b);
685
685
  if (a === void 0 && b === void 0) {
686
686
  return 0;
687
687
  } else if (b === void 0) {
@@ -935,7 +935,7 @@ var require_semver = __commonJS({
935
935
  return new Comparator(comp, options);
936
936
  }
937
937
  comp = comp.trim().split(/\s+/).join(" ");
938
- debug10("comparator", comp, options);
938
+ debug11("comparator", comp, options);
939
939
  this.options = options;
940
940
  this.loose = !!options.loose;
941
941
  this.parse(comp);
@@ -944,7 +944,7 @@ var require_semver = __commonJS({
944
944
  } else {
945
945
  this.value = this.operator + this.semver.version;
946
946
  }
947
- debug10("comp", this);
947
+ debug11("comp", this);
948
948
  }
949
949
  var ANY = {};
950
950
  Comparator.prototype.parse = function(comp) {
@@ -967,7 +967,7 @@ var require_semver = __commonJS({
967
967
  return this.value;
968
968
  };
969
969
  Comparator.prototype.test = function(version2) {
970
- debug10("Comparator.test", version2, this.options.loose);
970
+ debug11("Comparator.test", version2, this.options.loose);
971
971
  if (this.semver === ANY) {
972
972
  return true;
973
973
  }
@@ -1050,9 +1050,9 @@ var require_semver = __commonJS({
1050
1050
  var loose = this.options.loose;
1051
1051
  var hr = loose ? safeRe[HYPHENRANGELOOSE] : safeRe[HYPHENRANGE];
1052
1052
  range = range.replace(hr, hyphenReplace);
1053
- debug10("hyphen replace", range);
1053
+ debug11("hyphen replace", range);
1054
1054
  range = range.replace(safeRe[COMPARATORTRIM], comparatorTrimReplace);
1055
- debug10("comparator trim", range, safeRe[COMPARATORTRIM]);
1055
+ debug11("comparator trim", range, safeRe[COMPARATORTRIM]);
1056
1056
  range = range.replace(safeRe[TILDETRIM], tildeTrimReplace);
1057
1057
  range = range.replace(safeRe[CARETTRIM], caretTrimReplace);
1058
1058
  var compRe = loose ? safeRe[COMPARATORLOOSE] : safeRe[COMPARATOR];
@@ -1092,15 +1092,15 @@ var require_semver = __commonJS({
1092
1092
  });
1093
1093
  }
1094
1094
  function parseComparator(comp, options) {
1095
- debug10("comp", comp, options);
1095
+ debug11("comp", comp, options);
1096
1096
  comp = replaceCarets(comp, options);
1097
- debug10("caret", comp);
1097
+ debug11("caret", comp);
1098
1098
  comp = replaceTildes(comp, options);
1099
- debug10("tildes", comp);
1099
+ debug11("tildes", comp);
1100
1100
  comp = replaceXRanges(comp, options);
1101
- debug10("xrange", comp);
1101
+ debug11("xrange", comp);
1102
1102
  comp = replaceStars(comp, options);
1103
- debug10("stars", comp);
1103
+ debug11("stars", comp);
1104
1104
  return comp;
1105
1105
  }
1106
1106
  function isX(id) {
@@ -1114,7 +1114,7 @@ var require_semver = __commonJS({
1114
1114
  function replaceTilde(comp, options) {
1115
1115
  var r = options.loose ? safeRe[TILDELOOSE] : safeRe[TILDE];
1116
1116
  return comp.replace(r, function(_, M, m, p, pr) {
1117
- debug10("tilde", comp, _, M, m, p, pr);
1117
+ debug11("tilde", comp, _, M, m, p, pr);
1118
1118
  var ret;
1119
1119
  if (isX(M)) {
1120
1120
  ret = "";
@@ -1123,12 +1123,12 @@ var require_semver = __commonJS({
1123
1123
  } else if (isX(p)) {
1124
1124
  ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
1125
1125
  } else if (pr) {
1126
- debug10("replaceTilde pr", pr);
1126
+ debug11("replaceTilde pr", pr);
1127
1127
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + (+m + 1) + ".0";
1128
1128
  } else {
1129
1129
  ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
1130
1130
  }
1131
- debug10("tilde return", ret);
1131
+ debug11("tilde return", ret);
1132
1132
  return ret;
1133
1133
  });
1134
1134
  }
@@ -1138,10 +1138,10 @@ var require_semver = __commonJS({
1138
1138
  }).join(" ");
1139
1139
  }
1140
1140
  function replaceCaret(comp, options) {
1141
- debug10("caret", comp, options);
1141
+ debug11("caret", comp, options);
1142
1142
  var r = options.loose ? safeRe[CARETLOOSE] : safeRe[CARET];
1143
1143
  return comp.replace(r, function(_, M, m, p, pr) {
1144
- debug10("caret", comp, _, M, m, p, pr);
1144
+ debug11("caret", comp, _, M, m, p, pr);
1145
1145
  var ret;
1146
1146
  if (isX(M)) {
1147
1147
  ret = "";
@@ -1154,7 +1154,7 @@ var require_semver = __commonJS({
1154
1154
  ret = ">=" + M + "." + m + ".0 <" + (+M + 1) + ".0.0";
1155
1155
  }
1156
1156
  } else if (pr) {
1157
- debug10("replaceCaret pr", pr);
1157
+ debug11("replaceCaret pr", pr);
1158
1158
  if (M === "0") {
1159
1159
  if (m === "0") {
1160
1160
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + m + "." + (+p + 1);
@@ -1165,7 +1165,7 @@ var require_semver = __commonJS({
1165
1165
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + (+M + 1) + ".0.0";
1166
1166
  }
1167
1167
  } else {
1168
- debug10("no pr");
1168
+ debug11("no pr");
1169
1169
  if (M === "0") {
1170
1170
  if (m === "0") {
1171
1171
  ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." + (+p + 1);
@@ -1176,12 +1176,12 @@ var require_semver = __commonJS({
1176
1176
  ret = ">=" + M + "." + m + "." + p + " <" + (+M + 1) + ".0.0";
1177
1177
  }
1178
1178
  }
1179
- debug10("caret return", ret);
1179
+ debug11("caret return", ret);
1180
1180
  return ret;
1181
1181
  });
1182
1182
  }
1183
1183
  function replaceXRanges(comp, options) {
1184
- debug10("replaceXRanges", comp, options);
1184
+ debug11("replaceXRanges", comp, options);
1185
1185
  return comp.split(/\s+/).map(function(comp2) {
1186
1186
  return replaceXRange(comp2, options);
1187
1187
  }).join(" ");
@@ -1190,7 +1190,7 @@ var require_semver = __commonJS({
1190
1190
  comp = comp.trim();
1191
1191
  var r = options.loose ? safeRe[XRANGELOOSE] : safeRe[XRANGE];
1192
1192
  return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
1193
- debug10("xRange", comp, ret, gtlt, M, m, p, pr);
1193
+ debug11("xRange", comp, ret, gtlt, M, m, p, pr);
1194
1194
  var xM = isX(M);
1195
1195
  var xm = xM || isX(m);
1196
1196
  var xp = xm || isX(p);
@@ -1233,12 +1233,12 @@ var require_semver = __commonJS({
1233
1233
  } else if (xp) {
1234
1234
  ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
1235
1235
  }
1236
- debug10("xRange return", ret);
1236
+ debug11("xRange return", ret);
1237
1237
  return ret;
1238
1238
  });
1239
1239
  }
1240
1240
  function replaceStars(comp, options) {
1241
- debug10("replaceStars", comp, options);
1241
+ debug11("replaceStars", comp, options);
1242
1242
  return comp.trim().replace(safeRe[STAR], "");
1243
1243
  }
1244
1244
  function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
@@ -1286,7 +1286,7 @@ var require_semver = __commonJS({
1286
1286
  }
1287
1287
  if (version2.prerelease.length && !options.includePrerelease) {
1288
1288
  for (i2 = 0; i2 < set.length; i2++) {
1289
- debug10(set[i2].semver);
1289
+ debug11(set[i2].semver);
1290
1290
  if (set[i2].semver === ANY) {
1291
1291
  continue;
1292
1292
  }
@@ -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 fs8;
1898
+ var fs9;
1899
1899
  try {
1900
- fs8 = require("fs");
1900
+ fs9 = 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 (!fs8)
1912
+ if (!fs9)
1913
1913
  return false;
1914
- return (stream instanceof (fs8.ReadStream || noop) || stream instanceof (fs8.WriteStream || noop)) && isFn(stream.close);
1914
+ return (stream instanceof (fs9.ReadStream || noop) || stream instanceof (fs9.WriteStream || noop)) && isFn(stream.close);
1915
1915
  };
1916
1916
  var isRequest = function(stream) {
1917
1917
  return stream.setHeader && isFn(stream.abort);
@@ -2651,7 +2651,7 @@ ${stderr}${stdout}`;
2651
2651
  var require_lib = __commonJS({
2652
2652
  "../../node_modules/.pnpm/which@3.0.0/node_modules/which/lib/index.js"(exports, module2) {
2653
2653
  var isexe = require_isexe();
2654
- var { join: join11, delimiter: delimiter2, sep: sep2, posix } = require("path");
2654
+ var { join: join12, delimiter: delimiter2, sep: sep2, posix } = require("path");
2655
2655
  var isWindows = process.platform === "win32";
2656
2656
  var rSlash = new RegExp(`[${posix.sep}${sep2 === posix.sep ? "" : sep2}]`.replace(/(\\)/g, "\\$1"));
2657
2657
  var rRel = new RegExp(`^\\.${rSlash.source}`);
@@ -2680,7 +2680,7 @@ var require_lib = __commonJS({
2680
2680
  var getPathPart = (raw, cmd) => {
2681
2681
  const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
2682
2682
  const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : "";
2683
- return prefix + join11(pathPart, cmd);
2683
+ return prefix + join12(pathPart, cmd);
2684
2684
  };
2685
2685
  var which2 = async (cmd, opt = {}) => {
2686
2686
  const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
@@ -2862,20 +2862,22 @@ __export(src_exports, {
2862
2862
  downloadFilesInWorkPath: () => downloadFilesInWorkPath,
2863
2863
  installRequirement: () => installRequirement,
2864
2864
  installRequirementsFile: () => installRequirementsFile,
2865
+ prepareCache: () => prepareCache,
2866
+ runFrameworkHook: () => runFrameworkHook,
2865
2867
  shouldServe: () => shouldServe,
2866
2868
  startDevServer: () => startDevServer,
2867
2869
  version: () => version
2868
2870
  });
2869
2871
  module.exports = __toCommonJS(src_exports);
2870
- var import_fs8 = __toESM(require("fs"));
2871
- var import_path11 = require("path");
2872
+ var import_fs10 = __toESM(require("fs"));
2873
+ var import_path12 = require("path");
2872
2874
 
2873
2875
  // src/package-versions.ts
2874
- var VERCEL_RUNTIME_VERSION = "0.5.6";
2876
+ var VERCEL_RUNTIME_VERSION = "0.7.0";
2875
2877
  var VERCEL_WORKERS_VERSION = "0.0.12";
2876
2878
 
2877
2879
  // src/index.ts
2878
- var import_build_utils12 = require("@vercel/build-utils");
2880
+ var import_build_utils13 = require("@vercel/build-utils");
2879
2881
 
2880
2882
  // src/install.ts
2881
2883
  var import_execa3 = __toESM(require_execa());
@@ -2902,14 +2904,19 @@ var import_build_utils = require("@vercel/build-utils");
2902
2904
  var UV_VERSION = "0.9.22";
2903
2905
  var UV_PYTHON_PATH_PREFIX = "/uv/python/";
2904
2906
  var UV_PYTHON_DOWNLOADS_MODE = "automatic";
2907
+ var UV_CACHE_DIR_SUBPATH = [".vercel", "python", "cache", "uv"];
2905
2908
  var isWin = process.platform === "win32";
2906
2909
  var uvExec = isWin ? "uv.exe" : "uv";
2907
2910
  function findUvInPath() {
2908
2911
  return import_which.default.sync("uv", { nothrow: true });
2909
2912
  }
2913
+ function getUvCacheDir(workPath) {
2914
+ return (0, import_path.join)(workPath, ...UV_CACHE_DIR_SUBPATH);
2915
+ }
2910
2916
  var UvRunner = class {
2911
- constructor(uvPath) {
2917
+ constructor(uvPath, uvCacheDir) {
2912
2918
  this.uvPath = uvPath;
2919
+ this.uvCacheDir = uvCacheDir;
2913
2920
  }
2914
2921
  getPath() {
2915
2922
  return this.uvPath;
@@ -2986,7 +2993,7 @@ var UvRunner = class {
2986
2993
  try {
2987
2994
  await (0, import_execa.default)(this.uvPath, args, {
2988
2995
  cwd: projectDir,
2989
- env: getProtectedUvEnv(process.env)
2996
+ env: getProtectedUvEnv(process.env, this.uvCacheDir)
2990
2997
  });
2991
2998
  } catch (err) {
2992
2999
  const error = new Error(
@@ -3051,7 +3058,7 @@ var UvRunner = class {
3051
3058
  const binDir = isWin ? (0, import_path.join)(venvPath, "Scripts") : (0, import_path.join)(venvPath, "bin");
3052
3059
  const existingPath = process.env.PATH || "";
3053
3060
  return {
3054
- ...getProtectedUvEnv(process.env),
3061
+ ...getProtectedUvEnv(process.env, this.uvCacheDir),
3055
3062
  VIRTUAL_ENV: venvPath,
3056
3063
  PATH: existingPath ? `${binDir}${import_path2.delimiter}${existingPath}` : binDir
3057
3064
  };
@@ -3158,11 +3165,15 @@ async function getUvBinaryOrInstall(pythonPath) {
3158
3165
  function filterUnsafeUvPipArgs(args) {
3159
3166
  return args.filter((arg) => arg !== "--no-warn-script-location");
3160
3167
  }
3161
- function getProtectedUvEnv(baseEnv = process.env) {
3162
- return {
3168
+ function getProtectedUvEnv(baseEnv = process.env, uvCacheDir) {
3169
+ const env = {
3163
3170
  ...baseEnv,
3164
3171
  UV_PYTHON_DOWNLOADS: UV_PYTHON_DOWNLOADS_MODE
3165
3172
  };
3173
+ if (uvCacheDir) {
3174
+ env.UV_CACHE_DIR = uvCacheDir;
3175
+ }
3176
+ return env;
3166
3177
  }
3167
3178
  var UV_BUNDLE_DIR = "_uv";
3168
3179
  async function getUvBinaryForBundling(pythonPath) {
@@ -3201,9 +3212,9 @@ function useVirtualEnv(workPath, env, systemPython) {
3201
3212
  }
3202
3213
  return { pythonCmd };
3203
3214
  }
3204
- function createVenvEnv(venvPath, baseEnv = process.env) {
3215
+ function createVenvEnv(venvPath, baseEnv = process.env, uvCacheDir) {
3205
3216
  const env = {
3206
- ...getProtectedUvEnv(baseEnv),
3217
+ ...getProtectedUvEnv(baseEnv, uvCacheDir),
3207
3218
  VIRTUAL_ENV: venvPath
3208
3219
  };
3209
3220
  const binDir = getVenvBinDir(venvPath);
@@ -3215,6 +3226,7 @@ async function ensureVenv({
3215
3226
  pythonPath,
3216
3227
  venvPath,
3217
3228
  uvPath,
3229
+ uvCacheDir,
3218
3230
  quiet
3219
3231
  }) {
3220
3232
  const marker = (0, import_path3.join)(venvPath, "pyvenv.cfg");
@@ -3228,7 +3240,9 @@ async function ensureVenv({
3228
3240
  console.log(`Creating virtual environment at "${venvPath}"...`);
3229
3241
  }
3230
3242
  if (uvPath) {
3231
- await (0, import_execa2.default)(uvPath, ["venv", venvPath]);
3243
+ await (0, import_execa2.default)(uvPath, ["venv", venvPath], {
3244
+ env: getProtectedUvEnv(process.env, uvCacheDir)
3245
+ });
3232
3246
  } else {
3233
3247
  await (0, import_execa2.default)(pythonPath, ["-m", "venv", venvPath]);
3234
3248
  }
@@ -3735,7 +3749,7 @@ async function pipInstall(pipPath, uvPath, workPath, args, targetDir) {
3735
3749
  try {
3736
3750
  await (0, import_execa3.default)(uvPath, uvArgs, {
3737
3751
  cwd: workPath,
3738
- env: getProtectedUvEnv()
3752
+ env: getProtectedUvEnv(process.env, getUvCacheDir(workPath))
3739
3753
  });
3740
3754
  return;
3741
3755
  } catch (err) {
@@ -4202,13 +4216,14 @@ async function calculatePerPackageSizes(venvPath) {
4202
4216
 
4203
4217
  // src/start-dev-server.ts
4204
4218
  var import_child_process2 = require("child_process");
4205
- var import_fs5 = require("fs");
4219
+ var import_fs6 = require("fs");
4206
4220
  var import_path8 = require("path");
4207
4221
  var import_build_utils8 = require("@vercel/build-utils");
4208
4222
  var import_get_port = __toESM(require_get_port());
4209
4223
  var import_is_port_reachable = __toESM(require_is_port_reachable());
4210
4224
 
4211
4225
  // src/entrypoint.ts
4226
+ var import_fs5 = __toESM(require("fs"));
4212
4227
  var import_path7 = require("path");
4213
4228
  var import_build_utils6 = require("@vercel/build-utils");
4214
4229
  var import_build_utils7 = require("@vercel/build-utils");
@@ -4231,6 +4246,20 @@ function getCandidateEntrypointsInDirs(dirs) {
4231
4246
  )
4232
4247
  );
4233
4248
  }
4249
+ async function fileExists(filePath) {
4250
+ try {
4251
+ const stat = await import_fs5.default.promises.stat(filePath);
4252
+ return stat.isFile();
4253
+ } catch {
4254
+ return false;
4255
+ }
4256
+ }
4257
+ async function checkEntrypoint(workPath, relPath) {
4258
+ const absPath = (0, import_path7.join)(workPath, relPath);
4259
+ if (!await fileExists(absPath))
4260
+ return false;
4261
+ return (0, import_build_utils6.isPythonEntrypoint)({ fsPath: absPath });
4262
+ }
4234
4263
  async function getPyprojectEntrypoint(workPath) {
4235
4264
  const pyprojectData = await (0, import_build_utils7.readConfigFile)((0, import_path7.join)(workPath, "pyproject.toml"));
4236
4265
  if (!pyprojectData)
@@ -4244,46 +4273,56 @@ async function getPyprojectEntrypoint(workPath) {
4244
4273
  return null;
4245
4274
  const modulePath = match[1];
4246
4275
  const relPath = modulePath.replace(/\./g, "/");
4247
- try {
4248
- const fsFiles = await (0, import_build_utils6.glob)("**", workPath);
4249
- const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
4250
- for (const candidate of candidates) {
4251
- if (fsFiles[candidate])
4252
- return candidate;
4253
- }
4254
- return null;
4255
- } catch {
4256
- (0, import_build_utils6.debug)("Failed to discover Python entrypoint from pyproject.toml");
4257
- return null;
4276
+ const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
4277
+ for (const candidate of candidates) {
4278
+ if (await fileExists((0, import_path7.join)(workPath, candidate)))
4279
+ return candidate;
4258
4280
  }
4281
+ return null;
4259
4282
  }
4260
- async function findValidEntrypoint(fsFiles, candidates) {
4283
+ async function findValidEntrypoint(workPath, candidates) {
4261
4284
  for (const candidate of candidates) {
4262
- if (fsFiles[candidate]) {
4263
- const isValid = await (0, import_build_utils6.isPythonEntrypoint)(fsFiles[candidate]);
4264
- if (isValid) {
4265
- (0, import_build_utils6.debug)(`Detected Python entrypoint: ${candidate}`);
4266
- return candidate;
4267
- }
4285
+ if (await checkEntrypoint(workPath, candidate)) {
4286
+ (0, import_build_utils6.debug)(`Detected Python entrypoint: ${candidate}`);
4287
+ return candidate;
4268
4288
  }
4269
4289
  }
4270
4290
  return null;
4271
4291
  }
4292
+ async function checkDjangoManage(workPath) {
4293
+ const managePath = (0, import_path7.join)(workPath, "manage.py");
4294
+ try {
4295
+ const content = await import_fs5.default.promises.readFile(managePath, "utf-8");
4296
+ if (!content.includes("DJANGO_SETTINGS_MODULE"))
4297
+ return false;
4298
+ (0, import_build_utils6.debug)(`Found Django manage.py with DJANGO_SETTINGS_MODULE at ${workPath}`);
4299
+ return true;
4300
+ } catch {
4301
+ return false;
4302
+ }
4303
+ }
4304
+ async function getSubdirectories(workPath) {
4305
+ try {
4306
+ const entries = await import_fs5.default.promises.readdir(workPath, {
4307
+ withFileTypes: true
4308
+ });
4309
+ return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name).sort();
4310
+ } catch {
4311
+ return [];
4312
+ }
4313
+ }
4272
4314
  async function detectGenericPythonEntrypoint(workPath, configuredEntrypoint) {
4273
4315
  const entry = configuredEntrypoint.endsWith(".py") ? configuredEntrypoint : `${configuredEntrypoint}.py`;
4274
4316
  try {
4275
- const fsFiles = await (0, import_build_utils6.glob)("**", workPath);
4276
- if (fsFiles[entry]) {
4277
- const isValid = await (0, import_build_utils6.isPythonEntrypoint)(fsFiles[entry]);
4278
- if (isValid) {
4279
- (0, import_build_utils6.debug)(`Using configured Python entrypoint: ${entry}`);
4280
- return entry;
4281
- }
4317
+ if (await checkEntrypoint(workPath, entry)) {
4318
+ (0, import_build_utils6.debug)(`Using configured Python entrypoint: ${entry}`);
4319
+ return { entrypoint: entry };
4282
4320
  }
4283
- const candidates = PYTHON_CANDIDATE_ENTRYPOINTS.filter(
4284
- (c) => !!fsFiles[c]
4321
+ const found = await findValidEntrypoint(
4322
+ workPath,
4323
+ PYTHON_CANDIDATE_ENTRYPOINTS
4285
4324
  );
4286
- return findValidEntrypoint(fsFiles, candidates);
4325
+ return found ? { entrypoint: found } : null;
4287
4326
  } catch {
4288
4327
  (0, import_build_utils6.debug)("Failed to discover Python entrypoint");
4289
4328
  return null;
@@ -4292,48 +4331,33 @@ async function detectGenericPythonEntrypoint(workPath, configuredEntrypoint) {
4292
4331
  async function detectDjangoPythonEntrypoint(workPath, configuredEntrypoint) {
4293
4332
  const entry = configuredEntrypoint.endsWith(".py") ? configuredEntrypoint : `${configuredEntrypoint}.py`;
4294
4333
  try {
4295
- const fsFiles = await (0, import_build_utils6.glob)("**", workPath);
4296
- if (fsFiles[entry]) {
4297
- const isValid = await (0, import_build_utils6.isPythonEntrypoint)(fsFiles[entry]);
4298
- if (isValid) {
4299
- (0, import_build_utils6.debug)(`Using configured Python entrypoint: ${entry}`);
4300
- return entry;
4301
- }
4334
+ if (await checkEntrypoint(workPath, entry)) {
4335
+ (0, import_build_utils6.debug)(`Using configured Python entrypoint: ${entry}`);
4336
+ return { entrypoint: entry };
4302
4337
  }
4303
- const rootGlobs = await (0, import_build_utils6.glob)("*", {
4304
- cwd: workPath,
4305
- includeDirectories: true
4306
- });
4307
- const rootDirs = [
4308
- "",
4309
- ...Object.keys(rootGlobs).filter(
4310
- (name) => !name.startsWith(".") && rootGlobs[name].mode != null && (0, import_build_utils6.isDirectory)(rootGlobs[name].mode)
4311
- )
4312
- ];
4338
+ const subdirs = await getSubdirectories(workPath);
4339
+ const rootDirs = ["", ...subdirs];
4313
4340
  for (const rootDir of rootDirs) {
4314
4341
  const currPath = (0, import_path7.join)(workPath, rootDir);
4315
- const wsgiEntry = await (0, import_build_utils6.getDjangoEntrypoint)(currPath);
4316
- if (wsgiEntry) {
4317
- const fullWsgiEntry = import_path7.posix.join(rootDir, wsgiEntry);
4318
- if (fsFiles[fullWsgiEntry]) {
4319
- (0, import_build_utils6.debug)(`Using Django WSGI entrypoint: ${fullWsgiEntry}`);
4320
- return fullWsgiEntry;
4321
- }
4342
+ const isDjango = await checkDjangoManage(currPath);
4343
+ if (isDjango) {
4344
+ return { baseDir: rootDir };
4322
4345
  }
4323
4346
  }
4324
- const baseCandidates = getCandidateEntrypointsInDirs(rootDirs);
4325
- const candidates = baseCandidates.filter((c) => !!fsFiles[c]);
4326
- return findValidEntrypoint(fsFiles, candidates);
4347
+ const candidates = getCandidateEntrypointsInDirs(rootDirs);
4348
+ const found = await findValidEntrypoint(workPath, candidates);
4349
+ return found ? { entrypoint: found } : null;
4327
4350
  } catch {
4328
4351
  (0, import_build_utils6.debug)("Failed to discover Django Python entrypoint");
4329
4352
  return null;
4330
4353
  }
4331
4354
  }
4332
4355
  async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint) {
4333
- const entrypoint = framework === "django" ? await detectDjangoPythonEntrypoint(workPath, configuredEntrypoint) : await detectGenericPythonEntrypoint(workPath, configuredEntrypoint);
4334
- if (entrypoint)
4335
- return entrypoint;
4336
- return await getPyprojectEntrypoint(workPath);
4356
+ const result = framework === "django" ? await detectDjangoPythonEntrypoint(workPath, configuredEntrypoint) : await detectGenericPythonEntrypoint(workPath, configuredEntrypoint);
4357
+ if (result)
4358
+ return result;
4359
+ const pyprojectEntry = await getPyprojectEntrypoint(workPath);
4360
+ return pyprojectEntry ? { entrypoint: pyprojectEntry } : null;
4337
4361
  }
4338
4362
 
4339
4363
  // src/start-dev-server.ts
@@ -4424,10 +4448,10 @@ async function syncDependencies({
4424
4448
  }
4425
4449
  if (manifest?.origin && manifestType === "pyproject.toml") {
4426
4450
  const syncDir = (0, import_path8.join)(workPath, ".vercel", "python", "sync");
4427
- (0, import_fs5.mkdirSync)(syncDir, { recursive: true });
4451
+ (0, import_fs6.mkdirSync)(syncDir, { recursive: true });
4428
4452
  const tempPyproject = (0, import_path8.join)(syncDir, "pyproject.toml");
4429
4453
  const content = (0, import_python_analysis4.stringifyManifest)(manifest.data);
4430
- (0, import_fs5.writeFileSync)(tempPyproject, content, "utf8");
4454
+ (0, import_fs6.writeFileSync)(tempPyproject, content, "utf8");
4431
4455
  manifestPath = tempPyproject;
4432
4456
  (0, import_build_utils8.debug)(
4433
4457
  `Wrote converted ${manifest.origin.kind} manifest to ${tempPyproject}`
@@ -4544,6 +4568,77 @@ async function runSync({
4544
4568
  });
4545
4569
  });
4546
4570
  }
4571
+ async function installVercelRuntime({
4572
+ workPath,
4573
+ uvPath,
4574
+ pythonBin,
4575
+ env,
4576
+ onStdout,
4577
+ onStderr
4578
+ }) {
4579
+ const targetDir = (0, import_path8.join)(workPath, ".vercel", "python");
4580
+ (0, import_fs6.mkdirSync)(targetDir, { recursive: true });
4581
+ const localRuntimeDir = (0, import_path8.join)(
4582
+ __dirname,
4583
+ "..",
4584
+ "..",
4585
+ "..",
4586
+ "python",
4587
+ "vercel-runtime"
4588
+ );
4589
+ const isLocalDev = (0, import_fs6.existsSync)((0, import_path8.join)(localRuntimeDir, "pyproject.toml"));
4590
+ const runtimeDep = env.VERCEL_RUNTIME_PYTHON || (isLocalDev ? localRuntimeDir : `vercel-runtime==${VERCEL_RUNTIME_VERSION}`);
4591
+ if (!isLocalDev && !env.VERCEL_RUNTIME_PYTHON) {
4592
+ const distInfo = (0, import_path8.join)(
4593
+ targetDir,
4594
+ `vercel_runtime-${VERCEL_RUNTIME_VERSION}.dist-info`
4595
+ );
4596
+ if ((0, import_fs6.existsSync)(distInfo)) {
4597
+ (0, import_build_utils8.debug)(
4598
+ `vercel-runtime ${VERCEL_RUNTIME_VERSION} already installed, skipping`
4599
+ );
4600
+ return;
4601
+ }
4602
+ }
4603
+ (0, import_build_utils8.debug)(
4604
+ `Installing vercel-runtime into ${targetDir} (type: ${isLocalDev ? "local" : "pypi"}, source: ${runtimeDep})`
4605
+ );
4606
+ const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
4607
+ const spawnArgs = [...pip.prefix, "--target", targetDir, runtimeDep];
4608
+ await new Promise((resolve2, reject) => {
4609
+ const child = (0, import_child_process2.spawn)(pip.cmd, spawnArgs, {
4610
+ cwd: workPath,
4611
+ env: getProtectedUvEnv(env),
4612
+ stdio: ["inherit", "pipe", "pipe"]
4613
+ });
4614
+ child.stdout?.on("data", (data) => {
4615
+ if (onStdout) {
4616
+ onStdout(data);
4617
+ } else {
4618
+ (0, import_build_utils8.debug)(data.toString());
4619
+ }
4620
+ });
4621
+ child.stderr?.on("data", (data) => {
4622
+ if (onStderr) {
4623
+ onStderr(data);
4624
+ } else {
4625
+ (0, import_build_utils8.debug)(data.toString());
4626
+ }
4627
+ });
4628
+ child.on("error", reject);
4629
+ child.on("exit", (code, signal) => {
4630
+ if (code === 0) {
4631
+ resolve2();
4632
+ } else {
4633
+ reject(
4634
+ new Error(
4635
+ `Installing vercel-runtime failed with code ${code}, signal ${signal}`
4636
+ )
4637
+ );
4638
+ }
4639
+ });
4640
+ });
4641
+ }
4547
4642
  var PERSISTENT_SERVERS = /* @__PURE__ */ new Map();
4548
4643
  var PENDING_STARTS = /* @__PURE__ */ new Map();
4549
4644
  var restoreWarnings = null;
@@ -4588,20 +4683,25 @@ function installGlobalCleanupHandlers() {
4588
4683
  function createDevShim(workPath, entry, modulePath) {
4589
4684
  try {
4590
4685
  const vercelPythonDir = (0, import_path8.join)(workPath, ".vercel", "python");
4591
- (0, import_fs5.mkdirSync)(vercelPythonDir, { recursive: true });
4686
+ (0, import_fs6.mkdirSync)(vercelPythonDir, { recursive: true });
4592
4687
  let qualifiedModule = modulePath;
4593
4688
  let extraPythonPath;
4594
- if ((0, import_fs5.existsSync)((0, import_path8.join)(workPath, "__init__.py"))) {
4689
+ if ((0, import_fs6.existsSync)((0, import_path8.join)(workPath, "__init__.py"))) {
4595
4690
  const pkgName = (0, import_path8.basename)(workPath);
4596
4691
  qualifiedModule = `${pkgName}.${modulePath}`;
4597
4692
  extraPythonPath = (0, import_path8.dirname)(workPath);
4598
4693
  }
4599
4694
  const entryAbs = (0, import_path8.join)(workPath, entry);
4600
4695
  const shimPath = (0, import_path8.join)(vercelPythonDir, `${DEV_SHIM_MODULE}.py`);
4601
- const templatePath = (0, import_path8.join)(__dirname, "..", `${DEV_SHIM_MODULE}.py`);
4602
- const template = (0, import_fs5.readFileSync)(templatePath, "utf8");
4696
+ const templatePath = (0, import_path8.join)(
4697
+ __dirname,
4698
+ "..",
4699
+ "templates",
4700
+ `${DEV_SHIM_MODULE}.py`
4701
+ );
4702
+ const template = (0, import_fs6.readFileSync)(templatePath, "utf8");
4603
4703
  const shimSource = template.replace(/__VC_DEV_MODULE_NAME__/g, qualifiedModule).replace(/__VC_DEV_ENTRY_ABS__/g, entryAbs);
4604
- (0, import_fs5.writeFileSync)(shimPath, shimSource, "utf8");
4704
+ (0, import_fs6.writeFileSync)(shimPath, shimSource, "utf8");
4605
4705
  (0, import_build_utils8.debug)(`Prepared Python dev shim at ${shimPath}`);
4606
4706
  return { module: DEV_SHIM_MODULE, extraPythonPath };
4607
4707
  } catch (err) {
@@ -4616,7 +4716,12 @@ async function getMultiServicePythonRunner(workPath, env, systemPython, uvPath)
4616
4716
  return { command: pythonCmd, args: [] };
4617
4717
  }
4618
4718
  const venvPath = (0, import_path8.join)(workPath, ".venv");
4619
- await ensureVenv({ pythonPath: systemPython, venvPath, uvPath, quiet: true });
4719
+ await ensureVenv({
4720
+ pythonPath: systemPython,
4721
+ venvPath,
4722
+ uvPath,
4723
+ quiet: true
4724
+ });
4620
4725
  (0, import_build_utils8.debug)(`Created virtualenv at ${venvPath} for multi-service dev`);
4621
4726
  const pythonBin = getVenvPythonBin(venvPath);
4622
4727
  const binDir = getVenvBinDir(venvPath);
@@ -4634,29 +4739,7 @@ var startDevServer = async (opts) => {
4634
4739
  onStderr
4635
4740
  } = opts;
4636
4741
  const framework = config?.framework;
4637
- if (!framework) {
4638
- return null;
4639
- }
4640
- if (!restoreWarnings)
4641
- restoreWarnings = silenceNodeWarnings();
4642
- installGlobalCleanupHandlers();
4643
- const entry = await detectPythonEntrypoint(
4644
- framework,
4645
- workPath,
4646
- rawEntrypoint
4647
- );
4648
- if (!entry) {
4649
- const searched = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
4650
- throw new import_build_utils8.NowBuildError({
4651
- code: "PYTHON_ENTRYPOINT_NOT_FOUND",
4652
- message: `No ${framework} entrypoint found. Add an 'app' script in pyproject.toml or define an entrypoint in one of: ${searched}.`,
4653
- link: `https://vercel.com/docs/frameworks/backend/${framework?.toLowerCase()}#exporting-the-${framework?.toLowerCase()}-application`,
4654
- action: "Learn More"
4655
- });
4656
- }
4657
- const modulePath = entry.replace(/\.py$/i, "").replace(/[\\/]/g, ".");
4658
- const env = { ...process.env, ...meta.env || {} };
4659
- const serverKey = `${workPath}::${entry}::${framework}`;
4742
+ const serverKey = `${workPath}::${framework}`;
4660
4743
  const existing = PERSISTENT_SERVERS.get(serverKey);
4661
4744
  if (existing) {
4662
4745
  return {
@@ -4678,6 +4761,38 @@ var startDevServer = async (opts) => {
4678
4761
  };
4679
4762
  }
4680
4763
  }
4764
+ if (!framework) {
4765
+ return null;
4766
+ }
4767
+ if (!restoreWarnings)
4768
+ restoreWarnings = silenceNodeWarnings();
4769
+ installGlobalCleanupHandlers();
4770
+ const detected = await detectPythonEntrypoint(
4771
+ framework,
4772
+ workPath,
4773
+ rawEntrypoint
4774
+ );
4775
+ const env = { ...process.env, ...meta.env || {} };
4776
+ let entry = detected?.entrypoint;
4777
+ if (!entry) {
4778
+ const hookResult = await runFrameworkHook(framework, {
4779
+ pythonEnv: env,
4780
+ projectDir: (0, import_path8.join)(workPath, detected?.baseDir ?? ""),
4781
+ entrypoint: rawEntrypoint,
4782
+ detected: detected ?? void 0
4783
+ });
4784
+ entry = hookResult?.entrypoint;
4785
+ }
4786
+ if (!entry) {
4787
+ const searched = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
4788
+ throw new import_build_utils8.NowBuildError({
4789
+ code: "PYTHON_ENTRYPOINT_NOT_FOUND",
4790
+ message: `No ${framework} entrypoint found. Add an 'app' script in pyproject.toml or define an entrypoint in one of: ${searched}.`,
4791
+ link: `https://vercel.com/docs/frameworks/backend/${framework?.toLowerCase()}#exporting-the-${framework?.toLowerCase()}-application`,
4792
+ action: "Learn More"
4793
+ });
4794
+ }
4795
+ const modulePath = entry.replace(/\.py$/i, "").replace(/[\\/]/g, ".");
4681
4796
  let childProcess = null;
4682
4797
  let stdoutLogListener = null;
4683
4798
  let stderrLogListener = null;
@@ -4765,6 +4880,12 @@ If you are using a virtual environment, activate it before running "vercel dev",
4765
4880
  onStderr
4766
4881
  });
4767
4882
  }
4883
+ await installVercelRuntime({
4884
+ workPath,
4885
+ uvPath,
4886
+ pythonBin: spawnCommand,
4887
+ env
4888
+ });
4768
4889
  const port = typeof meta.port === "number" ? meta.port : await (0, import_get_port.default)();
4769
4890
  env.PORT = `${port}`;
4770
4891
  const devShim = createDevShim(workPath, entry, modulePath);
@@ -4851,7 +4972,7 @@ var matplotlibQuirk = {
4851
4972
  };
4852
4973
 
4853
4974
  // src/quirks/litellm.ts
4854
- var import_fs6 = __toESM(require("fs"));
4975
+ var import_fs7 = __toESM(require("fs"));
4855
4976
  var import_path9 = require("path");
4856
4977
  var import_build_utils9 = require("@vercel/build-utils");
4857
4978
  var LAMBDA_ROOT = "/var/task";
@@ -4865,7 +4986,7 @@ async function findConfigFile(workPath) {
4865
4986
  for (const name of CONFIG_CANDIDATES) {
4866
4987
  const candidate = (0, import_path9.join)(workPath, name);
4867
4988
  try {
4868
- await import_fs6.default.promises.access(candidate);
4989
+ await import_fs7.default.promises.access(candidate);
4869
4990
  return name;
4870
4991
  } catch {
4871
4992
  }
@@ -4887,7 +5008,7 @@ var litellmQuirk = {
4887
5008
  "schema.prisma"
4888
5009
  );
4889
5010
  try {
4890
- await import_fs6.default.promises.access(schemaPath);
5011
+ await import_fs7.default.promises.access(schemaPath);
4891
5012
  (0, import_build_utils9.debug)(`LiteLLM quirk: found schema at ${schemaPath}`);
4892
5013
  buildEnv.PRISMA_SCHEMA_PATH = schemaPath;
4893
5014
  break;
@@ -4914,7 +5035,7 @@ var litellmQuirk = {
4914
5035
  };
4915
5036
 
4916
5037
  // src/quirks/prisma.ts
4917
- var import_fs7 = __toESM(require("fs"));
5038
+ var import_fs8 = __toESM(require("fs"));
4918
5039
  var import_path10 = require("path");
4919
5040
  var import_execa4 = __toESM(require_execa());
4920
5041
  var import_build_utils10 = require("@vercel/build-utils");
@@ -4956,7 +5077,7 @@ async function findUserSchema(workPath) {
4956
5077
  if (envPath) {
4957
5078
  const resolved = (0, import_path10.isAbsolute)(envPath) ? envPath : (0, import_path10.join)(workPath, envPath);
4958
5079
  try {
4959
- await import_fs7.default.promises.access(resolved);
5080
+ await import_fs8.default.promises.access(resolved);
4960
5081
  return resolved;
4961
5082
  } catch {
4962
5083
  (0, import_build_utils10.debug)(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`);
@@ -4969,7 +5090,7 @@ async function findUserSchema(workPath) {
4969
5090
  ];
4970
5091
  for (const candidate of candidates) {
4971
5092
  try {
4972
- await import_fs7.default.promises.access(candidate);
5093
+ await import_fs8.default.promises.access(candidate);
4973
5094
  return candidate;
4974
5095
  } catch {
4975
5096
  }
@@ -4980,7 +5101,7 @@ async function collectFiles(dir, base) {
4980
5101
  const result = [];
4981
5102
  let entries;
4982
5103
  try {
4983
- entries = await import_fs7.default.promises.readdir(dir, { withFileTypes: true });
5104
+ entries = await import_fs8.default.promises.readdir(dir, { withFileTypes: true });
4984
5105
  } catch {
4985
5106
  return result;
4986
5107
  }
@@ -5005,7 +5126,7 @@ async function cleanCacheArtifacts(cacheDir, extras = []) {
5005
5126
  ];
5006
5127
  for (const p of paths) {
5007
5128
  try {
5008
- await import_fs7.default.promises.rm(p, { recursive: true, force: true });
5129
+ await import_fs8.default.promises.rm(p, { recursive: true, force: true });
5009
5130
  } catch (err) {
5010
5131
  console.warn(
5011
5132
  `could not clean up ${p}: ${err instanceof Error ? err.message : String(err)}`
@@ -5039,7 +5160,7 @@ var prismaQuirk = {
5039
5160
  let sitePackages;
5040
5161
  for (const dir of sitePackagesDirs) {
5041
5162
  try {
5042
- await import_fs7.default.promises.access((0, import_path10.join)(dir, "prisma"));
5163
+ await import_fs8.default.promises.access((0, import_path10.join)(dir, "prisma"));
5043
5164
  sitePackages = dir;
5044
5165
  break;
5045
5166
  } catch {
@@ -5052,14 +5173,14 @@ var prismaQuirk = {
5052
5173
  return {};
5053
5174
  }
5054
5175
  const cacheDir = (0, import_path10.join)(sitePackages, "prisma", "__bincache__");
5055
- await import_fs7.default.promises.mkdir(cacheDir, { recursive: true });
5176
+ await import_fs8.default.promises.mkdir(cacheDir, { recursive: true });
5056
5177
  const generateEnv = {
5057
5178
  ...pythonEnv,
5058
5179
  PRISMA_BINARY_CACHE_DIR: cacheDir
5059
5180
  };
5060
5181
  const generatedDir = (0, import_path10.join)(workPath, "_prisma_generated");
5061
5182
  const dummySchemaPath = (0, import_path10.join)(workPath, DUMMY_SCHEMA_NAME);
5062
- await import_fs7.default.promises.writeFile(
5183
+ await import_fs8.default.promises.writeFile(
5063
5184
  dummySchemaPath,
5064
5185
  buildDummySchema(generatedDir)
5065
5186
  );
@@ -5090,18 +5211,18 @@ var prismaQuirk = {
5090
5211
  const nodeModulesDir = (0, import_path10.join)(cacheDir, "node_modules", "prisma");
5091
5212
  let engineCopied = false;
5092
5213
  try {
5093
- const entries = await import_fs7.default.promises.readdir(nodeModulesDir);
5214
+ const entries = await import_fs8.default.promises.readdir(nodeModulesDir);
5094
5215
  for (const entry of entries) {
5095
5216
  if (!entry.startsWith(srcBinaryPrefix))
5096
5217
  continue;
5097
5218
  const srcPath = (0, import_path10.join)(nodeModulesDir, entry);
5098
5219
  const destPath = (0, import_path10.join)(cacheDir, runtimeName);
5099
5220
  try {
5100
- await import_fs7.default.promises.access(destPath);
5221
+ await import_fs8.default.promises.access(destPath);
5101
5222
  (0, import_build_utils10.debug)(`Engine binary: ${runtimeName} already exists, skipping`);
5102
5223
  } catch {
5103
5224
  (0, import_build_utils10.debug)(`Engine binary: copying ${entry} -> ${runtimeName}`);
5104
- await import_fs7.default.promises.copyFile(srcPath, destPath);
5225
+ await import_fs8.default.promises.copyFile(srcPath, destPath);
5105
5226
  }
5106
5227
  engineCopied = true;
5107
5228
  }
@@ -5119,15 +5240,15 @@ var prismaQuirk = {
5119
5240
  });
5120
5241
  }
5121
5242
  const shimPath = (0, import_path10.join)(cacheDir, "openssl");
5122
- await import_fs7.default.promises.writeFile(
5243
+ await import_fs8.default.promises.writeFile(
5123
5244
  shimPath,
5124
5245
  `#!/bin/sh
5125
5246
  echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIME_OPENSSL_VERSION}.0)"
5126
5247
  `
5127
5248
  );
5128
- await import_fs7.default.promises.chmod(shimPath, 493);
5249
+ await import_fs8.default.promises.chmod(shimPath, 493);
5129
5250
  for (const p of [generatedDir, dummySchemaPath]) {
5130
- await import_fs7.default.promises.rm(p, { recursive: true, force: true });
5251
+ await import_fs8.default.promises.rm(p, { recursive: true, force: true });
5131
5252
  }
5132
5253
  await cleanCacheArtifacts(cacheDir);
5133
5254
  const generateMode = (process.env.VERCEL_PRISMA_GENERATE_CLIENT ?? "auto").toLowerCase();
@@ -5299,22 +5420,74 @@ async function runQuirks(ctx) {
5299
5420
  };
5300
5421
  }
5301
5422
 
5423
+ // src/django.ts
5424
+ var import_fs9 = require("fs");
5425
+ var import_path11 = require("path");
5426
+ var import_execa5 = __toESM(require_execa());
5427
+ var import_build_utils12 = require("@vercel/build-utils");
5428
+ var scriptPath = (0, import_path11.join)(__dirname, "..", "templates", "vc_django_settings.py");
5429
+ var script = (0, import_fs9.readFileSync)(scriptPath, "utf-8");
5430
+ async function getDjangoSettings(projectDir, env) {
5431
+ try {
5432
+ const { stdout } = await (0, import_execa5.default)("python", ["-c", script], {
5433
+ env,
5434
+ cwd: projectDir
5435
+ });
5436
+ return JSON.parse(stdout);
5437
+ } catch (err) {
5438
+ (0, import_build_utils12.debug)(`Django hook: failed to discover settings from manage.py: ${err}`);
5439
+ return null;
5440
+ }
5441
+ }
5442
+
5302
5443
  // src/index.ts
5303
- var writeFile = import_fs8.default.promises.writeFile;
5444
+ var import_python_analysis7 = require("@vercel/python-analysis");
5445
+ var writeFile = import_fs10.default.promises.writeFile;
5304
5446
  var version = 3;
5447
+ async function runFrameworkHook(framework, ctx) {
5448
+ const hook = framework ? frameworkHooks[framework] : void 0;
5449
+ return hook?.(ctx);
5450
+ }
5451
+ var frameworkHooks = {
5452
+ django: async ({ pythonEnv, projectDir, detected }) => {
5453
+ if (detected?.baseDir === void 0) {
5454
+ (0, import_build_utils13.debug)("Django hook: no manage.py detected, skipping");
5455
+ return;
5456
+ }
5457
+ const settings = await getDjangoSettings(projectDir, pythonEnv);
5458
+ (0, import_build_utils13.debug)(`Django settings: ${JSON.stringify(settings)}`);
5459
+ if (!settings)
5460
+ return;
5461
+ const baseDir = detected?.baseDir ?? "";
5462
+ const asgiApp = settings["ASGI_APPLICATION"];
5463
+ if (typeof asgiApp === "string") {
5464
+ const rel = `${asgiApp.split(".").slice(0, -1).join("/")}.py`;
5465
+ const entrypoint = baseDir ? `${baseDir}/${rel}` : rel;
5466
+ (0, import_build_utils13.debug)(`Django hook: ASGI entrypoint: ${entrypoint}`);
5467
+ return { entrypoint };
5468
+ }
5469
+ const wsgiApp = settings["WSGI_APPLICATION"];
5470
+ if (typeof wsgiApp === "string") {
5471
+ const rel = `${wsgiApp.split(".").slice(0, -1).join("/")}.py`;
5472
+ const entrypoint = baseDir ? `${baseDir}/${rel}` : rel;
5473
+ (0, import_build_utils13.debug)(`Django hook: WSGI entrypoint: ${entrypoint}`);
5474
+ return { entrypoint };
5475
+ }
5476
+ }
5477
+ };
5305
5478
  async function downloadFilesInWorkPath({
5306
5479
  entrypoint,
5307
5480
  workPath,
5308
5481
  files,
5309
5482
  meta = {}
5310
5483
  }) {
5311
- (0, import_build_utils12.debug)("Downloading user files...");
5312
- let downloadedFiles = await (0, import_build_utils12.download)(files, workPath, meta);
5484
+ (0, import_build_utils13.debug)("Downloading user files...");
5485
+ let downloadedFiles = await (0, import_build_utils13.download)(files, workPath, meta);
5313
5486
  if (meta.isDev) {
5314
- const { devCacheDir = (0, import_path11.join)(workPath, ".now", "cache") } = meta;
5315
- const destCache = (0, import_path11.join)(devCacheDir, (0, import_path11.basename)(entrypoint, ".py"));
5316
- await (0, import_build_utils12.download)(downloadedFiles, destCache);
5317
- downloadedFiles = await (0, import_build_utils12.glob)("**", destCache);
5487
+ const { devCacheDir = (0, import_path12.join)(workPath, ".now", "cache") } = meta;
5488
+ const destCache = (0, import_path12.join)(devCacheDir, (0, import_path12.basename)(entrypoint, ".py"));
5489
+ await (0, import_build_utils13.download)(downloadedFiles, destCache);
5490
+ downloadedFiles = await (0, import_build_utils13.glob)("**", destCache);
5318
5491
  workPath = destCache;
5319
5492
  }
5320
5493
  return workPath;
@@ -5328,13 +5501,13 @@ var build = async ({
5328
5501
  config,
5329
5502
  span: parentSpan
5330
5503
  }) => {
5331
- const builderSpan = parentSpan ?? new import_build_utils12.Span({ name: "vc.builder" });
5504
+ const builderSpan = parentSpan ?? new import_build_utils13.Span({ name: "vc.builder" });
5332
5505
  const framework = config?.framework;
5333
5506
  const shouldInstallVercelWorkers = config?.hasWorkerServices === true;
5334
5507
  let spawnEnv;
5335
5508
  let projectInstallCommand;
5336
5509
  let hasCustomCommand = false;
5337
- (0, import_build_utils12.debug)(`workPath: ${workPath}`);
5510
+ (0, import_build_utils13.debug)(`workPath: ${workPath}`);
5338
5511
  workPath = await downloadFilesInWorkPath({
5339
5512
  workPath,
5340
5513
  files: originalFiles,
@@ -5343,28 +5516,31 @@ var build = async ({
5343
5516
  });
5344
5517
  try {
5345
5518
  if (meta.isDev) {
5346
- const setupCfg = (0, import_path11.join)(workPath, "setup.cfg");
5519
+ const setupCfg = (0, import_path12.join)(workPath, "setup.cfg");
5347
5520
  await writeFile(setupCfg, "[install]\nprefix=\n");
5348
5521
  }
5349
5522
  } catch (err) {
5350
5523
  console.log('Failed to create "setup.cfg" file');
5351
5524
  throw err;
5352
5525
  }
5353
- let fsFiles = await (0, import_build_utils12.glob)("**", workPath);
5354
- if ((0, import_build_utils12.isPythonFramework)(framework) && (!fsFiles[entrypoint] || !entrypoint.endsWith(".py"))) {
5355
- const detected = await detectPythonEntrypoint(
5526
+ let fsFiles = await (0, import_build_utils13.glob)("**", workPath);
5527
+ let detected;
5528
+ let entrypointNotFound;
5529
+ if ((0, import_build_utils13.isPythonFramework)(framework) && // XXX: we might want to detect anyway for django!
5530
+ (!fsFiles[entrypoint] || !entrypoint.endsWith(".py"))) {
5531
+ detected = await detectPythonEntrypoint(
5356
5532
  config.framework,
5357
5533
  workPath,
5358
5534
  entrypoint
5359
- );
5360
- if (detected) {
5361
- (0, import_build_utils12.debug)(
5362
- `Resolved Python entrypoint to "${detected}" (configured "${entrypoint}" not found).`
5535
+ ) ?? void 0;
5536
+ if (detected?.entrypoint) {
5537
+ (0, import_build_utils13.debug)(
5538
+ `Resolved Python entrypoint to "${detected.entrypoint}" (configured "${entrypoint}" not found).`
5363
5539
  );
5364
- entrypoint = detected;
5540
+ entrypoint = detected.entrypoint;
5365
5541
  } else {
5366
5542
  const searchedList = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
5367
- throw new import_build_utils12.NowBuildError({
5543
+ entrypointNotFound = new import_build_utils13.NowBuildError({
5368
5544
  code: `${framework.toUpperCase()}_ENTRYPOINT_NOT_FOUND`,
5369
5545
  message: `No ${framework} entrypoint found. Add an 'app' script in pyproject.toml or define an entrypoint in one of: ${searchedList}.`,
5370
5546
  link: `https://vercel.com/docs/frameworks/backend/${framework}#exporting-the-${framework}-application`,
@@ -5372,8 +5548,11 @@ var build = async ({
5372
5548
  });
5373
5549
  }
5374
5550
  }
5375
- const entryDirectory = (0, import_path11.dirname)(entrypoint);
5376
- const entrypointAbsDir = (0, import_path11.join)(workPath, entryDirectory);
5551
+ if (entrypointNotFound && detected?.baseDir === void 0) {
5552
+ throw entrypointNotFound;
5553
+ }
5554
+ const entryDirectory = detected?.baseDir ?? (0, import_path12.dirname)(entrypoint);
5555
+ const entrypointAbsDir = (0, import_path12.join)(workPath, entryDirectory);
5377
5556
  const rootDir = repoRootPath ?? workPath;
5378
5557
  const pythonPackage = await builderSpan.child("vc.builder.python.discover").trace(
5379
5558
  () => discoverPackage({
@@ -5403,22 +5582,24 @@ var build = async ({
5403
5582
  `
5404
5583
  );
5405
5584
  }
5406
- fsFiles = await (0, import_build_utils12.glob)("**", workPath);
5407
- const venvPath = (0, import_path11.join)(workPath, ".vercel", "python", ".venv");
5585
+ fsFiles = await (0, import_build_utils13.glob)("**", workPath);
5586
+ const venvPath = (0, import_path12.join)(workPath, ".vercel", "python", ".venv");
5587
+ const uvCacheDir = getUvCacheDir(workPath);
5408
5588
  await builderSpan.child("vc.builder.python.venv").trace(async () => {
5409
5589
  await ensureVenv({
5410
5590
  pythonPath: pythonVersion.pythonPath,
5411
- venvPath
5591
+ venvPath,
5592
+ uvCacheDir
5412
5593
  });
5413
5594
  });
5414
- if ((0, import_build_utils12.isPythonFramework)(framework)) {
5595
+ if ((0, import_build_utils13.isPythonFramework)(framework)) {
5415
5596
  const {
5416
5597
  cliType,
5417
5598
  lockfileVersion,
5418
5599
  packageJsonPackageManager,
5419
5600
  turboSupportsCorepackHome
5420
- } = await (0, import_build_utils12.scanParentDirs)(workPath, true);
5421
- spawnEnv = (0, import_build_utils12.getEnvForPackageManager)({
5601
+ } = await (0, import_build_utils13.scanParentDirs)(workPath, true);
5602
+ spawnEnv = (0, import_build_utils13.getEnvForPackageManager)({
5422
5603
  cliType,
5423
5604
  lockfileVersion,
5424
5605
  packageJsonPackageManager,
@@ -5437,14 +5618,14 @@ var build = async ({
5437
5618
  }
5438
5619
  }
5439
5620
  const baseEnv = spawnEnv || process.env;
5440
- const pythonEnv = createVenvEnv(venvPath, baseEnv);
5621
+ const pythonEnv = createVenvEnv(venvPath, baseEnv, uvCacheDir);
5441
5622
  pythonEnv.VERCEL_PYTHON_VENV_PATH = venvPath;
5442
5623
  let assumeDepsInstalled = false;
5443
5624
  let uv;
5444
5625
  try {
5445
5626
  const uvPath = await getUvBinaryOrInstall(pythonVersion.pythonPath);
5446
5627
  console.log(`Using uv at "${uvPath}"`);
5447
- uv = new UvRunner(uvPath);
5628
+ uv = new UvRunner(uvPath, uvCacheDir);
5448
5629
  } catch (err) {
5449
5630
  console.log("Failed to install or locate uv");
5450
5631
  throw new Error(
@@ -5455,14 +5636,14 @@ var build = async ({
5455
5636
  let uvProjectDir = null;
5456
5637
  let projectName;
5457
5638
  let noBuildCheckFailed = false;
5458
- await builderSpan.child(import_build_utils12.BUILDER_INSTALLER_STEP, {
5639
+ await builderSpan.child(import_build_utils13.BUILDER_INSTALLER_STEP, {
5459
5640
  installCommand: projectInstallCommand || void 0
5460
5641
  }).trace(async () => {
5461
5642
  if (projectInstallCommand) {
5462
5643
  console.log(
5463
5644
  `Running "install" command: \`${projectInstallCommand}\`...`
5464
5645
  );
5465
- await (0, import_build_utils12.execCommand)(projectInstallCommand, {
5646
+ await (0, import_build_utils13.execCommand)(projectInstallCommand, {
5466
5647
  env: pythonEnv,
5467
5648
  cwd: workPath
5468
5649
  });
@@ -5504,7 +5685,7 @@ var build = async ({
5504
5685
  });
5505
5686
  } catch (err) {
5506
5687
  noBuildCheckFailed = true;
5507
- (0, import_build_utils12.debug)(
5688
+ (0, import_build_utils13.debug)(
5508
5689
  `--no-build check failed: ${err instanceof Error ? err.message : String(err)}`
5509
5690
  );
5510
5691
  }
@@ -5517,15 +5698,15 @@ var build = async ({
5517
5698
  });
5518
5699
  }
5519
5700
  });
5520
- if ((0, import_build_utils12.isPythonFramework)(framework)) {
5701
+ if ((0, import_build_utils13.isPythonFramework)(framework)) {
5521
5702
  const projectBuildCommand = config?.projectSettings?.buildCommand ?? // fallback if provided directly on config (some callers set this)
5522
5703
  config?.buildCommand;
5523
- await builderSpan.child(import_build_utils12.BUILDER_COMPILE_STEP, {
5704
+ await builderSpan.child(import_build_utils13.BUILDER_COMPILE_STEP, {
5524
5705
  buildCommand: projectBuildCommand || void 0
5525
5706
  }).trace(async () => {
5526
5707
  if (projectBuildCommand) {
5527
5708
  console.log(`Running "${projectBuildCommand}"`);
5528
- await (0, import_build_utils12.execCommand)(projectBuildCommand, {
5709
+ await (0, import_build_utils13.execCommand)(projectBuildCommand, {
5529
5710
  env: pythonEnv,
5530
5711
  cwd: workPath
5531
5712
  });
@@ -5538,19 +5719,32 @@ var build = async ({
5538
5719
  }
5539
5720
  });
5540
5721
  }
5722
+ const hookResult = await runFrameworkHook(framework, {
5723
+ pythonEnv,
5724
+ projectDir: (0, import_path12.join)(workPath, entryDirectory),
5725
+ entrypoint,
5726
+ detected
5727
+ });
5728
+ if (entrypointNotFound && hookResult?.entrypoint) {
5729
+ entrypoint = hookResult.entrypoint;
5730
+ entrypointNotFound = void 0;
5731
+ }
5732
+ if (entrypointNotFound) {
5733
+ throw entrypointNotFound;
5734
+ }
5541
5735
  const runtimeDep = baseEnv.VERCEL_RUNTIME_PYTHON || `vercel-runtime==${VERCEL_RUNTIME_VERSION}`;
5542
- (0, import_build_utils12.debug)(`Installing ${runtimeDep}`);
5736
+ (0, import_build_utils13.debug)(`Installing ${runtimeDep}`);
5543
5737
  await uv.pip({
5544
5738
  venvPath,
5545
- projectDir: (0, import_path11.join)(workPath, entryDirectory),
5739
+ projectDir: (0, import_path12.join)(workPath, entryDirectory),
5546
5740
  args: ["install", runtimeDep]
5547
5741
  });
5548
5742
  if (shouldInstallVercelWorkers) {
5549
5743
  const workersDep = baseEnv.VERCEL_WORKERS_PYTHON || `vercel-workers==${VERCEL_WORKERS_VERSION}`;
5550
- (0, import_build_utils12.debug)(`Installing ${workersDep}`);
5744
+ (0, import_build_utils13.debug)(`Installing ${workersDep}`);
5551
5745
  await uv.pip({
5552
5746
  venvPath,
5553
- projectDir: (0, import_path11.join)(workPath, entryDirectory),
5747
+ projectDir: (0, import_path12.join)(workPath, entryDirectory),
5554
5748
  args: ["install", workersDep]
5555
5749
  });
5556
5750
  }
@@ -5558,12 +5752,26 @@ var build = async ({
5558
5752
  if (quirksResult.buildEnv) {
5559
5753
  Object.assign(pythonEnv, quirksResult.buildEnv);
5560
5754
  }
5561
- (0, import_build_utils12.debug)("Entrypoint is", entrypoint);
5755
+ (0, import_build_utils13.debug)("Entrypoint is", entrypoint);
5562
5756
  const moduleName = entrypoint.replace(/\//g, ".").replace(/\.py$/i, "");
5757
+ const handlerFunction = typeof config?.handlerFunction === "string" ? config.handlerFunction : void 0;
5758
+ if (handlerFunction) {
5759
+ const entrypointPath = (0, import_path12.join)(workPath, entrypoint);
5760
+ const source = await import_fs10.default.promises.readFile(entrypointPath, "utf-8");
5761
+ const found = await (0, import_python_analysis7.containsTopLevelCallable)(source, handlerFunction);
5762
+ if (!found) {
5763
+ throw new import_build_utils13.NowBuildError({
5764
+ code: "PYTHON_HANDLER_NOT_FOUND",
5765
+ message: `Handler function "${handlerFunction}" not found in ${entrypoint}. Ensure it is defined at the module's top level.`
5766
+ });
5767
+ }
5768
+ }
5563
5769
  const vendorDir = resolveVendorDir();
5564
5770
  const suffix = meta.isDev && !entrypoint.endsWith(".py") ? ".py" : "";
5565
5771
  const entrypointWithSuffix = `${entrypoint}${suffix}`;
5566
- (0, import_build_utils12.debug)("Entrypoint with suffix is", entrypointWithSuffix);
5772
+ (0, import_build_utils13.debug)("Entrypoint with suffix is", entrypointWithSuffix);
5773
+ const handlerFuncEnvLine = handlerFunction ? `
5774
+ "__VC_HANDLER_FUNC_NAME": "${handlerFunction}",` : "";
5567
5775
  const runtimeTrampoline = `
5568
5776
  import importlib
5569
5777
  import os
@@ -5577,7 +5785,7 @@ os.environ.update({
5577
5785
  "__VC_HANDLER_MODULE_NAME": "${moduleName}",
5578
5786
  "__VC_HANDLER_ENTRYPOINT": "${entrypointWithSuffix}",
5579
5787
  "__VC_HANDLER_ENTRYPOINT_ABS": os.path.join(_here, "${entrypointWithSuffix}"),
5580
- "__VC_HANDLER_VENDOR_DIR": "${vendorDir}",
5788
+ "__VC_HANDLER_VENDOR_DIR": "${vendorDir}",${handlerFuncEnvLine}
5581
5789
  })
5582
5790
 
5583
5791
  _vendor_rel = '${vendorDir}'
@@ -5627,7 +5835,7 @@ from vercel_runtime.vc_init import vc_handler
5627
5835
  cwd: workPath,
5628
5836
  ignore: config && typeof config.excludeFiles === "string" ? [...predefinedExcludes, config.excludeFiles] : predefinedExcludes
5629
5837
  };
5630
- const files = await (0, import_build_utils12.glob)("**", globOptions);
5838
+ const files = await (0, import_build_utils13.glob)("**", globOptions);
5631
5839
  const depExternalizer = new PythonDependencyExternalizer({
5632
5840
  venvPath,
5633
5841
  vendorDir,
@@ -5660,12 +5868,12 @@ from vercel_runtime.vc_init import vc_handler
5660
5868
  }
5661
5869
  });
5662
5870
  const handlerPyFilename = "vc__handler__python";
5663
- files[`${handlerPyFilename}.py`] = new import_build_utils12.FileBlob({ data: runtimeTrampoline });
5871
+ files[`${handlerPyFilename}.py`] = new import_build_utils13.FileBlob({ data: runtimeTrampoline });
5664
5872
  if (config.framework === "fasthtml") {
5665
5873
  const { SESSKEY = "" } = process.env;
5666
- files[".sesskey"] = new import_build_utils12.FileBlob({ data: `"${SESSKEY}"` });
5874
+ files[".sesskey"] = new import_build_utils13.FileBlob({ data: `"${SESSKEY}"` });
5667
5875
  }
5668
- const output = new import_build_utils12.Lambda({
5876
+ const output = new import_build_utils13.Lambda({
5669
5877
  files,
5670
5878
  handler: `${handlerPyFilename}.vc_handler`,
5671
5879
  runtime: pythonVersion.runtime,
@@ -5674,9 +5882,44 @@ from vercel_runtime.vc_init import vc_handler
5674
5882
  });
5675
5883
  return { output };
5676
5884
  };
5885
+ async function readBuildOutputV3Config(workPath) {
5886
+ try {
5887
+ const configPath = (0, import_path12.join)(workPath, ".vercel", "output", "config.json");
5888
+ return JSON.parse(await import_fs10.default.promises.readFile(configPath, "utf8"));
5889
+ } catch (err) {
5890
+ if (err.code !== "ENOENT") {
5891
+ throw err;
5892
+ }
5893
+ }
5894
+ return void 0;
5895
+ }
5896
+ var prepareCache = async ({
5897
+ repoRootPath,
5898
+ workPath
5899
+ }) => {
5900
+ const cacheFiles = {};
5901
+ const root = repoRootPath || workPath;
5902
+ const ignore = ["**/*.pyc", "**/__pycache__/**"];
5903
+ const configV3 = await readBuildOutputV3Config(workPath);
5904
+ if (configV3?.cache && Array.isArray(configV3.cache)) {
5905
+ for (const cacheGlob of configV3.cache) {
5906
+ Object.assign(cacheFiles, await (0, import_build_utils13.glob)(cacheGlob, workPath));
5907
+ }
5908
+ return cacheFiles;
5909
+ }
5910
+ Object.assign(
5911
+ cacheFiles,
5912
+ await (0, import_build_utils13.glob)("**/.vercel/python/.venv/**", { cwd: root, ignore })
5913
+ );
5914
+ Object.assign(
5915
+ cacheFiles,
5916
+ await (0, import_build_utils13.glob)("**/.vercel/python/cache/uv/**", { cwd: root, ignore })
5917
+ );
5918
+ return cacheFiles;
5919
+ };
5677
5920
  var shouldServe = (opts) => {
5678
5921
  const framework = opts.config.framework;
5679
- if ((0, import_build_utils12.isPythonFramework)(framework)) {
5922
+ if ((0, import_build_utils13.isPythonFramework)(framework)) {
5680
5923
  const requestPath = opts.requestPath.replace(/\/$/, "");
5681
5924
  if (requestPath.startsWith("api") && opts.hasMatched) {
5682
5925
  return false;
@@ -5695,7 +5938,7 @@ var defaultShouldServe = ({
5695
5938
  if (entrypoint === requestPath && hasProp(files, entrypoint)) {
5696
5939
  return true;
5697
5940
  }
5698
- const { dir, name } = (0, import_path11.parse)(entrypoint);
5941
+ const { dir, name } = (0, import_path12.parse)(entrypoint);
5699
5942
  if (name === "index" && dir === requestPath && hasProp(files, entrypoint)) {
5700
5943
  return true;
5701
5944
  }
@@ -5711,6 +5954,8 @@ function hasProp(obj, key) {
5711
5954
  downloadFilesInWorkPath,
5712
5955
  installRequirement,
5713
5956
  installRequirementsFile,
5957
+ prepareCache,
5958
+ runFrameworkHook,
5714
5959
  shouldServe,
5715
5960
  startDevServer,
5716
5961
  version