Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ruff_python_ast = { path = "crates/ruff_python_ast" }
ruff_python_codegen = { path = "crates/ruff_python_codegen" }
ruff_python_formatter = { path = "crates/ruff_python_formatter" }
ruff_python_importer = { path = "crates/ruff_python_importer" }
ruff_python_imports = { path = "crates/ruff_python_imports" }
ruff_python_index = { path = "crates/ruff_python_index" }
ruff_python_literal = { path = "crates/ruff_python_literal" }
ruff_python_parser = { path = "crates/ruff_python_parser" }
Expand Down
7 changes: 1 addition & 6 deletions crates/ruff_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ ruff_db = { workspace = true, features = ["serde"] }
ruff_linter = { workspace = true }
ruff_macros = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_python_parser = { workspace = true }
ty_module_resolver = { workspace = true }
ty_site_packages = { workspace = true }
ruff_python_imports = { workspace = true }

anyhow = { workspace = true }
clap = { workspace = true, optional = true }
memchr = { workspace = true }
salsa = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
zip = { workspace = true, features = [] }

[lints]
workspace = true
Expand Down
97 changes: 0 additions & 97 deletions crates/ruff_graph/src/db.rs

This file was deleted.

46 changes: 17 additions & 29 deletions crates/ruff_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ use anyhow::Result;

use ruff_db::system::{SystemPath, SystemPathBuf};
use ruff_python_ast::PySourceType;
use ruff_python_ast::helpers::to_module_path;
use ruff_python_parser::{ParseOptions, parse};
use ruff_python_imports::{AnalyzeOptions, analyze_file};

use crate::collector::Collector;
pub use crate::db::ModuleDb;
use crate::resolver::Resolver;
pub use crate::settings::{AnalyzeSettings, Direction, StringImports};
pub use crate::settings::{AnalyzeSettings, Direction};
pub use ruff_python_imports::ImportDb as ModuleDb;
pub use ruff_python_imports::StringImports;

mod collector;
mod db;
mod resolver;
mod settings;

#[derive(Debug, Default)]
Expand All @@ -32,27 +27,20 @@ impl ModuleImports {
string_imports: StringImports,
type_checking_imports: bool,
) -> Result<Self> {
// Parse the source code.
let parsed = parse(source, ParseOptions::from(source_type))?;

let module_path =
package.and_then(|package| to_module_path(package.as_std_path(), path.as_std_path()));

// Collect the imports.
let imports = Collector::new(
module_path.as_deref(),
string_imports,
type_checking_imports,
)
.collect(parsed.syntax());

// Resolve the imports.
let mut resolved_imports = ModuleImports::default();
for import in imports {
for resolved in Resolver::new(db, path).resolve(import) {
if let Some(path) = resolved.as_system_path() {
resolved_imports.insert(path.to_path_buf());
}
for resolved in analyze_file(
db,
path,
package,
source,
source_type,
&AnalyzeOptions {
string_imports,
type_checking_imports,
},
)? {
if let Some(path) = resolved.resolved_path {
resolved_imports.insert(path);
}
}

Expand Down
120 changes: 0 additions & 120 deletions crates/ruff_graph/src/resolver.rs

This file was deleted.

26 changes: 1 addition & 25 deletions crates/ruff_graph/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ruff_linter::display_settings;
use ruff_linter::settings::types::{ExtensionMapping, FilePatternSet, PreviewMode};
use ruff_macros::CacheKey;
use ruff_python_ast::PythonVersion;
use ruff_python_imports::StringImports;
use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
Expand Down Expand Up @@ -51,31 +52,6 @@ impl fmt::Display for AnalyzeSettings {
}
}

#[derive(Debug, Copy, Clone, CacheKey)]
pub struct StringImports {
pub enabled: bool,
pub min_dots: usize,
}

impl Default for StringImports {
fn default() -> Self {
Self {
enabled: false,
min_dots: 2,
}
}
}

impl fmt::Display for StringImports {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.enabled {
write!(f, "enabled (min_dots: {})", self.min_dots)
} else {
write!(f, "disabled")
}
}
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, CacheKey)]
#[cfg_attr(
feature = "serde",
Expand Down
Loading
Loading