Skip to content

Commit 3f11933

Browse files
Merge pull request #1261 from rd4398/issue-1246
cleanup(bootstrapper): expose `DEFAULT_BG_THREADS` as public class constant
2 parents 341214d + 39d29be commit 3f11933

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from ._bootstrapper import Bootstrapper
2-
from ._types import _DEFAULT_BG_THREADS
32

4-
__all__ = ["_DEFAULT_BG_THREADS", "Bootstrapper"]
3+
__all__ = ["Bootstrapper"]

src/fromager/bootstrapper/_bootstrapper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
bootstrap_requirement_resolver,
2121
progress,
2222
sources,
23+
threading_utils,
2324
)
2425
from ..dependency_graph import DependencyGraph
2526
from ..log import req_ctxvar_context, requirement_ctxvar
@@ -32,7 +33,6 @@
3233
from ._process_install_deps import ProcessInstallDeps
3334
from ._resolve import Resolve
3435
from ._types import (
35-
_DEFAULT_BG_THREADS,
3636
FailureRecord,
3737
FailureType,
3838
SeenKey,
@@ -53,6 +53,8 @@ class Bootstrapper:
5353
the dependency tree, then ``finalize()`` for cleanup and exit code.
5454
"""
5555

56+
DEFAULT_BG_THREADS: int = max(1, threading_utils.get_cpu_count() // 2)
57+
5658
def __init__(
5759
self,
5860
ctx: context.WorkContext,
@@ -62,7 +64,7 @@ def __init__(
6264
sdist_only: bool = False,
6365
test_mode: bool = False,
6466
multiple_versions: bool = False,
65-
num_bg_threads: int = _DEFAULT_BG_THREADS,
67+
num_bg_threads: int = DEFAULT_BG_THREADS,
6668
) -> None:
6769
if test_mode and sdist_only:
6870
raise ValueError(

src/fromager/bootstrapper/_types.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88

99
from packaging.utils import NormalizedName
1010

11-
from .. import build_environment, threading_utils
11+
from .. import build_environment
1212
from ..requirements_file import SourceType
1313

1414
logger = logging.getLogger(__name__)
1515

1616
# package name, extras, version, sdist/wheel
1717
SeenKey = tuple[NormalizedName, tuple[str, ...], str, typing.Literal["sdist", "wheel"]]
1818

19-
_DEFAULT_BG_THREADS: int = max(1, threading_utils.get_cpu_count() // 2)
20-
2119

2220
@dataclasses.dataclass
2321
class SourceBuildResult:

src/fromager/commands/bootstrap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
resolver,
2121
server,
2222
)
23+
from ..bootstrapper import Bootstrapper
2324
from .build import build_parallel
2425
from .graph import find_why, show_explain_duplicates
2526

@@ -120,7 +121,7 @@ def _get_requirements_from_args(
120121
"--bg-threads",
121122
"num_bg_threads",
122123
type=click.IntRange(min=1),
123-
default=bootstrapper._DEFAULT_BG_THREADS,
124+
default=Bootstrapper.DEFAULT_BG_THREADS,
124125
show_default=True,
125126
help="Number of background threads for parallel I/O pre-fetching (min 1).",
126127
)
@@ -511,7 +512,7 @@ def write_constraints_file(
511512
"--bg-threads",
512513
"num_bg_threads",
513514
type=click.IntRange(min=1),
514-
default=bootstrapper._DEFAULT_BG_THREADS,
515+
default=Bootstrapper.DEFAULT_BG_THREADS,
515516
show_default=True,
516517
help="Number of background threads for parallel I/O pre-fetching (min 1).",
517518
)

0 commit comments

Comments
 (0)