Skip to content

Commit

Permalink
Speed up UV_NON_PEP440_COMPAT
Browse files Browse the repository at this point in the history
  • Loading branch information
JakkuSakura committed Feb 12, 2025
1 parent e428fb9 commit 5dac27b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crates/uv-pep440/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,8 +1705,10 @@ impl<'a> Parser<'a> {

/// Create a new `Parser` for parsing the version in the given byte string.
fn new(version: &'a [u8]) -> Parser<'a> {
static NON_PEP440_COMPAT: LazyLock<bool> =
LazyLock::new(|| std::env::var("UV_NON_PEP440_COMPAT").is_ok());
Parser {
compat: std::env::var("UV_NON_PEP440_COMPAT").is_ok(),
compat: *NON_PEP440_COMPAT,
v: version,
i: 0,
epoch: 0,
Expand All @@ -1724,7 +1726,7 @@ impl<'a> Parser<'a> {
/// If a version pattern is found, then an error is returned.
fn parse(self) -> Result<Version, VersionParseError> {
let compat = self.compat;
let version = self.v;
let _version = self.v;
match self.parse_pattern() {
Ok(vpat) => {
if vpat.is_wildcard() {
Expand All @@ -1733,13 +1735,13 @@ impl<'a> Parser<'a> {
Ok(vpat.into_version())
}
}
Err(err) if compat => {
Err(_err) if compat => {
#[cfg(feature = "tracing")]
{
tracing::warn!(
"Accepted non-PEP 440 version: {} {}",
String::from_utf8_lossy(version),
err
String::from_utf8_lossy(_version),
_err
);
}
Ok(MIN_VERSION.clone())
Expand Down

0 comments on commit 5dac27b

Please sign in to comment.