Move DirectUrl into pypi-types (#343)

This needs to be reused elsewhere, and there's nothing specific to wheel
installation about it.
This commit is contained in:
Charlie Marsh 2023-11-06 10:26:33 -08:00 committed by GitHub
parent 24e30e6557
commit b013ea9c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 6 deletions

View file

@ -17,8 +17,9 @@ license = { workspace = true }
name = "install_wheel_rs"
[dependencies]
platform-host = { path = "../platform-host" }
distribution-filename = { path = "../distribution-filename" }
platform-host = { path = "../platform-host" }
pypi-types = { path = "../pypi-types" }
clap = { workspace = true, optional = true, features = ["derive", "env"] }
configparser = { workspace = true }

View file

@ -1,59 +0,0 @@
use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
/// Metadata for a distribution that was installed via a direct URL.
///
/// See: <https://packaging.python.org/en/latest/specifications/direct-url-data-structure/>
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DirectUrl {
/// The direct URL is a path to an archive. For example:
/// ```json
/// {"archive_info": {"hash": "sha256=75909db2664838d015e3d9139004ee16711748a52c8f336b52882266540215d8", "hashes": {"sha256": "75909db2664838d015e3d9139004ee16711748a52c8f336b52882266540215d8"}}, "url": "https://files.pythonhosted.org/packages/b8/8b/31273bf66016be6ad22bb7345c37ff350276cfd46e389a0c2ac5da9d9073/wheel-0.41.2-py3-none-any.whl"}
/// ```
ArchiveUrl {
url: String,
archive_info: ArchiveInfo,
#[serde(skip_serializing_if = "Option::is_none")]
subdirectory: Option<PathBuf>,
},
/// The direct URL is path to a VCS repository. For example:
/// ```json
/// {"url": "https://github.com/pallets/flask.git", "vcs_info": {"commit_id": "8d9519df093864ff90ca446d4af2dc8facd3c542", "vcs": "git"}}
/// ```
VcsUrl {
url: String,
vcs_info: VcsInfo,
#[serde(skip_serializing_if = "Option::is_none")]
subdirectory: Option<PathBuf>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ArchiveInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub hash: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hashes: Option<HashMap<String, String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct VcsInfo {
pub vcs: VcsKind,
pub commit_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub requested_revision: Option<String>,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VcsKind {
Git,
Hg,
Bzr,
Svn,
}

View file

@ -7,7 +7,6 @@ use platform_info::PlatformInfoError;
use thiserror::Error;
use zip::result::ZipError;
pub use direct_url::DirectUrl;
pub use install_location::{normalize_name, InstallLocation, LockedDir};
use platform_host::{Arch, Os};
pub use record::RecordEntry;
@ -18,7 +17,6 @@ pub use wheel::{
relative_to, SHEBANG_PYTHON,
};
mod direct_url;
mod install_location;
pub mod linker;
#[cfg(feature = "python_bindings")]

View file

@ -10,12 +10,14 @@ use fs_err::File;
use mailparse::MailHeaderMap;
use tracing::{debug, span, Level};
use pypi_types::DirectUrl;
use crate::install_location::InstallLocation;
use crate::wheel::{
extra_dist_info, install_data, parse_wheel_version, read_scripts_from_section,
write_script_entrypoints,
};
use crate::{read_record_file, DirectUrl, Error, Script};
use crate::{read_record_file, Error, Script};
/// Install the given wheel to the given venv
///

View file

@ -14,18 +14,18 @@ use mailparse::MailHeaderMap;
use sha2::{Digest, Sha256};
use tempfile::tempdir;
use tracing::{debug, error, span, warn, Level};
use walkdir::WalkDir;
use zip::result::ZipError;
use zip::write::FileOptions;
use zip::{ZipArchive, ZipWriter};
use distribution_filename::WheelFilename;
use pypi_types::DirectUrl;
use crate::install_location::{InstallLocation, LockedDir};
use crate::record::RecordEntry;
use crate::script::Script;
use crate::{DirectUrl, Error};
use crate::Error;
/// `#!/usr/bin/env python`
pub const SHEBANG_PYTHON: &str = "#!/usr/bin/env python";