From 8cbeab7107d09416242073f6dae416083b3c7ac3 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Tue, 20 Feb 2024 18:07:08 +0100 Subject: [PATCH] feat: add installer to `InstalledDist` (#1762) ## Summary Add `installer` method to `InstalledDist` to distinguish between different installers. Might be nice to add an enum for all possible installers, but this might be too hard to keep up to date :). The `INSTALLER` file is a file that can be added to the `.dist-info` folder with the installer name. Closes: #1759 ## Test Plan Not sure if there is a place I can automatically test it, if you have a pointer I would be happy to add a test. --- crates/distribution-types/src/installed.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/distribution-types/src/installed.rs b/crates/distribution-types/src/installed.rs index 9179fc28a..56ac0aaac 100644 --- a/crates/distribution-types/src/installed.rs +++ b/crates/distribution-types/src/installed.rs @@ -111,6 +111,16 @@ impl InstalledDist { }) } + /// Return the `INSTALLER` of the distribution. + pub fn installer(&self) -> Result> { + let path = self.path().join("INSTALLER"); + match fs::read_to_string(path) { + Ok(installer) => Ok(Some(installer)), + Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(err) => Err(err.into()), + } + } + /// Return the [`Url`] of the distribution, if it is editable. pub fn as_editable(&self) -> Option<&Url> { match self {