Skip to content

Commit

Permalink
Make tracing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed May 11, 2023
1 parent 6f16a97 commit ca6a438
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy_static = "1.4.0"
pyo3 = { version = "0.18.3", optional = true, features = ["extension-module", "abi3-py37"] }
regex = { version = "1.8.1", default-features = false, features = ["std", "perf", "unicode-case", "unicode-perl"] }
serde = { version = "1.0.162", features = ["derive"], optional = true }
tracing = "0.1.37"
tracing = { version = "0.1.37", optional = true }
unicode-width = "0.1.10"

[dev-dependencies]
Expand Down
7 changes: 6 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::fmt::{Display, Formatter};
use std::hash::{Hash, Hasher};
use std::iter;
use std::str::FromStr;

#[cfg(feature = "tracing")]
use tracing::warn;

/// A regex copied from <https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions>,
Expand Down Expand Up @@ -97,7 +99,10 @@ impl FromStr for Operator {
let operator = match s {
"==" => Self::Equal,
"===" => {
warn!("Using arbitrary equality (`===`) is discouraged");
#[cfg(feature = "tracing")]
{
warn!("Using arbitrary equality (`===`) is discouraged");
}
#[allow(deprecated)]
Self::ExactEqual
}
Expand Down
9 changes: 7 additions & 2 deletions src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ use std::fmt::{Debug, Display};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::str::FromStr;
use tracing::warn;
use unicode_width::UnicodeWidthStr;

#[cfg(feature = "tracing")]
use tracing::warn;

lazy_static! {
/// Matches a python version specifier, such as `>=1.19.a1` or `4.1.*`. Extends the PEP 440
/// version regex to version specifiers
Expand Down Expand Up @@ -384,7 +386,10 @@ impl VersionSpecifier {
}
#[allow(deprecated)]
Operator::ExactEqual => {
warn!("Using arbitrary equality (`===`) is discouraged");
#[cfg(feature = "tracing")]
{
warn!("Using arbitrary equality (`===`) is discouraged");
}
self.version.to_string() == version.to_string()
}
Operator::NotEqual => other != this,
Expand Down

0 comments on commit ca6a438

Please sign in to comment.