diff --git a/crates/prek/src/languages/bun/installer.rs b/crates/prek/src/languages/bun/installer.rs index 1cd8b7150..abd8a82cb 100644 --- a/crates/prek/src/languages/bun/installer.rs +++ b/crates/prek/src/languages/bun/installer.rs @@ -149,7 +149,7 @@ impl BunInstaller { installed .find_map(|(v, path)| { - if req.matches(&v, Some(&path)) { + if req.matches(&v) { Some(BunResult::from_dir(&path).with_version(v)) } else { None @@ -166,7 +166,7 @@ impl BunInstaller { .context("Failed to list remote versions")?; let version = versions .into_iter() - .find(|version| req.matches(version, None)) + .find(|version| req.matches(version)) .context("Version not found on remote")?; Ok(version) } @@ -259,7 +259,7 @@ impl BunInstaller { match BunResult::from_executable(bun_path).fill_version().await { Ok(bun_result) => { // Check if this version matches the request - if bun_request.matches(&bun_result.version, Some(&bun_result.bun)) { + if bun_request.matches(&bun_result.version) { trace!( %bun_result, "Found a matching system bun" diff --git a/crates/prek/src/languages/bun/version.rs b/crates/prek/src/languages/bun/version.rs index 9f616ad0d..863ece2c0 100644 --- a/crates/prek/src/languages/bun/version.rs +++ b/crates/prek/src/languages/bun/version.rs @@ -1,6 +1,5 @@ use std::fmt::Display; use std::ops::Deref; -use std::path::{Path, PathBuf}; use std::str::FromStr; use serde::Deserialize; @@ -48,14 +47,12 @@ impl FromStr for BunVersion { /// - `x.y.z` or `bun@x.y.z`: Install the specific version. /// - `^x.y.z`: Install the latest version that satisfies the semver requirement. /// Or any other semver compatible version requirement. -/// - `local/path/to/bun`: Use bun executable at the specified path. #[derive(Debug, Clone, Eq, PartialEq)] pub(crate) enum BunRequest { Any, Major(u64), MajorMinor(u64, u64), MajorMinorPatch(u64, u64, u64), - Path(PathBuf), Range(semver::VersionReq), } @@ -79,20 +76,11 @@ impl FromStr for BunRequest { return Ok(BunRequest::Any); } - Self::parse_version_numbers(s, s) - .or_else(|_| { - semver::VersionReq::parse(s) - .map(BunRequest::Range) - .map_err(|_| Error::InvalidVersion(s.to_string())) - }) - .or_else(|_| { - let path = PathBuf::from(s); - if path.exists() { - Ok(BunRequest::Path(path)) - } else { - Err(Error::InvalidVersion(s.to_string())) - } - }) + Self::parse_version_numbers(s, s).or_else(|_| { + semver::VersionReq::parse(s) + .map(BunRequest::Range) + .map_err(|_| Error::InvalidVersion(s.to_string())) + }) } } @@ -118,13 +106,10 @@ impl BunRequest { pub(crate) fn satisfied_by(&self, install_info: &InstallInfo) -> bool { let version = &install_info.language_version; - self.matches( - &BunVersion(version.clone()), - Some(install_info.toolchain.as_ref()), - ) + self.matches(&BunVersion(version.clone())) } - pub(crate) fn matches(&self, version: &BunVersion, toolchain: Option<&Path>) -> bool { + pub(crate) fn matches(&self, version: &BunVersion) -> bool { match self { Self::Any => true, Self::Major(major) => version.major == *major, @@ -132,8 +117,6 @@ impl BunRequest { Self::MajorMinorPatch(major, minor, patch) => { version.major == *major && version.minor == *minor && version.patch == *patch } - // FIXME: consider resolving symlinks and normalizing paths before comparison - Self::Path(path) => toolchain.is_some_and(|toolchain_path| toolchain_path == path), Self::Range(req) => req.matches(version), } } @@ -204,12 +187,12 @@ mod tests { fn test_bun_request_matches() { let version = BunVersion(semver::Version::new(1, 1, 4)); - assert!(BunRequest::Any.matches(&version, None)); - assert!(BunRequest::Major(1).matches(&version, None)); - assert!(!BunRequest::Major(2).matches(&version, None)); - assert!(BunRequest::MajorMinor(1, 1).matches(&version, None)); - assert!(!BunRequest::MajorMinor(1, 2).matches(&version, None)); - assert!(BunRequest::MajorMinorPatch(1, 1, 4).matches(&version, None)); - assert!(!BunRequest::MajorMinorPatch(1, 1, 5).matches(&version, None)); + assert!(BunRequest::Any.matches(&version)); + assert!(BunRequest::Major(1).matches(&version)); + assert!(!BunRequest::Major(2).matches(&version)); + assert!(BunRequest::MajorMinor(1, 1).matches(&version)); + assert!(!BunRequest::MajorMinor(1, 2).matches(&version)); + assert!(BunRequest::MajorMinorPatch(1, 1, 4).matches(&version)); + assert!(!BunRequest::MajorMinorPatch(1, 1, 5).matches(&version)); } } diff --git a/crates/prek/src/languages/golang/installer.rs b/crates/prek/src/languages/golang/installer.rs index bf3e775ed..3994ed999 100644 --- a/crates/prek/src/languages/golang/installer.rs +++ b/crates/prek/src/languages/golang/installer.rs @@ -164,7 +164,7 @@ impl GoInstaller { installed .find_map(|(version, path)| { - if request.matches(&version, Some(&path)) { + if request.matches(&version) { trace!(%version, "Found matching installed go"); Some(GoResult::from_dir(&path, false).with_version(version)) } else { @@ -196,7 +196,7 @@ impl GoInstaller { let version = versions .into_iter() - .find(|version| req.matches(version, None)) + .find(|version| req.matches(version)) .with_context(|| format!("Version `{req}` not found on remote"))?; Ok(version) } @@ -263,7 +263,7 @@ impl GoInstaller { { Ok(go) => { // Check if this version matches the request - if go_request.matches(&go.version, Some(&go.path)) { + if go_request.matches(&go.version) { trace!( %go, "Found matching system go" diff --git a/crates/prek/src/languages/golang/version.rs b/crates/prek/src/languages/golang/version.rs index edd3c2520..d680f253d 100644 --- a/crates/prek/src/languages/golang/version.rs +++ b/crates/prek/src/languages/golang/version.rs @@ -1,6 +1,5 @@ use std::fmt::Display; use std::ops::Deref; -use std::path::{Path, PathBuf}; use std::str::FromStr; use serde::Deserialize; @@ -51,14 +50,12 @@ impl FromStr for GoVersion { /// `go1.20rc1` or `1.20rc1` /// `go1.18beta1` or `1.18beta1` /// `>= 1.20, < 1.22` -/// `local/path/to/go` #[derive(Debug, Clone, Eq, PartialEq)] pub(crate) enum GoRequest { Any, Major(u64), MajorMinor(u64, u64), MajorMinorPatch(u64, u64, u64), - Path(PathBuf), Range(semver::VersionReq, String), // TODO: support prerelease versions like `go1.20.0b1`, `go1.20rc1` // MajorMinorPrerelease(u64, u64, String), @@ -73,7 +70,6 @@ impl Display for GoRequest { GoRequest::MajorMinorPatch(major, minor, patch) => { write!(f, "go{major}.{minor}.{patch}") } - GoRequest::Path(path) => write!(f, "path: {}", path.display()), GoRequest::Range(_, raw) => write!(f, "{raw}"), } } @@ -96,21 +92,11 @@ impl FromStr for GoRequest { return Self::parse_version_numbers(version_part, s); } - Self::parse_version_numbers(s, s) - .or_else(|_| { - semver::VersionReq::parse(s) - .map(|version_req| GoRequest::Range(version_req, s.into())) - .map_err(|_| Error::InvalidVersion(s.to_string())) - }) - .or_else(|_| { - let path = PathBuf::from(s); - if path.exists() { - Ok(GoRequest::Path(path)) - } else { - // TODO: better error message - Err(Error::InvalidVersion(s.to_string())) - } - }) + Self::parse_version_numbers(s, s).or_else(|_| { + semver::VersionReq::parse(s) + .map(|version_req| GoRequest::Range(version_req, s.into())) + .map_err(|_| Error::InvalidVersion(s.to_string())) + }) } } @@ -137,13 +123,10 @@ impl GoRequest { pub(crate) fn satisfied_by(&self, install_info: &InstallInfo) -> bool { let version = &install_info.language_version; - self.matches( - &GoVersion(version.clone()), - Some(install_info.toolchain.as_ref()), - ) + self.matches(&GoVersion(version.clone())) } - pub(crate) fn matches(&self, version: &GoVersion, toolchain: Option<&Path>) -> bool { + pub(crate) fn matches(&self, version: &GoVersion) -> bool { match self { GoRequest::Any => true, GoRequest::Major(major) => version.0.major == *major, @@ -153,8 +136,6 @@ impl GoRequest { GoRequest::MajorMinorPatch(major, minor, patch) => { version.0.major == *major && version.0.minor == *minor && version.0.patch == *patch } - // FIXME: consider resolving symlinks and normalizing paths before comparison - GoRequest::Path(path) => toolchain.is_some_and(|t| t == path), GoRequest::Range(req, _) => req.matches(&version.0), } } @@ -227,7 +208,7 @@ mod tests { ]; for (req, expected) in cases { - let result = req.matches(&version, None); + let result = req.matches(&version); assert_eq!(result, expected, "Request: {req}"); } } diff --git a/crates/prek/src/languages/node/installer.rs b/crates/prek/src/languages/node/installer.rs index 5817aad91..aa7bd0c15 100644 --- a/crates/prek/src/languages/node/installer.rs +++ b/crates/prek/src/languages/node/installer.rs @@ -158,7 +158,7 @@ impl NodeInstaller { installed .find_map(|(v, path)| { - if req.matches(&v, Some(&path)) { + if req.matches(&v) { Some(NodeResult::from_dir(&path).with_version(v)) } else { None @@ -175,7 +175,7 @@ impl NodeInstaller { .context("Failed to list remote versions")?; let version = versions .into_iter() - .find(|version| req.matches(version, None)) + .find(|version| req.matches(version)) .context("Version not found on remote")?; Ok(version) } @@ -254,7 +254,7 @@ impl NodeInstaller { { Ok(node_result) => { // Check if this version matches the request - if node_request.matches(&node_result.version, Some(&node_result.node)) { + if node_request.matches(&node_result.version) { trace!( %node_result, "Found a matching system node" diff --git a/crates/prek/src/languages/node/version.rs b/crates/prek/src/languages/node/version.rs index 02f6c8944..1c015d1ee 100644 --- a/crates/prek/src/languages/node/version.rs +++ b/crates/prek/src/languages/node/version.rs @@ -1,5 +1,4 @@ use std::fmt::Display; -use std::path::{Path, PathBuf}; use std::str::FromStr; use serde::{Deserialize, Deserializer, Serialize}; @@ -134,14 +133,12 @@ impl NodeVersion { /// - `^x.y.z`: Install the latest version of node that satisfies the version requirement. /// Or any other semver compatible version requirement. /// - `lts/`: Install the latest version of node with the specified code name. -/// - `local/path/to/node`: Use the node executable at the specified path. #[derive(Debug, Clone, Eq, PartialEq)] pub(crate) enum NodeRequest { Any, Major(u64), MajorMinor(u64, u64), MajorMinorPatch(u64, u64, u64), - Path(PathBuf), Range(semver::VersionReq), // A bare `lts` request is interpreted as the latest LTS version. Lts, @@ -174,20 +171,11 @@ impl FromStr for NodeRequest { Err(Error::InvalidVersion(request.to_string())) } } else { - Self::parse_version_numbers(request, request) - .or_else(|_| { - semver::VersionReq::parse(request) - .map(NodeRequest::Range) - .map_err(|_| Error::InvalidVersion(request.to_string())) - }) - .or_else(|_| { - let path = PathBuf::from(request); - if path.exists() { - Ok(NodeRequest::Path(path)) - } else { - Err(Error::InvalidVersion(request.to_string())) - } - }) + Self::parse_version_numbers(request, request).or_else(|_| { + semver::VersionReq::parse(request) + .map(NodeRequest::Range) + .map_err(|_| Error::InvalidVersion(request.to_string())) + }) } } } @@ -221,16 +209,13 @@ impl NodeRequest { .and_then(|s| serde_json::from_str(s).ok()) .unwrap_or(Lts::NotLts); - self.matches( - &NodeVersion { - version: version.clone(), - lts: tls, - }, - Some(install_info.toolchain.as_ref()), - ) + self.matches(&NodeVersion { + version: version.clone(), + lts: tls, + }) } - pub(crate) fn matches(&self, version: &NodeVersion, toolchain: Option<&Path>) -> bool { + pub(crate) fn matches(&self, version: &NodeVersion) -> bool { match self { NodeRequest::Any => true, NodeRequest::Major(major) => version.major() == *major, @@ -240,8 +225,6 @@ impl NodeRequest { NodeRequest::MajorMinorPatch(major, minor, patch) => { version.major() == *major && version.minor() == *minor && version.patch() == *patch } - // FIXME: consider resolving symlinks and normalizing paths before comparison - NodeRequest::Path(path) => toolchain.is_some_and(|t| t == path), NodeRequest::Range(req) => req.matches(version.version()), NodeRequest::Lts => version.lts.code_name().is_some(), NodeRequest::CodeName(name) => version @@ -338,12 +321,6 @@ mod tests { let request = NodeRequest::CodeName("Boron".to_string()); assert!(!request.satisfied_by(&install_info)); - let request = NodeRequest::Path(PathBuf::from("/usr/bin/node")); - assert!(request.satisfied_by(&install_info)); - - let request = NodeRequest::Path(PathBuf::from("/usr/bin/nodejs")); - assert!(!request.satisfied_by(&install_info)); - let request = NodeRequest::Range(semver::VersionReq::parse(">=12.18").unwrap()); assert!(request.satisfied_by(&install_info)); diff --git a/crates/prek/src/languages/python/python.rs b/crates/prek/src/languages/python/python.rs index e4905cc16..9c75dfa54 100644 --- a/crates/prek/src/languages/python/python.rs +++ b/crates/prek/src/languages/python/python.rs @@ -246,7 +246,6 @@ fn to_uv_python_request(request: &LanguageRequest) -> Option { Some(format!("{major}.{minor}.{patch}")) } PythonRequest::Range(_, raw) => Some(raw.clone()), - PythonRequest::Path(path) => Some(path.to_string_lossy().to_string()), }, _ => unreachable!(), } diff --git a/crates/prek/src/languages/python/version.rs b/crates/prek/src/languages/python/version.rs index f30555524..c82ba5f2a 100644 --- a/crates/prek/src/languages/python/version.rs +++ b/crates/prek/src/languages/python/version.rs @@ -1,6 +1,5 @@ -//! Implement `-p ` argument parser of `virutualenv` from +//! Implement `-p ` argument parser of `virtualenv` from //! -use std::path::PathBuf; use std::str::FromStr; use crate::hook::InstallInfo; @@ -12,11 +11,10 @@ pub(crate) enum PythonRequest { Major(u64), MajorMinor(u64, u64), MajorMinorPatch(u64, u64, u64), - Path(PathBuf), Range(semver::VersionReq, String), } -/// Represents a request for a specific Python version or path. +/// Represents a request for a specific Python version. /// example formats: /// - `python` /// - `python3` @@ -28,8 +26,6 @@ pub(crate) enum PythonRequest { /// - `3.12.3` /// - `>=3.12` /// - `>=3.8, <3.12` -/// - `/path/to/python` -/// - `/path/to/python3.12` // TODO: support version like `3.8b1`, `3.8rc2`, `python3.8t`, `python3.8-64`, `pypy3.8`. impl FromStr for PythonRequest { type Err = Error; @@ -47,22 +43,12 @@ impl FromStr for PythonRequest { Self::parse_version_numbers(version_part, request) } else { - Self::parse_version_numbers(request, request) - .or_else(|_| { - // Try to parse as a VersionReq (like ">= 3.12" or ">=3.8, <3.12") - semver::VersionReq::parse(request) - .map(|version_req| PythonRequest::Range(version_req, request.into())) - .map_err(|_| Error::InvalidVersion(request.to_string())) - }) - .or_else(|_| { - // If it doesn't match any known format, treat it as a path - let path = PathBuf::from(request); - if path.exists() { - Ok(PythonRequest::Path(path)) - } else { - Err(Error::InvalidVersion(request.to_string())) - } - }) + Self::parse_version_numbers(request, request).or_else(|_| { + // Try to parse as a VersionReq (like ">= 3.12" or ">=3.8, <3.12") + semver::VersionReq::parse(request) + .map(|version_req| PythonRequest::Range(version_req, request.into())) + .map_err(|_| Error::InvalidVersion(request.to_string())) + }) } } } @@ -100,8 +86,6 @@ impl PythonRequest { PythonRequest::MajorMinorPatch(major, minor, patch) => { version.major == *major && version.minor == *minor && version.patch == *patch } - // FIXME: consider resolving symlinks and normalizing paths before comparison - PythonRequest::Path(path) => path == &install_info.toolchain, PythonRequest::Range(req, _) => req.matches(version), } } @@ -138,6 +122,7 @@ mod tests { use super::*; use crate::config::Language; use rustc_hash::FxHashSet; + use std::path::PathBuf; #[test] fn test_parse_python_request() { @@ -229,12 +214,6 @@ mod tests { assert!(PythonRequest::MajorMinor(3, 12).satisfied_by(&install_info)); assert!(PythonRequest::MajorMinorPatch(3, 12, 1).satisfied_by(&install_info)); assert!(!PythonRequest::MajorMinorPatch(3, 12, 2).satisfied_by(&install_info)); - assert!( - PythonRequest::Path(PathBuf::from("/usr/bin/python3.12")).satisfied_by(&install_info) - ); - assert!( - !PythonRequest::Path(PathBuf::from("/usr/bin/python3.11")).satisfied_by(&install_info) - ); let range_req = semver::VersionReq::parse(">=3.12").unwrap(); assert!( diff --git a/crates/prek/src/languages/ruby/installer.rs b/crates/prek/src/languages/ruby/installer.rs index 128a92cb0..22cad0e03 100644 --- a/crates/prek/src/languages/ruby/installer.rs +++ b/crates/prek/src/languages/ruby/installer.rs @@ -223,7 +223,7 @@ impl RubyInstaller { } }; - let Some(version) = versions.into_iter().find(|v| request.matches(v, None)) else { + let Some(version) = versions.into_iter().find(|v| request.matches(v)) else { anyhow::bail!(ruby_not_found_error( request, &format!("No rv-ruby release found matching: {request}") @@ -251,7 +251,7 @@ impl RubyInstaller { }) .sorted_unstable_by(|(a, _), (b, _)| b.cmp(a)) // descending .find_map(|(version, ruby_bin)| { - if request.matches(&version, Some(&ruby_bin)) { + if request.matches(&version) { Some(RubyResult { ruby_bin, version, @@ -400,7 +400,7 @@ async fn try_ruby_path(ruby_path: &Path, request: &RubyRequest) -> Option=3.2, <4.0") Range(semver::VersionReq, String), } @@ -34,7 +30,6 @@ impl fmt::Display for RubyRequest { Self::Exact(maj, min, patch) => write!(f, "{maj}.{min}.{patch}"), Self::MajorMinor(maj, min) => write!(f, "{maj}.{min}"), Self::Major(maj) => write!(f, "{maj}"), - Self::Path(p) => write!(f, "{}", p.display()), Self::Range(_, s) => f.write_str(s), } } @@ -70,12 +65,6 @@ impl FromStr for RubyRequest { return Ok(Self::Range(req, s.to_string())); } - // Finally try as a file path - let path = PathBuf::from(s); - if path.exists() { - return Ok(Self::Path(path)); - } - Err(Error::InvalidVersion(s.to_string())) } } @@ -105,7 +94,7 @@ impl RubyRequest { /// Check if this request matches a Ruby version during installation search /// /// This is used by the installer when searching for existing Ruby installations. - pub(crate) fn matches(&self, version: &semver::Version, toolchain: Option<&Path>) -> bool { + pub(crate) fn matches(&self, version: &semver::Version) -> bool { match self { Self::Any => true, Self::Exact(maj, min, patch) => { @@ -113,8 +102,6 @@ impl RubyRequest { } Self::MajorMinor(maj, min) => version.major == *maj && version.minor == *min, Self::Major(maj) => version.major == *maj, - // FIXME: consider resolving symlinks and normalizing paths before comparison - Self::Path(path) => toolchain.is_some_and(|t| t == path), Self::Range(req, _) => req.matches(version), } } @@ -123,10 +110,7 @@ impl RubyRequest { /// /// This is used at runtime to verify an installation meets the requirements. pub(crate) fn satisfied_by(&self, install_info: &InstallInfo) -> bool { - self.matches( - &install_info.language_version, - Some(&install_info.toolchain), - ) + self.matches(&install_info.language_version) } } @@ -135,6 +119,7 @@ mod tests { use super::*; use crate::config::Language; use rustc_hash::FxHashSet; + use std::path::PathBuf; #[test] fn test_parse_ruby_request() { @@ -192,10 +177,6 @@ mod tests { assert!(!RubyRequest::Exact(3, 3, 7).satisfied_by(&install_info)); assert!(!RubyRequest::Exact(3, 2, 6).satisfied_by(&install_info)); - // Test path matching - assert!(RubyRequest::Path(PathBuf::from("/usr/bin/ruby")).satisfied_by(&install_info)); - assert!(!RubyRequest::Path(PathBuf::from("/usr/bin/ruby3.2")).satisfied_by(&install_info)); - // Test range matching let req = semver::VersionReq::parse(">=3.2, <4.0")?; assert!( diff --git a/crates/prek/src/languages/rust/installer.rs b/crates/prek/src/languages/rust/installer.rs index fd36ac0c5..4af1070c2 100644 --- a/crates/prek/src/languages/rust/installer.rs +++ b/crates/prek/src/languages/rust/installer.rs @@ -125,7 +125,7 @@ impl RustInstaller { installed .into_iter() .find_map(|info| { - let matches = request.matches(&info.version, Some(&info.path)); + let matches = request.matches(&info.version); if matches { trace!(name = %info.name, "Found matching installed rust"); @@ -146,7 +146,7 @@ impl RustInstaller { .sorted_unstable_by(|a, b| b.version.cmp(&a.version)); for info in installed { - let matches = rust_request.matches(&info.version, Some(&info.path)); + let matches = rust_request.matches(&info.version); if matches { trace!(name = %info.name, "Found matching system rust"); @@ -193,7 +193,7 @@ impl RustInstaller { let version = versions .into_iter() - .find(|version| req.matches(version, None)) + .find(|version| req.matches(version)) .with_context(|| format!("Version `{req}` not found on remote"))?; Ok(version) } diff --git a/crates/prek/src/languages/rust/version.rs b/crates/prek/src/languages/rust/version.rs index 04db99b6a..21c46f0cf 100644 --- a/crates/prek/src/languages/rust/version.rs +++ b/crates/prek/src/languages/rust/version.rs @@ -202,15 +202,12 @@ impl RustRequest { } _ => { let version = &install_info.language_version; - self.matches( - &RustVersion::from_version(version), - Some(install_info.toolchain.as_ref()), - ) + self.matches(&RustVersion::from_version(version)) } } } - pub(crate) fn matches(&self, version: &RustVersion, _toolchain: Option<&Path>) -> bool { + pub(crate) fn matches(&self, version: &RustVersion) -> bool { match self { RustRequest::Any => true, RustRequest::Channel(requested_channel) => version @@ -290,19 +287,19 @@ mod tests { ); let other_version = RustVersion::from_version(&semver::Version::new(1, 72, 1)); - assert!(RustRequest::Any.matches(&version, None)); - assert!(RustRequest::Channel(Channel::Stable).matches(&version, None)); - assert!(!RustRequest::Channel(Channel::Stable).matches(&other_version, None)); - assert!(RustRequest::Major(1).matches(&version, None)); - assert!(!RustRequest::Major(2).matches(&version, None)); - assert!(RustRequest::MajorMinor(1, 71).matches(&version, None)); - assert!(!RustRequest::MajorMinor(1, 72).matches(&version, None)); - assert!(RustRequest::MajorMinorPatch(1, 71, 0).matches(&version, None)); - assert!(!RustRequest::MajorMinorPatch(1, 71, 1).matches(&version, None)); + assert!(RustRequest::Any.matches(&version)); + assert!(RustRequest::Channel(Channel::Stable).matches(&version)); + assert!(!RustRequest::Channel(Channel::Stable).matches(&other_version)); + assert!(RustRequest::Major(1).matches(&version)); + assert!(!RustRequest::Major(2).matches(&version)); + assert!(RustRequest::MajorMinor(1, 71).matches(&version)); + assert!(!RustRequest::MajorMinor(1, 72).matches(&version)); + assert!(RustRequest::MajorMinorPatch(1, 71, 0).matches(&version)); + assert!(!RustRequest::MajorMinorPatch(1, 71, 1).matches(&version)); let req = semver::VersionReq::parse(">=1.70, <1.72")?; - assert!(RustRequest::Range(req.clone(), ">=1.70, <1.72".into()).matches(&version, None)); - assert!(!RustRequest::Range(req, ">=1.70, <1.72".into()).matches(&other_version, None)); + assert!(RustRequest::Range(req.clone(), ">=1.70, <1.72".into()).matches(&version)); + assert!(!RustRequest::Range(req, ">=1.70, <1.72".into()).matches(&other_version)); Ok(()) } diff --git a/crates/prek/tests/languages/ruby.rs b/crates/prek/tests/languages/ruby.rs index 391738035..cd5d2e331 100644 --- a/crates/prek/tests/languages/ruby.rs +++ b/crates/prek/tests/languages/ruby.rs @@ -7,15 +7,7 @@ use crate::common::{TestContext, cmd_snapshot, git_cmd}; fn system_ruby() { let context = TestContext::new(); context.init_project(); - - // Discover the actual system Ruby path - let ruby_path = which::which("ruby") - .expect("Ruby not found in PATH") - .to_string_lossy() - .to_string(); - - context.write_pre_commit_config(&format!( - indoc::indoc! {r" + context.write_pre_commit_config(indoc::indoc! {r" repos: - repo: local hooks: @@ -32,16 +24,7 @@ fn system_ruby() { entry: ruby --version pass_filenames: false always_run: true - - id: ruby-version-path - name: ruby-version-path - language: ruby - language_version: {} - entry: ruby --version - pass_filenames: false - always_run: true - "}, - ruby_path - )); + "}); context.git_add("."); let filters = [( @@ -63,11 +46,6 @@ fn system_ruby() { ruby 3.4.X ([DATE] revision [HASH]) [FLAGS] [PLATFORM] ruby-version-unspecified.................................................Passed - hook id: ruby-version-unspecified - - duration: [TIME] - - ruby 3.4.X ([DATE] revision [HASH]) [FLAGS] [PLATFORM] - ruby-version-path........................................................Passed - - hook id: ruby-version-path - duration: [TIME] ruby 3.4.X ([DATE] revision [HASH]) [FLAGS] [PLATFORM] diff --git a/docs/configuration.md b/docs/configuration.md index 88a9b9570..33f3a4c84 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1287,7 +1287,7 @@ If not set, `prek` may use `default_language_version` for the hook’s language. Language-specific behavior: - - Python: passed to the Python resolver (for example `python3`, `python3.12`, or a specific interpreter name). May trigger toolchain download. + - Python: passed to the Python resolver (for example `python3` or `python3.12`). May trigger toolchain download. - Node: passed to the Node resolver (for example `20`, `18.19.0`). May trigger toolchain download. - Go: uses Go version strings such as `1.22.1` (downloaded if missing). - Rust: supports rustup toolchains such as `stable`, `beta`, `nightly`, or versioned toolchains. diff --git a/docs/languages.md b/docs/languages.md index 33db1e962..aabed72f2 100644 --- a/docs/languages.md +++ b/docs/languages.md @@ -57,7 +57,6 @@ Supported formats: - `bun@1.1`, `1.1` - `bun@1.1.0`, `1.1.0` - Semver ranges like `>=1.0, <2.0` -- Absolute path to a Bun executable !!! note "prek-only" @@ -145,7 +144,6 @@ Supported formats: - `go1.22`, `1.22` - `go1.22.1`, `1.22.1` - Semver ranges like `>=1.20, <1.23` -- Absolute path to a `go` executable Pre-release strings (for example `go1.22rc1`) are not supported yet. @@ -205,7 +203,6 @@ Supported formats: - `node18`, `18`, `18.19`, `18.19.1` - Semver ranges like `^18.12` or `>=18, <20` - LTS selectors: `lts` or `lts/` -- Absolute path to a Node executable ### perl @@ -230,7 +227,6 @@ Supported formats: - `3`, `3.12`, `3.12.1` - Wheel-style short forms like `312` or `python312` - Semver ranges like `>=3.9, <3.13` -- Absolute path to a Python executable !!! note "prek-only" @@ -309,7 +305,6 @@ Supported formats: - `3`, `3.3`, `3.3.6` - `ruby-3`, `ruby-3.3`, `ruby-3.3.6` - Semver ranges like `>=3.2, <4.0` -- Absolute path to a Ruby executable !!! note "prek-only"