@vercel/python 4.5.0 → 4.6.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 (3) hide show
  1. package/dist/index.js +33 -20
  2. package/package.json +2 -2
  3. package/vc_init.py +29 -17
package/dist/index.js CHANGED
@@ -302,9 +302,9 @@ var require_path_key = __commonJS({
302
302
  }
303
303
  });
304
304
 
305
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js
305
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
306
306
  var require_resolveCommand = __commonJS({
307
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) {
307
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) {
308
308
  "use strict";
309
309
  var path = require("path");
310
310
  var which2 = require_which();
@@ -312,7 +312,8 @@ var require_resolveCommand = __commonJS({
312
312
  function resolveCommandAttempt(parsed, withoutPathExt) {
313
313
  const cwd = process.cwd();
314
314
  const hasCustomCwd = parsed.options.cwd != null;
315
- if (hasCustomCwd) {
315
+ const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0;
316
+ if (shouldSwitchCwd) {
316
317
  try {
317
318
  process.chdir(parsed.options.cwd);
318
319
  } catch (err) {
@@ -326,7 +327,9 @@ var require_resolveCommand = __commonJS({
326
327
  });
327
328
  } catch (e) {
328
329
  } finally {
329
- process.chdir(cwd);
330
+ if (shouldSwitchCwd) {
331
+ process.chdir(cwd);
332
+ }
330
333
  }
331
334
  if (resolved) {
332
335
  resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
@@ -340,9 +343,9 @@ var require_resolveCommand = __commonJS({
340
343
  }
341
344
  });
342
345
 
343
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/escape.js
346
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/escape.js
344
347
  var require_escape = __commonJS({
345
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/escape.js"(exports, module2) {
348
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module2) {
346
349
  "use strict";
347
350
  var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
348
351
  function escapeCommand(arg) {
@@ -351,8 +354,8 @@ var require_escape = __commonJS({
351
354
  }
352
355
  function escapeArgument(arg, doubleEscapeMetaChars) {
353
356
  arg = `${arg}`;
354
- arg = arg.replace(/(\\*)"/g, '$1$1\\"');
355
- arg = arg.replace(/(\\*)$/, "$1$1");
357
+ arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
358
+ arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
356
359
  arg = `"${arg}"`;
357
360
  arg = arg.replace(metaCharsRegExp, "^$1");
358
361
  if (doubleEscapeMetaChars) {
@@ -391,9 +394,9 @@ var require_shebang_command = __commonJS({
391
394
  }
392
395
  });
393
396
 
394
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js
397
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/readShebang.js
395
398
  var require_readShebang = __commonJS({
396
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
399
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
397
400
  "use strict";
398
401
  var fs2 = require("fs");
399
402
  var shebangCommand = require_shebang_command();
@@ -1488,9 +1491,9 @@ var require_semver = __commonJS({
1488
1491
  }
1489
1492
  });
1490
1493
 
1491
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/parse.js
1494
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/parse.js
1492
1495
  var require_parse = __commonJS({
1493
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/parse.js"(exports, module2) {
1496
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module2) {
1494
1497
  "use strict";
1495
1498
  var path = require("path");
1496
1499
  var niceTry = require_src();
@@ -1574,9 +1577,9 @@ var require_parse = __commonJS({
1574
1577
  }
1575
1578
  });
1576
1579
 
1577
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/enoent.js
1580
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/enoent.js
1578
1581
  var require_enoent = __commonJS({
1579
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/enoent.js"(exports, module2) {
1582
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module2) {
1580
1583
  "use strict";
1581
1584
  var isWin = process.platform === "win32";
1582
1585
  function notFoundError(original, syscall) {
@@ -1624,9 +1627,9 @@ var require_enoent = __commonJS({
1624
1627
  }
1625
1628
  });
1626
1629
 
1627
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/index.js
1630
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/index.js
1628
1631
  var require_cross_spawn = __commonJS({
1629
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/index.js"(exports, module2) {
1632
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/index.js"(exports, module2) {
1630
1633
  "use strict";
1631
1634
  var cp = require("child_process");
1632
1635
  var parse = require_parse();
@@ -1890,12 +1893,16 @@ var require_end_of_stream = __commonJS({
1890
1893
  }
1891
1894
  });
1892
1895
 
1893
- // ../../node_modules/.pnpm/pump@3.0.0/node_modules/pump/index.js
1896
+ // ../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js
1894
1897
  var require_pump = __commonJS({
1895
- "../../node_modules/.pnpm/pump@3.0.0/node_modules/pump/index.js"(exports, module2) {
1898
+ "../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js"(exports, module2) {
1896
1899
  var once = require_once();
1897
1900
  var eos = require_end_of_stream();
1898
- var fs2 = require("fs");
1901
+ var fs2;
1902
+ try {
1903
+ fs2 = require("fs");
1904
+ } catch (e) {
1905
+ }
1899
1906
  var noop = function() {
1900
1907
  };
1901
1908
  var ancient = /^v?\.0/.test(process.version);
@@ -3083,7 +3090,13 @@ var build = async ({
3083
3090
  const handlerPyContents = originalHandlerPyContents.replace(/__VC_HANDLER_MODULE_NAME/g, moduleName).replace(/__VC_HANDLER_ENTRYPOINT/g, entrypointWithSuffix);
3084
3091
  const globOptions = {
3085
3092
  cwd: workPath,
3086
- ignore: config && typeof config.excludeFiles === "string" ? config.excludeFiles : "node_modules/**"
3093
+ ignore: config && typeof config.excludeFiles === "string" ? config.excludeFiles : [
3094
+ ".git/**",
3095
+ ".vercel/**",
3096
+ "**/node_modules/**",
3097
+ "**/.next/**",
3098
+ "**/.nuxt/**"
3099
+ ]
3087
3100
  };
3088
3101
  const files = await (0, import_build_utils3.glob)("**", globOptions);
3089
3102
  const handlerPyFilename = "vc__handler__python";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "27.4.1",
20
20
  "@types/node": "14.18.33",
21
21
  "@types/which": "3.0.0",
22
- "@vercel/build-utils": "8.4.12",
22
+ "@vercel/build-utils": "9.0.0",
23
23
  "cross-env": "7.0.3",
24
24
  "execa": "^1.0.0",
25
25
  "fs-extra": "11.1.1",
package/vc_init.py CHANGED
@@ -27,7 +27,7 @@ def format_headers(headers, decode=False):
27
27
  keyToList[key].append(value)
28
28
  return keyToList
29
29
 
30
- if 'VERCEL_IPC_FD' in os.environ:
30
+ if 'VERCEL_IPC_FD' in os.environ or 'VERCEL_IPC_PATH' in os.environ:
31
31
  from http.server import ThreadingHTTPServer
32
32
  import http
33
33
  import time
@@ -36,10 +36,15 @@ if 'VERCEL_IPC_FD' in os.environ:
36
36
  import builtins
37
37
  import logging
38
38
 
39
- ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
40
- sock = socket.socket(fileno=ipc_fd)
41
39
  start_time = time.time()
42
40
 
41
+ if 'VERCEL_IPC_FD' in os.environ:
42
+ ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
43
+ sock = socket.socket(fileno=ipc_fd)
44
+ else:
45
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
46
+ sock.connect(os.getenv("VERCEL_IPC_PATH", ""))
47
+
43
48
  send_message = lambda message: sock.sendall((json.dumps(message) + '\0').encode())
44
49
  storage = contextvars.ContextVar('storage', default=None)
45
50
 
@@ -319,21 +324,23 @@ if 'VERCEL_IPC_FD' in os.environ:
319
324
  'raw_path': url.path.encode(),
320
325
  }
321
326
 
327
+ if 'content-length' in self.headers:
328
+ content_length = int(self.headers['content-length'])
329
+ body = self.rfile.read(content_length)
330
+ else:
331
+ body = b''
332
+
333
+ if _use_legacy_asyncio:
334
+ loop = asyncio.new_event_loop()
335
+ app_queue = asyncio.Queue(loop=loop)
336
+ else:
337
+ app_queue = asyncio.Queue()
338
+ app_queue.put_nowait({'type': 'http.request', 'body': body, 'more_body': False})
339
+
322
340
  # Prepare ASGI receive function
323
341
  async def receive():
324
- if 'content-length' in self.headers:
325
- content_length = int(self.headers['content-length'])
326
- body = self.rfile.read(content_length)
327
- return {
328
- 'type': 'http.request',
329
- 'body': body,
330
- 'more_body': False,
331
- }
332
- return {
333
- 'type': 'http.request',
334
- 'body': b'',
335
- 'more_body': False,
336
- }
342
+ message = await app_queue.get()
343
+ return message
337
344
 
338
345
  # Prepare ASGI send function
339
346
  response_started = False
@@ -352,7 +359,12 @@ if 'VERCEL_IPC_FD' in os.environ:
352
359
  self.wfile.flush()
353
360
 
354
361
  # Run the ASGI application
355
- asyncio.run(app(scope, receive, send))
362
+ asgi_instance = app(scope, receive, send)
363
+ if _use_legacy_asyncio:
364
+ asgi_task = loop.create_task(asgi_instance)
365
+ loop.run_until_complete(asgi_task)
366
+ else:
367
+ asyncio.run(asgi_instance)
356
368
 
357
369
  if 'Handler' in locals():
358
370
  server = ThreadingHTTPServer(('127.0.0.1', 0), Handler)