mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-21 07:42:05 +00:00
Initial windows support (#940)
## Summary First batch of changes for windows support. Notable changes: * Fixes all compile errors and added windows specific paths. * Working venv creation on windows, both from a base interpreter and from a venv. This requires querying `stdlib` from the sysconfig paths to find the launcher. * Basic url/path conversion handling for windows. * `if cfg!(...)` instead of `#[cfg()]`. This should make it easier to keep everything compiling across platforms. ## Outlook Test summary: 402 tests run: 299 passed (15 slow), 103 failed, 1 skipped There are various reason for the remaining test failure: * Windows-specific colorama and tzdata dependencies that change the snapshot slightly. This is by far the biggest batch. * Some url-path handling issues. I fixed some in the PR, some remain. * Lack of the latest python patch versions for older pythons on my machine, since there are no builds for windows and we need to register them in the registry for them to be picked up for `py --list-paths` (CC @zanieb RE #1070). * Lack of entrypoint launchers. * ... likely more
This commit is contained in:
parent
ea4ab29bad
commit
2e0ce70d13
24 changed files with 535 additions and 276 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
#[cfg(feature = "pyo3")]
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::collections::HashSet;
|
||||
|
@ -714,10 +715,32 @@ fn parse_url(cursor: &mut Cursor, working_dir: Option<&Path>) -> Result<Verbatim
|
|||
});
|
||||
}
|
||||
|
||||
// Create a `VerbatimUrl` to represent the requirement.
|
||||
let url = preprocess_url(url, working_dir, cursor, start, len)?;
|
||||
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
/// Create a `VerbatimUrl` to represent the requirement.
|
||||
fn preprocess_url(
|
||||
url: &str,
|
||||
working_dir: Option<&Path>,
|
||||
cursor: &Cursor,
|
||||
start: usize,
|
||||
len: usize,
|
||||
) -> Result<VerbatimUrl, Pep508Error> {
|
||||
let url = if let Some((scheme, path)) = split_scheme(url) {
|
||||
if scheme == "file" {
|
||||
if let Some(path) = path.strip_prefix("//") {
|
||||
let path = if cfg!(windows) {
|
||||
// Transform `/C:/Users/ferris/wheel-0.42.0.tar.gz` to `C:\Users\ferris\wheel-0.42.0.tar.gz`
|
||||
Cow::Owned(
|
||||
path.strip_prefix('/')
|
||||
.unwrap_or(path)
|
||||
.replace('/', std::path::MAIN_SEPARATOR_STR),
|
||||
)
|
||||
} else {
|
||||
Cow::Borrowed(path)
|
||||
};
|
||||
// Ex) `file:///home/ferris/project/scripts/...`
|
||||
if let Some(working_dir) = working_dir {
|
||||
VerbatimUrl::from_path(path, working_dir).with_given(url.to_string())
|
||||
|
@ -770,7 +793,6 @@ fn parse_url(cursor: &mut Cursor, working_dir: Option<&Path>) -> Result<Verbatim
|
|||
.with_given(url.to_string())
|
||||
}
|
||||
};
|
||||
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
|
@ -1004,6 +1026,24 @@ mod tests {
|
|||
assert_eq!(Requirement::from_str(input).unwrap_err().to_string(), error);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn test_preprocess_url_windows() {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let actual = crate::preprocess_url(
|
||||
"file:///C:/Users/ferris/wheel-0.42.0.tar.gz",
|
||||
None,
|
||||
&Cursor::new(""),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
.unwrap()
|
||||
.to_file_path();
|
||||
let expected = PathBuf::from(r"C:\Users\ferris\wheel-0.42.0.tar.gz");
|
||||
assert_eq!(actual, Ok(expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_empty() {
|
||||
assert_err(
|
||||
|
|
|
@ -731,9 +731,9 @@ impl MarkerExpression {
|
|||
/// # use std::str::FromStr;
|
||||
/// # use pep508_rs::{MarkerTree, Pep508Error};
|
||||
/// # use pep440_rs::Version;
|
||||
/// # use puffin_normalize::ExtraName;
|
||||
///
|
||||
/// # fn main() -> Result<(), Pep508Error> {
|
||||
/// use puffin_normalize::ExtraName;
|
||||
/// let marker_tree = MarkerTree::from_str(r#"("linux" in sys_platform) and extra == 'day'"#)?;
|
||||
/// let versions: Vec<Version> = (8..12).map(|minor| Version::new([3, minor])).collect();
|
||||
/// assert!(marker_tree.evaluate_extras_and_python_version(&[ExtraName::from_str("day").unwrap()].into(), &versions));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue