-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::path::Path; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::Tool; | ||
|
||
/// A `uv-receipt.toml` file tracking the installation of a tool. | ||
#[allow(dead_code)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct ToolReceipt { | ||
pub(crate) tool: Tool, | ||
|
||
/// The raw unserialized document. | ||
#[serde(skip)] | ||
pub(crate) raw: String, | ||
} | ||
|
||
impl ToolReceipt { | ||
/// Parse a [`ToolReceipt`] from a raw TOML string. | ||
pub(crate) fn from_string(raw: String) -> Result<Self, toml::de::Error> { | ||
let tool = toml::from_str(&raw)?; | ||
Ok(ToolReceipt { raw, ..tool }) | ||
} | ||
|
||
/// Read a [`ToolReceipt`] from the given path. | ||
pub(crate) fn from_path(path: &Path) -> Result<ToolReceipt, crate::Error> { | ||
match fs_err::read_to_string(path) { | ||
Ok(contents) => Ok(ToolReceipt::from_string(contents) | ||
.map_err(|err| crate::Error::ReceiptRead(path.to_owned(), Box::new(err)))?), | ||
Err(err) => Err(err.into()), | ||
} | ||
} | ||
} | ||
|
||
// Ignore raw document in comparison. | ||
impl PartialEq for ToolReceipt { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.tool.eq(&other.tool) | ||
} | ||
} | ||
|
||
impl Eq for ToolReceipt {} | ||
|
||
impl From<Tool> for ToolReceipt { | ||
fn from(tool: Tool) -> Self { | ||
ToolReceipt { | ||
tool, | ||
raw: String::new(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use pypi_types::VerbatimParsedUrl; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A tool entry. | ||
#[allow(dead_code)] | ||
#[derive(Debug, Clone, Serialize, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
pub struct Tool { | ||
requirements: Vec<pep508_rs::Requirement<VerbatimParsedUrl>>, | ||
python: Option<String>, | ||
} | ||
|
||
impl Tool { | ||
/// Create a new `Tool`. | ||
pub fn new( | ||
requirements: Vec<pep508_rs::Requirement<VerbatimParsedUrl>>, | ||
python: Option<String>, | ||
) -> Self { | ||
Self { | ||
requirements, | ||
python, | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters