Skip to content

Commit

Permalink
Skip comments and empty lines in python versions file
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jul 23, 2024
1 parent 0f8186d commit fb9aed3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/uv-python/src/version_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ async fn read_versions_file() -> Result<Option<Vec<String>>, std::io::Error> {
match fs::tokio::read_to_string(PYTHON_VERSIONS_FILENAME).await {
Ok(content) => {
debug!("Reading requests from `{PYTHON_VERSIONS_FILENAME}`");
Ok(Some(content.lines().map(ToString::to_string).collect()))
Ok(Some(
content
.lines()
.filter(|line| {
// Skip comments and empty lines.
let trimmed = line.trim();
!(trimmed.is_empty() || trimmed.starts_with('#'))
})
.map(ToString::to_string)
.collect(),
))
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(err) => Err(err),
Expand All @@ -67,7 +77,15 @@ async fn read_version_file() -> Result<Option<String>, std::io::Error> {
match fs::tokio::read_to_string(PYTHON_VERSION_FILENAME).await {
Ok(content) => {
debug!("Reading requests from `{PYTHON_VERSION_FILENAME}`");
Ok(content.lines().next().map(ToString::to_string))
Ok(content
.lines()
// Skip comments and empty lines.
.find(|line| {
// Skip comments and empty lines.
let trimmed = line.trim();
!(trimmed.is_empty() || trimmed.starts_with('#'))
})
.map(ToString::to_string))
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(err) => Err(err),
Expand Down

0 comments on commit fb9aed3

Please sign in to comment.