Skip to content

Commit 68c2f9e

Browse files
committed
chore: happy little adjustments
1 parent cb72c86 commit 68c2f9e

File tree

9 files changed

+24
-26
lines changed

9 files changed

+24
-26
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.13

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: all
2-
all: install bindings lint check_types test build_release
2+
all: install bindings lint check_types test
33

44
.PHONY: install
55
install:

crates/pyrust-bindings/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ mod py_globals {
55
use super::*;
66

77
#[pyfunction]
8-
pub fn num_cpus() -> usize {
9-
pyrust_internal::num_cpus_available()
8+
#[pyo3(signature = (physical_only=false))]
9+
pub fn num_cpus(physical_only: bool) -> usize {
10+
pyrust_internal::num_cpus_available(physical_only)
1011
}
1112

1213
pub const BACKEND: &str = "Rust!";

crates/pyrust-cli/src/cli.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ pub enum Subcommand {
1616
name: String,
1717
},
1818

19-
/// Print the number of CPUs available on the system.
19+
/// Print the number of (logical) CPU cores available on the system.
2020
#[clap(name = "num-cpus")]
21-
NumCPUs,
21+
NumCPUs {
22+
#[clap(long, short, default_value = "false")]
23+
/// Only count physical CPU cores.
24+
physical: bool,
25+
},
2226

2327
/// Estimate the value of pi using a Monte Carlo method.
2428
EstimatePi {
@@ -43,8 +47,8 @@ pub fn run(args: Option<&Vec<String>>) {
4347
Subcommand::Greet { name } => {
4448
println!("Hello, {name}!",);
4549
}
46-
Subcommand::NumCPUs => {
47-
println!("{}", num_cpus_available());
50+
Subcommand::NumCPUs { physical } => {
51+
println!("{}", num_cpus_available(physical));
4852
}
4953
Subcommand::EstimatePi {
5054
num_samples,

crates/pyrust-internal/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
pub mod pi;
22

3-
pub fn num_cpus_available() -> usize {
4-
num_cpus::get()
3+
pub fn num_cpus_available(physical_only: bool) -> usize {
4+
if physical_only {
5+
num_cpus::get_physical()
6+
} else {
7+
num_cpus::get()
8+
}
59
}

pyproject.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "pyrust"
33
description = "Bindings for the pyrust-internal crate"
44
readme = "README.md"
5-
requires-python = ">=3.12"
5+
requires-python = ">=3.13"
66
license = { file = "LICENSE" }
77
authors = [
88
{ name = "Eric Egli", email = "43848365+eegli@users.noreply.github.com" },
@@ -19,12 +19,7 @@ strip = true
1919
pyrust = "pyrust.__main__:launch_cli"
2020

2121
[dependency-groups]
22-
dev = [
23-
"maturin>=1.8.1",
24-
"mypy>=1.15.0",
25-
"pytest>=8.3.4",
26-
"ruff>=0.9.4",
27-
]
22+
dev = ["maturin>=1.8.1", "mypy>=1.15.0", "pytest>=8.3.4", "ruff>=0.9.4"]
2823

2924
[tool.pytest.ini_options]
3025
testpaths = ["tests"]

python/pyrust/_bindings.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
backend: str
44

5-
def num_cpus() -> int: ...
5+
def num_cpus(physical_only: bool = False) -> int: ...
66

77
# cli is defined as a submodule:
88
# https://pyo3.rs/v0.23.4/module.html#python-submodules. note that

tests/unit/test_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def test_num_cpus() -> None:
8-
num_cpus_result = num_cpus()
8+
num_cpus_result = num_cpus(physical_only=False)
99
assert_type(num_cpus_result, int)
1010
assert num_cpus_result > 0
1111

uv.lock

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)