mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Move Configuration
to ruff_workspace
crate (#6920)
This commit is contained in:
parent
039694aaed
commit
a6aa16630d
77 changed files with 3704 additions and 4108 deletions
|
@ -7,9 +7,9 @@ use log::{debug, error};
|
|||
use rayon::prelude::*;
|
||||
|
||||
use ruff::linter::add_noqa_to_path;
|
||||
use ruff::resolver::PyprojectConfig;
|
||||
use ruff::{packaging, resolver, warn_user_once};
|
||||
use ruff::warn_user_once;
|
||||
use ruff_python_stdlib::path::{is_jupyter_notebook, is_project_toml};
|
||||
use ruff_workspace::resolver::{python_files_in_path, PyprojectConfig};
|
||||
|
||||
use crate::args::Overrides;
|
||||
|
||||
|
@ -21,7 +21,7 @@ pub(crate) fn add_noqa(
|
|||
) -> Result<usize> {
|
||||
// Collect all the files to check.
|
||||
let start = Instant::now();
|
||||
let (paths, resolver) = resolver::python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let (paths, resolver) = python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let duration = start.elapsed();
|
||||
debug!("Identified files to lint in: {:?}", duration);
|
||||
|
||||
|
@ -31,13 +31,12 @@ pub(crate) fn add_noqa(
|
|||
}
|
||||
|
||||
// Discover the package root for each Python file.
|
||||
let package_roots = packaging::detect_package_roots(
|
||||
let package_roots = resolver.package_roots(
|
||||
&paths
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(ignore::DirEntry::path)
|
||||
.collect::<Vec<_>>(),
|
||||
&resolver,
|
||||
pyproject_config,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use ruff::settings::options::Options;
|
||||
|
||||
use crate::ExitStatus;
|
||||
use ruff_workspace::options::Options;
|
||||
|
||||
#[allow(clippy::print_stdout)]
|
||||
pub(crate) fn config(key: Option<&str>) -> ExitStatus {
|
||||
|
|
|
@ -9,11 +9,11 @@ use thiserror::Error;
|
|||
use tracing::{span, Level};
|
||||
|
||||
use ruff::fs;
|
||||
use ruff::resolver::python_files_in_path;
|
||||
use ruff::warn_user_once;
|
||||
use ruff_formatter::LineWidth;
|
||||
use ruff_python_ast::PySourceType;
|
||||
use ruff_python_formatter::{format_module, FormatModuleError, PyFormatOptions};
|
||||
use ruff_workspace::resolver::python_files_in_path;
|
||||
|
||||
use crate::args::{Arguments, Overrides};
|
||||
use crate::resolve::resolve;
|
||||
|
|
|
@ -11,16 +11,16 @@ use itertools::Itertools;
|
|||
use log::{debug, error, warn};
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use rayon::prelude::*;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
use ruff::message::Message;
|
||||
use ruff::registry::Rule;
|
||||
use ruff::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
use ruff::settings::{flags, AllSettings};
|
||||
use ruff::{fs, packaging, resolver, warn_user_once, IOError};
|
||||
use ruff::{fs, warn_user_once, IOError};
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_python_ast::imports::ImportMap;
|
||||
use ruff_source_file::SourceFileBuilder;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use ruff_workspace::resolver::{python_files_in_path, PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
|
||||
use crate::args::Overrides;
|
||||
use crate::cache::{self, Cache};
|
||||
|
@ -38,7 +38,7 @@ pub(crate) fn run(
|
|||
) -> Result<Diagnostics> {
|
||||
// Collect all the Python files to check.
|
||||
let start = Instant::now();
|
||||
let (paths, resolver) = resolver::python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let (paths, resolver) = python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let duration = start.elapsed();
|
||||
debug!("Identified files to lint in: {:?}", duration);
|
||||
|
||||
|
@ -60,7 +60,9 @@ pub(crate) fn run(
|
|||
init_cache(&pyproject_config.settings.cli.cache_dir);
|
||||
}
|
||||
PyprojectDiscoveryStrategy::Hierarchical => {
|
||||
for settings in std::iter::once(&pyproject_config.settings).chain(resolver.iter()) {
|
||||
for settings in
|
||||
std::iter::once(&pyproject_config.settings).chain(resolver.settings())
|
||||
{
|
||||
init_cache(&settings.cli.cache_dir);
|
||||
}
|
||||
}
|
||||
|
@ -68,13 +70,12 @@ pub(crate) fn run(
|
|||
};
|
||||
|
||||
// Discover the package root for each Python file.
|
||||
let package_roots = packaging::detect_package_roots(
|
||||
let package_roots = resolver.package_roots(
|
||||
&paths
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(ignore::DirEntry::path)
|
||||
.collect::<Vec<_>>(),
|
||||
&resolver,
|
||||
pyproject_config,
|
||||
);
|
||||
|
||||
|
@ -230,18 +231,22 @@ with the relevant file contents, the `pyproject.toml` settings, and the followin
|
|||
#[cfg(test)]
|
||||
#[cfg(unix)]
|
||||
mod test {
|
||||
use super::run;
|
||||
use crate::args::Overrides;
|
||||
use anyhow::Result;
|
||||
use ruff::message::{Emitter, EmitterContext, TextEmitter};
|
||||
use ruff::registry::Rule;
|
||||
use ruff::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
use ruff::settings::{flags, AllSettings, CliSettings, Settings};
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::fs;
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
|
||||
use anyhow::Result;
|
||||
use rustc_hash::FxHashMap;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use ruff::message::{Emitter, EmitterContext, TextEmitter};
|
||||
use ruff::registry::Rule;
|
||||
use ruff::settings::{flags, AllSettings, CliSettings, Settings};
|
||||
use ruff_workspace::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
|
||||
use crate::args::Overrides;
|
||||
|
||||
use super::run;
|
||||
|
||||
/// We check that regular python files, pyproject.toml and jupyter notebooks all handle io
|
||||
/// errors gracefully
|
||||
#[test]
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::path::Path;
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use ruff::resolver::PyprojectConfig;
|
||||
use ruff::packaging;
|
||||
use ruff::settings::flags;
|
||||
use ruff::{packaging, resolver};
|
||||
use ruff_workspace::resolver::{python_file_at_path, PyprojectConfig};
|
||||
|
||||
use crate::args::Overrides;
|
||||
use crate::diagnostics::{lint_stdin, Diagnostics};
|
||||
|
@ -26,7 +26,7 @@ pub(crate) fn run_stdin(
|
|||
autofix: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
if let Some(filename) = filename {
|
||||
if !resolver::python_file_at_path(filename, pyproject_config, overrides)? {
|
||||
if !python_file_at_path(filename, pyproject_config, overrides)? {
|
||||
return Ok(Diagnostics::default());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::path::PathBuf;
|
|||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
use ruff::resolver::PyprojectConfig;
|
||||
use ruff::{resolver, warn_user_once};
|
||||
use ruff::warn_user_once;
|
||||
use ruff_workspace::resolver::{python_files_in_path, PyprojectConfig};
|
||||
|
||||
use crate::args::Overrides;
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub(crate) fn show_files(
|
|||
writer: &mut impl Write,
|
||||
) -> Result<()> {
|
||||
// Collect all files in the hierarchy.
|
||||
let (paths, _resolver) = resolver::python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let (paths, _resolver) = python_files_in_path(files, pyproject_config, overrides)?;
|
||||
|
||||
if paths.is_empty() {
|
||||
warn_user_once!("No Python files found under the given path(s)");
|
||||
|
|
|
@ -4,8 +4,7 @@ use std::path::PathBuf;
|
|||
use anyhow::{bail, Result};
|
||||
use itertools::Itertools;
|
||||
|
||||
use ruff::resolver;
|
||||
use ruff::resolver::PyprojectConfig;
|
||||
use ruff_workspace::resolver::{python_files_in_path, PyprojectConfig};
|
||||
|
||||
use crate::args::Overrides;
|
||||
|
||||
|
@ -17,7 +16,7 @@ pub(crate) fn show_settings(
|
|||
writer: &mut impl Write,
|
||||
) -> Result<()> {
|
||||
// Collect all files in the hierarchy.
|
||||
let (paths, resolver) = resolver::python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let (paths, resolver) = python_files_in_path(files, pyproject_config, overrides)?;
|
||||
|
||||
// Print the list of files.
|
||||
let Some(entry) = paths
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue