summaryrefslogtreecommitdiffstats
path: root/pre_commit/xargs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:30:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:30:40 +0000
commitf174d1c83b97cd7007a792255c5e132306e6c1a3 (patch)
tree0506eadfc5ef4db1ca746799d35d4610df9a9c78 /pre_commit/xargs.py
parentAdding upstream version 3.2.2. (diff)
downloadpre-commit-f174d1c83b97cd7007a792255c5e132306e6c1a3.tar.xz
pre-commit-f174d1c83b97cd7007a792255c5e132306e6c1a3.zip
Adding upstream version 3.3.1.upstream/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`