summaryrefslogtreecommitdiffstats
path: root/pre_commit/xargs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:30:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:30:43 +0000
commitc3ded2824ef2c8a2ed59b2a6e339aba8810c1e06 (patch)
tree3261d832802f924e45a17fe459b89b2a1829b75d /pre_commit/xargs.py
parentReleasing debian version 3.2.2-1. (diff)
downloadpre-commit-c3ded2824ef2c8a2ed59b2a6e339aba8810c1e06.tar.xz
pre-commit-c3ded2824ef2c8a2ed59b2a6e339aba8810c1e06.zip
Merging upstream version 3.3.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/xargs.py')
-rw-r--r--pre_commit/xargs.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py
index e3af90e..31be6f3 100644
--- a/pre_commit/xargs.py
+++ b/pre_commit/xargs.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import concurrent.futures
import contextlib
import math
+import multiprocessing
import os
import subprocess
import sys
@@ -22,6 +23,13 @@ TArg = TypeVar('TArg')
TRet = TypeVar('TRet')
+def cpu_count() -> int:
+ try:
+ return multiprocessing.cpu_count()
+ except NotImplementedError:
+ return 1
+
+
def _environ_size(_env: MutableMapping[str, str] | None = None) -> int:
environ = _env if _env is not None else getattr(os, 'environb', os.environ)
size = 8 * len(environ) # number of pointers in `envp`