mirror of https://github.com/astral-sh/ruff
Soft-deprecate update_check (#2530)
This commit is contained in:
parent
924e35b1c3
commit
38addbe50d
|
|
@ -138,7 +138,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
manylinux: auto
|
manylinux: auto
|
||||||
args: --no-default-features --release --out dist
|
args: --release --out dist
|
||||||
- uses: uraimo/run-on-arch-action@v2.5.0
|
- uses: uraimo/run-on-arch-action@v2.5.0
|
||||||
if: matrix.target != 'ppc64'
|
if: matrix.target != 'ppc64'
|
||||||
name: Install built wheel
|
name: Install built wheel
|
||||||
|
|
|
||||||
|
|
@ -608,15 +608,6 @@ dependencies = [
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "directories"
|
|
||||||
version = "4.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
|
|
||||||
dependencies = [
|
|
||||||
"dirs-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "4.0.0"
|
version = "4.0.0"
|
||||||
|
|
@ -2007,7 +1998,6 @@ dependencies = [
|
||||||
"similar",
|
"similar",
|
||||||
"strum",
|
"strum",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"update-informer",
|
|
||||||
"ureq",
|
"ureq",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
@ -2758,19 +2748,6 @@ version = "0.7.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "update-informer"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "152ff185ca29f7f487c51ca785b0f1d85970c4581f4cdd12ed499227890200f5"
|
|
||||||
dependencies = [
|
|
||||||
"directories",
|
|
||||||
"semver",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"ureq",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ureq"
|
name = "ureq"
|
||||||
version = "2.6.2"
|
version = "2.6.2"
|
||||||
|
|
@ -2782,8 +2759,6 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustls",
|
"rustls",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"url",
|
"url",
|
||||||
"webpki",
|
"webpki",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
|
|
|
||||||
|
|
@ -476,8 +476,6 @@ Miscellaneous:
|
||||||
The name of the file when passing it through stdin
|
The name of the file when passing it through stdin
|
||||||
-e, --exit-zero
|
-e, --exit-zero
|
||||||
Exit with status code "0", even upon detecting lint violations
|
Exit with status code "0", even upon detecting lint violations
|
||||||
--update-check
|
|
||||||
Enable or disable automatic update checks
|
|
||||||
|
|
||||||
Log levels:
|
Log levels:
|
||||||
-v, --verbose Enable verbose logging
|
-v, --verbose Enable verbose logging
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ serde = { version = "1.0.147", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.87" }
|
serde_json = { version = "1.0.87" }
|
||||||
similar = { version = "2.2.1" }
|
similar = { version = "2.2.1" }
|
||||||
textwrap = { version = "0.16.0" }
|
textwrap = { version = "0.16.0" }
|
||||||
update-informer = { version = "0.6.0", default-features = false, features = ["pypi"], optional = true }
|
|
||||||
walkdir = { version = "2.3.2" }
|
walkdir = { version = "2.3.2" }
|
||||||
strum = "0.24.1"
|
strum = "0.24.1"
|
||||||
|
|
||||||
|
|
@ -60,10 +59,6 @@ assert_cmd = { version = "2.0.4" }
|
||||||
strum = { version = "0.24.1" }
|
strum = { version = "0.24.1" }
|
||||||
ureq = { version = "2.5.0", features = [] }
|
ureq = { version = "2.5.0", features = [] }
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["update-informer"]
|
|
||||||
update-informer = ["dep:update-informer"]
|
|
||||||
|
|
||||||
[package.metadata.maturin]
|
[package.metadata.maturin]
|
||||||
name = "ruff"
|
name = "ruff"
|
||||||
# Setting the name here is necessary for maturin to include the package in its builds.
|
# Setting the name here is necessary for maturin to include the package in its builds.
|
||||||
|
|
|
||||||
|
|
@ -211,11 +211,12 @@ pub struct CheckArgs {
|
||||||
/// Exit with status code "0", even upon detecting lint violations.
|
/// Exit with status code "0", even upon detecting lint violations.
|
||||||
#[arg(short, long, help_heading = "Miscellaneous")]
|
#[arg(short, long, help_heading = "Miscellaneous")]
|
||||||
pub exit_zero: bool,
|
pub exit_zero: bool,
|
||||||
/// Enable or disable automatic update checks.
|
/// Does nothing and will be removed in the future.
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
overrides_with("no_update_check"),
|
overrides_with("no_update_check"),
|
||||||
help_heading = "Miscellaneous"
|
help_heading = "Miscellaneous",
|
||||||
|
hide = true
|
||||||
)]
|
)]
|
||||||
update_check: bool,
|
update_check: bool,
|
||||||
#[clap(long, overrides_with("update_check"), hide = true)]
|
#[clap(long, overrides_with("update_check"), hide = true)]
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,18 @@ use std::path::PathBuf;
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
use ::ruff::logging::{set_up_logging, LogLevel};
|
|
||||||
use ::ruff::resolver::PyprojectDiscovery;
|
|
||||||
use ::ruff::settings::types::SerializationFormat;
|
|
||||||
use ::ruff::{fix, fs, warn_user_once};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use args::{Args, CheckArgs, Command};
|
|
||||||
use clap::{CommandFactory, Parser, Subcommand};
|
use clap::{CommandFactory, Parser, Subcommand};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use notify::{recommended_watcher, RecursiveMode, Watcher};
|
use notify::{recommended_watcher, RecursiveMode, Watcher};
|
||||||
|
|
||||||
|
use ::ruff::logging::{set_up_logging, LogLevel};
|
||||||
|
use ::ruff::resolver::PyprojectDiscovery;
|
||||||
|
use ::ruff::settings::types::SerializationFormat;
|
||||||
|
use ::ruff::settings::CliSettings;
|
||||||
|
use ::ruff::{fix, fs, warn_user_once};
|
||||||
|
use args::{Args, CheckArgs, Command};
|
||||||
use printer::{Printer, Violations};
|
use printer::{Printer, Violations};
|
||||||
use ruff::settings::CliSettings;
|
|
||||||
|
|
||||||
pub(crate) mod args;
|
pub(crate) mod args;
|
||||||
mod cache;
|
mod cache;
|
||||||
|
|
@ -22,8 +23,6 @@ mod diagnostics;
|
||||||
mod iterators;
|
mod iterators;
|
||||||
mod printer;
|
mod printer;
|
||||||
mod resolve;
|
mod resolve;
|
||||||
#[cfg(all(feature = "update-informer"))]
|
|
||||||
pub mod updates;
|
|
||||||
|
|
||||||
fn inner_main() -> Result<ExitCode> {
|
fn inner_main() -> Result<ExitCode> {
|
||||||
let mut args: Vec<_> = std::env::args_os().collect();
|
let mut args: Vec<_> = std::env::args_os().collect();
|
||||||
|
|
@ -256,14 +255,10 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for updates if we're in a non-silent log level.
|
if update_check {
|
||||||
#[cfg(feature = "update-informer")]
|
warn_user_once!(
|
||||||
if update_check
|
"update-check has been removed; setting it will cause an error in a future version."
|
||||||
&& !is_stdin
|
);
|
||||||
&& log_level >= LogLevel::Default
|
|
||||||
&& atty::is(atty::Stream::Stdout)
|
|
||||||
{
|
|
||||||
drop(updates::check_for_updates());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cli.exit_zero {
|
if !cli.exit_zero {
|
||||||
|
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
use std::fs::{create_dir_all, read_to_string, File};
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use colored::Colorize;
|
|
||||||
|
|
||||||
const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
|
||||||
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
||||||
|
|
||||||
fn cache_dir() -> &'static str {
|
|
||||||
"./.ruff_cache"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn file_path() -> PathBuf {
|
|
||||||
Path::new(cache_dir()).join(".update-informer")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the "latest" version for which the user has been informed.
|
|
||||||
fn get_latest() -> Result<Option<String>> {
|
|
||||||
let path = file_path();
|
|
||||||
if path.exists() {
|
|
||||||
Ok(Some(read_to_string(path)?.trim().to_string()))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the "latest" version for which the user has been informed.
|
|
||||||
fn set_latest(version: &str) -> Result<()> {
|
|
||||||
create_dir_all(cache_dir())?;
|
|
||||||
let path = file_path();
|
|
||||||
let mut file = File::create(path)?;
|
|
||||||
file.write_all(version.trim().as_bytes())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the user if a newer version is available.
|
|
||||||
pub fn check_for_updates() -> Result<()> {
|
|
||||||
use update_informer::{registry, Check};
|
|
||||||
|
|
||||||
let informer = update_informer::new(registry::PyPI, CARGO_PKG_NAME, CARGO_PKG_VERSION);
|
|
||||||
|
|
||||||
if let Some(new_version) = informer
|
|
||||||
.check_version()
|
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.map(|version| version.to_string())
|
|
||||||
{
|
|
||||||
// If we've already notified the user about this version, return early.
|
|
||||||
if let Some(latest_version) = get_latest()? {
|
|
||||||
if latest_version == new_version {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set_latest(&new_version)?;
|
|
||||||
|
|
||||||
let msg = format!(
|
|
||||||
"A new version of {pkg_name} is available: v{pkg_version} -> {new_version}",
|
|
||||||
pkg_name = CARGO_PKG_NAME.italic().cyan(),
|
|
||||||
pkg_version = CARGO_PKG_VERSION,
|
|
||||||
new_version = new_version.green()
|
|
||||||
);
|
|
||||||
|
|
||||||
let cmd = format!(
|
|
||||||
"Run to update: {cmd} {pkg_name}",
|
|
||||||
cmd = "pip3 install --upgrade".green(),
|
|
||||||
pkg_name = CARGO_PKG_NAME.green()
|
|
||||||
);
|
|
||||||
|
|
||||||
#[allow(clippy::print_stdout)]
|
|
||||||
{
|
|
||||||
println!("\n{msg}\n{cmd}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue