@vercel/python 6.0.4 → 6.0.5

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 +92 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -989,10 +989,10 @@ var require_semver = __commonJS({
989
989
  var rangeTmp;
990
990
  if (this.operator === "") {
991
991
  rangeTmp = new Range(comp.value, options);
992
- return satisfies(this.value, rangeTmp, options);
992
+ return satisfies2(this.value, rangeTmp, options);
993
993
  } else if (comp.operator === "") {
994
994
  rangeTmp = new Range(this.value, options);
995
- return satisfies(comp.semver, rangeTmp, options);
995
+ return satisfies2(comp.semver, rangeTmp, options);
996
996
  }
997
997
  var sameDirectionIncreasing = (this.operator === ">=" || this.operator === ">") && (comp.operator === ">=" || comp.operator === ">");
998
998
  var sameDirectionDecreasing = (this.operator === "<=" || this.operator === "<") && (comp.operator === "<=" || comp.operator === "<");
@@ -1301,8 +1301,8 @@ var require_semver = __commonJS({
1301
1301
  }
1302
1302
  return true;
1303
1303
  }
1304
- exports.satisfies = satisfies;
1305
- function satisfies(version2, range, options) {
1304
+ exports.satisfies = satisfies2;
1305
+ function satisfies2(version2, range, options) {
1306
1306
  try {
1307
1307
  range = new Range(range, options);
1308
1308
  } catch (er) {
@@ -1430,7 +1430,7 @@ var require_semver = __commonJS({
1430
1430
  default:
1431
1431
  throw new TypeError('Must provide a hilo val of "<" or ">"');
1432
1432
  }
1433
- if (satisfies(version2, range, options)) {
1433
+ if (satisfies2(version2, range, options)) {
1434
1434
  return false;
1435
1435
  }
1436
1436
  for (var i2 = 0; i2 < range.set.length; ++i2) {
@@ -3133,6 +3133,81 @@ function getLatestPythonVersion({
3133
3133
  }
3134
3134
  return selection;
3135
3135
  }
3136
+ function parseVersionTuple(input) {
3137
+ const cleaned = input.trim().replace(/\s+/g, "");
3138
+ const m = cleaned.match(/^(\d+)(?:\.(\d+))?/);
3139
+ if (!m)
3140
+ return null;
3141
+ const major = Number(m[1]);
3142
+ const minor = m[2] !== void 0 ? Number(m[2]) : 0;
3143
+ if (Number.isNaN(major) || Number.isNaN(minor))
3144
+ return null;
3145
+ return [major, minor];
3146
+ }
3147
+ function compareTuples(a, b) {
3148
+ if (a[0] !== b[0])
3149
+ return a[0] - b[0];
3150
+ return a[1] - b[1];
3151
+ }
3152
+ function parseSpecifier(spec) {
3153
+ const s = spec.trim();
3154
+ const m = s.match(/^(<=|>=|==|!=|~=|<|>)\s*([0-9]+(?:\.[0-9]+)?)(?:\.\*)?$/) || // Bare version like "3.11" -> implied ==
3155
+ s.match(/^()([0-9]+(?:\.[0-9]+)?)(?:\.\*)?$/);
3156
+ if (!m)
3157
+ return null;
3158
+ const op = m[1] || "==";
3159
+ const vt = parseVersionTuple(m[2]);
3160
+ if (!vt)
3161
+ return null;
3162
+ return { op, ver: vt };
3163
+ }
3164
+ function satisfies(candidate, spec) {
3165
+ const cmp = compareTuples(candidate, spec.ver);
3166
+ switch (spec.op) {
3167
+ case "==":
3168
+ return cmp === 0;
3169
+ case "!=":
3170
+ return cmp !== 0;
3171
+ case "<":
3172
+ return cmp < 0;
3173
+ case "<=":
3174
+ return cmp <= 0;
3175
+ case ">":
3176
+ return cmp > 0;
3177
+ case ">=":
3178
+ return cmp >= 0;
3179
+ case "~=": {
3180
+ const lowerOk = cmp >= 0;
3181
+ const upper = [spec.ver[0], spec.ver[1] + 1];
3182
+ return lowerOk && compareTuples(candidate, upper) < 0;
3183
+ }
3184
+ default:
3185
+ return false;
3186
+ }
3187
+ }
3188
+ function selectFromRequiresPython(expr) {
3189
+ const raw = expr.trim();
3190
+ if (!raw)
3191
+ return void 0;
3192
+ const parts = raw.split(",").map((p) => p.trim()).filter(Boolean);
3193
+ const specifiers = [];
3194
+ for (const p of parts) {
3195
+ const sp = parseSpecifier(p);
3196
+ if (sp)
3197
+ specifiers.push(sp);
3198
+ }
3199
+ if (specifiers.length === 0) {
3200
+ return allOptions.find((o) => o.version === raw);
3201
+ }
3202
+ const matches = allOptions.filter((opt) => {
3203
+ const vt = parseVersionTuple(opt.version);
3204
+ return specifiers.every((sp) => satisfies(vt, sp));
3205
+ });
3206
+ if (matches.length === 0)
3207
+ return void 0;
3208
+ const installedMatch = matches.find(isInstalled2);
3209
+ return installedMatch ?? matches[0];
3210
+ }
3136
3211
  function getSupportedPythonVersion({
3137
3212
  isDev,
3138
3213
  declaredPythonVersion
@@ -3143,7 +3218,12 @@ function getSupportedPythonVersion({
3143
3218
  let selection = getLatestPythonVersion({ isDev: false });
3144
3219
  if (declaredPythonVersion) {
3145
3220
  const { version: version2, source } = declaredPythonVersion;
3146
- const requested = allOptions.find((o) => o.version === version2);
3221
+ let requested;
3222
+ if (source === "pyproject.toml") {
3223
+ requested = selectFromRequiresPython(version2);
3224
+ } else {
3225
+ requested = allOptions.find((o) => o.version === version2);
3226
+ }
3147
3227
  if (requested) {
3148
3228
  if (isDiscontinued(requested)) {
3149
3229
  throw new import_build_utils2.NowBuildError({
@@ -3920,17 +4000,12 @@ var build = async ({
3920
4000
  } catch (err) {
3921
4001
  (0, import_build_utils7.debug)("Failed to parse pyproject.toml", err);
3922
4002
  }
3923
- const VERSION_REGEX = /\b\d+\.\d+\b/;
3924
- const exact = requiresPython?.trim().match(VERSION_REGEX)?.[0];
3925
- if (exact) {
3926
- declaredPythonVersion = { version: exact, source: "pyproject.toml" };
3927
- (0, import_build_utils7.debug)(
3928
- `Found Python version ${exact} in pyproject.toml (requires-python: "${requiresPython}")`
3929
- );
3930
- } else if (requiresPython) {
3931
- (0, import_build_utils7.debug)(
3932
- `Could not parse Python version from pyproject.toml requires-python: "${requiresPython}"`
3933
- );
4003
+ if (typeof requiresPython === "string" && requiresPython.trim()) {
4004
+ declaredPythonVersion = {
4005
+ version: requiresPython.trim(),
4006
+ source: "pyproject.toml"
4007
+ };
4008
+ (0, import_build_utils7.debug)(`Found requires-python "${requiresPython}" in pyproject.toml`);
3934
4009
  }
3935
4010
  } else if (pipfileLockDir) {
3936
4011
  let lock = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "6.0.4",
3
+ "version": "6.0.5",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",