mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Add ruff version
with long version display (#8034)
Adds a new `ruff version` sub-command which displays long version information in the style of `cargo` and `rustc`. We include the number of commits since the last release tag if its a development build, in the style of Python's versioneer. ``` ❯ ruff version ruff 0.1.0+14 (947940e91 2023-10-18) ``` ``` ❯ ruff version --output-format json { "version": "0.1.0", "commit_info": { "short_commit_hash": "947940e91", "commit_hash": "947940e91269f20f6b3f8f8c7c63f8e914680e80", "commit_date": "2023-10-18", "last_tag": "v0.1.0", "commits_since_last_tag": 14 } }% ``` ``` ❯ cargo version cargo 1.72.1 (103a7ff2e 2023-08-15) ``` ## Test plan I've tested this manually locally, but want to at least add unit tests for the message formatting. We'd also want to check the next release to ensure the information is correct. I checked build behavior with a detached head and branches. ## Future work We could include rustc and cargo versions from the build, the current Python version, and other diagnostic information for bug reports. The `--version` and `-V` output is unchanged. However, we could update it to display the long ruff version without the rust and cargo versions (this is what cargo does). We'll need to be careful to ensure this does not break downstream packages which parse our version string. ``` ❯ ruff --version ruff 0.1.0 ``` The LSP should be updated to use `ruff version --output-format json` instead of parsing `ruff --version`.
This commit is contained in:
parent
90ebea86a4
commit
860ffb9549
12 changed files with 281 additions and 7 deletions
|
@ -9,3 +9,4 @@ pub(crate) mod linter;
|
|||
pub(crate) mod rule;
|
||||
pub(crate) mod show_files;
|
||||
pub(crate) mod show_settings;
|
||||
pub(crate) mod version;
|
||||
|
|
21
crates/ruff_cli/src/commands/version.rs
Normal file
21
crates/ruff_cli/src/commands/version.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::io::{self, BufWriter, Write};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::args::HelpFormat;
|
||||
|
||||
/// Display version information
|
||||
pub(crate) fn version(output_format: HelpFormat) -> Result<()> {
|
||||
let mut stdout = BufWriter::new(io::stdout().lock());
|
||||
let version_info = crate::version::version();
|
||||
|
||||
match output_format {
|
||||
HelpFormat::Text => {
|
||||
writeln!(stdout, "ruff {}", &version_info)?;
|
||||
}
|
||||
HelpFormat::Json => {
|
||||
serde_json::to_writer_pretty(stdout, &version_info)?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue