Skip to content

Commit 87477d4

Browse files
committed
fix: split pip into local pip and remote pypi sources
Previously, the pip source fell back to 'pip index versions' when a package wasn't installed locally, but still showed '(installed)' since pip is marked as a local source. This was misleading. Now: - pip: only checks locally installed packages via 'pip show' - pypi: new remote source using PyPI JSON API Closes latest-kfr
1 parent 1163cca commit 87477d4

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

.beads/last-touched

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latest-2t7.10
1+
latest-kfr

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "latest"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2024"
55
description = "Find the latest version of any command, package, or library"
66
license = "MIT"

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod tests {
3131
#[test]
3232
fn test_default_has_all_sources() {
3333
let config = Config::default();
34-
assert_eq!(config.precedence.len(), 17);
34+
assert_eq!(config.precedence.len(), 18);
3535
}
3636

3737
#[test]

src/sources/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ static PUB: JsonApiSource = JsonApiSource {
166166
url_template: "https://pub.dev/api/packages/{}",
167167
version_path: "latest.version",
168168
};
169+
static PYPI: JsonApiSource = JsonApiSource {
170+
name: "pypi",
171+
ecosystem: Ecosystem::Python,
172+
url_template: "https://pypi.org/pypi/{}/json",
173+
version_path: "info.version",
174+
};
169175

170176
/// Source definitions: (name, `type_variant`, constructor, `is_local`, ecosystem)
171177
/// This is the SINGLE source of truth.
@@ -210,6 +216,7 @@ define_sources! {
210216
"npm", Npm => &NPM, false, Ecosystem::Npm;
211217
"uv", Uv => UvSource, true, Ecosystem::Python;
212218
"pip", Pip => PipSource, true, Ecosystem::Python;
219+
"pypi", Pypi => &PYPI, false, Ecosystem::Python;
213220
"conda", Conda => CondaSource, false, Ecosystem::Python;
214221
"go", Go => &GO, false, Ecosystem::Go;
215222
"cargo", Cargo => &CARGO, false, Ecosystem::Cargo;

src/sources/pip.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Ecosystem, Source, extract_version, extract_version_field};
1+
use super::{Ecosystem, Source, extract_version_field};
22
use std::process::Command;
33

44
pub struct PipSource;
@@ -19,20 +19,12 @@ impl Source for PipSource {
1919
Command::new("which").arg(cmd).output().map(|o| o.status.success()).unwrap_or(false)
2020
})?;
2121

22-
// Try local install first, then PyPI
22+
// Only check locally installed packages
2323
Command::new(pip)
2424
.args(["show", package])
2525
.output()
2626
.ok()
2727
.filter(|o| o.status.success())
2828
.and_then(|o| extract_version_field(&String::from_utf8_lossy(&o.stdout)))
29-
.or_else(|| {
30-
Command::new(pip)
31-
.args(["index", "versions", package])
32-
.output()
33-
.ok()
34-
.filter(|o| o.status.success())
35-
.and_then(|o| extract_version(&String::from_utf8_lossy(&o.stdout)))
36-
})
3729
}
3830
}

0 commit comments

Comments
 (0)