GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix crawl of --system-site-packages venvs (#409) (#1419) · SocketDev/socket-patch@b81abc8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates
    • socket-patch-cli
      • src
        • commands/scan/hosted
          • python.rs
        • ecosystem_dispatch.rs
      • tests
        • in_process_redirect_poetry.rs
    • socket-patch-core
      • src
        • crawlers
          • python_crawler.rs
        • vendor
          • pypi.rs
      • tests
        • crawler_python_e2e.rs
        • crawlers_empty_paths_e2e.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/socket-patch-cli/src/commands/scan/hosted/python.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-cli/src/commands/scan/hosted/python.rs
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ pub(super) async fn stale_install_warnings(
6363
.await
6464
.unwrap_or_default()
6565
} else {
66-
socket_patch_core::crawlers::python_crawler::find_local_venv_site_packages(&common.cwd)
67-
.await
66+
let sites =
67+
socket_patch_core::crawlers::python_crawler::find_local_venv_site_packages(&common.cwd)
68+
.await;
69+
// A `--system-site-packages` venv's own copy hides its base
70+
// interpreter's (#409).
71+
crawler.set_search_order(&sites).await;
72+
sites
6873
};
6974

7075
#[derive(Default)]
Collapse file

‎crates/socket-patch-cli/src/ecosystem_dispatch.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-cli/src/ecosystem_dispatch.rs
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ async fn dispatch_find(
461461
eco = Ecosystem::Pypi,
462462
options = options,
463463
silent = silent,
464-
crawler = PythonCrawler,
464+
crawler = PythonCrawler::new(),
465465
get_paths = get_site_packages_paths,
466466
using_label = "",
467467
err_label = "Python packages",
@@ -1159,7 +1159,7 @@ async fn crawl_every_ecosystem(
11591159
if walk_pool::fd_limit_is_tight() {
11601160
(
11611161
crawl!(Ecosystem::Npm, NpmCrawler.crawl_all_with_roots(options)).await,
1162-
crawl!(Ecosystem::Pypi, PythonCrawler.crawl_all(options)).await,
1162+
crawl!(Ecosystem::Pypi, PythonCrawler::new().crawl_all(options)).await,
11631163
crawl!(Ecosystem::Cargo, CargoCrawler.crawl_all(options)).await,
11641164
crawl!(
11651165
Ecosystem::Gem,
@@ -1175,7 +1175,7 @@ async fn crawl_every_ecosystem(
11751175
} else {
11761176
tokio::join!(
11771177
crawl!(Ecosystem::Npm, NpmCrawler.crawl_all_with_roots(options)),
1178-
crawl!(Ecosystem::Pypi, PythonCrawler.crawl_all(options)),
1178+
crawl!(Ecosystem::Pypi, PythonCrawler::new().crawl_all(options)),
11791179
crawl!(Ecosystem::Cargo, CargoCrawler.crawl_all(options)),
11801180
crawl!(
11811181
Ecosystem::Gem,
@@ -2408,7 +2408,10 @@ mod tests {
24082408
}};
24092409
}
24102410
serial!(Ecosystem::Npm, NpmCrawler.crawl_all(&options).await);
2411-
serial!(Ecosystem::Pypi, PythonCrawler.crawl_all(&options).await);
2411+
serial!(
2412+
Ecosystem::Pypi,
2413+
PythonCrawler::new().crawl_all(&options).await
2414+
);
24122415
serial!(Ecosystem::Cargo, CargoCrawler.crawl_all(&options).await);
24132416
serial!(Ecosystem::Gem, RubyCrawler.crawl_all(&options).await);
24142417
serial!(Ecosystem::Golang, GoCrawler.crawl_all(&options).await);
Collapse file

‎crates/socket-patch-cli/tests/in_process_redirect_poetry.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-cli/tests/in_process_redirect_poetry.rs
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,10 @@ async fn scan_output(root: &Path, server: &MockServer, extra: &[&str]) -> std::p
403403
] {
404404
cmd.env_remove(key);
405405
}
406+
// Hermetic against the runner's own Python user site, which a
407+
// `--system-site-packages` venv reaches (#409).
406408
cmd.env("SOCKET_TELEMETRY_DISABLED", "1")
409+
.env("PYTHONNOUSERSITE", "1")
407410
.args(["scan", "--mode", "hosted", "--yes", "--cwd"])
408411
.arg(root)
409412
.args([
@@ -490,6 +493,84 @@ async fn stale_python_install_warns_and_cannot_attest_even_on_rescan() {
490493
}
491494
}
492495

496+
/// A `.venv` created with `--system-site-packages` whose base interpreter
497+
/// lives at `root/base`; `bytes` is installed in the BASE interpreter only,
498+
/// which is where pip leaves a release it finds already satisfied there.
499+
/// Returns the base copy's file.
500+
fn install_behind_system_site_venv(root: &Path, bytes: &[u8]) -> std::path::PathBuf {
501+
let base = root.join("base");
502+
let (home, stdlib) = if cfg!(windows) {
503+
(base.clone(), base.join("Lib"))
504+
} else {
505+
(base.join("bin"), base.join("lib").join("python3.12"))
506+
};
507+
std::fs::create_dir_all(&home).unwrap();
508+
std::fs::create_dir_all(&stdlib).unwrap();
509+
std::fs::write(stdlib.join("os.py"), "").unwrap();
510+
let file = install_package(root, "base", bytes);
511+
// The project venv (`write_project` made its empty site-packages)
512+
// reaches the base interpreter.
513+
std::fs::write(
514+
root.join(".venv").join("pyvenv.cfg"),
515+
format!(
516+
"home = {}\ninclude-system-site-packages = true\nversion = 3.12.4\n",
517+
home.display()
518+
),
519+
)
520+
.unwrap();
521+
file
522+
}
523+
524+
/// #409: pip leaves a release the base interpreter already has where it
525+
/// is, so behind a `--system-site-packages` venv the unpatched base copy is
526+
/// the one the build imports. It must get the stale-install warning, and
527+
/// `--vex` must not attest from the lock pin as if nothing were installed.
528+
#[tokio::test]
529+
async fn stale_base_copy_behind_system_site_venv_warns_and_cannot_attest() {
530+
let server = MockServer::start().await;
531+
mock_api(&server).await;
532+
let tmp = tempfile::tempdir().unwrap();
533+
write_project(tmp.path());
534+
let installed = install_behind_system_site_venv(tmp.path(), UPSTREAM);
535+
let vex = tmp.path().join("out.vex.json");
536+
let out = scan_output(
537+
tmp.path(),
538+
&server,
539+
&["--json", "--vex", vex.to_str().unwrap()],
540+
)
541+
.await;
542+
let json = envelope(&out);
543+
assert_eq!(out.status.code(), Some(1), "{json}");
544+
assert!(stale_warning(&json), "{json}");
545+
assert_eq!(json["error"]["code"], "no_applicable_patches", "{json}");
546+
assert!(!vex.exists(), "stale base bytes cannot produce a VEX file");
547+
assert_eq!(std::fs::read(installed).unwrap(), UPSTREAM);
548+
}
549+
550+
/// #409: once the venv holds its own patched copy (`pip install
551+
/// --force-reinstall` leaves the base copy in place), the base copy is
552+
/// shadowed: no stale warning, and the venv's verified bytes attest.
553+
#[tokio::test]
554+
async fn venv_copy_shadows_stale_base_copy_behind_system_site_venv() {
555+
let server = MockServer::start().await;
556+
mock_api(&server).await;
557+
let tmp = tempfile::tempdir().unwrap();
558+
write_project(tmp.path());
559+
install_behind_system_site_venv(tmp.path(), UPSTREAM);
560+
install_package(tmp.path(), ".venv", PATCHED);
561+
let vex = tmp.path().join("out.vex.json");
562+
let out = scan_output(
563+
tmp.path(),
564+
&server,
565+
&["--json", "--vex", vex.to_str().unwrap()],
566+
)
567+
.await;
568+
let json = envelope(&out);
569+
assert!(out.status.success(), "{json}");
570+
assert!(!stale_warning(&json), "{json}");
571+
assert_eq!(json["vex"]["statements"], 1, "{json}");
572+
}
573+
493574
#[tokio::test]
494575
async fn patched_python_install_attests_without_a_stale_warning() {
495576
let server = MockServer::start().await;

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.