Skip to content

Commit

Permalink
Rename import-map to graph
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 19, 2024
1 parent c2e14c4 commit 9509dc7
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ruff_cache = { path = "crates/ruff_cache" }
ruff_db = { path = "crates/ruff_db" }
ruff_diagnostics = { path = "crates/ruff_diagnostics" }
ruff_formatter = { path = "crates/ruff_formatter" }
ruff_import_map = { path = "crates/ruff_import_map" }
ruff_graph = { path = "crates/ruff_graph" }
ruff_index = { path = "crates/ruff_index" }
ruff_linter = { path = "crates/ruff_linter" }
ruff_macros = { path = "crates/ruff_macros" }
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default-run = "ruff"
[dependencies]
ruff_cache = { workspace = true }
ruff_diagnostics = { workspace = true }
ruff_import_map = { workspace = true, features = ["serde", "clap"] }
ruff_graph = { workspace = true, features = ["serde", "clap"] }
ruff_linter = { workspace = true, features = ["clap"] }
ruff_macros = { workspace = true }
ruff_notebook = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use clap::{command, Parser};
use colored::Colorize;
use path_absolutize::path_dedot;
use regex::Regex;
use ruff_import_map::Direction;
use ruff_graph::Direction;
use ruff_linter::line_width::LineLength;
use ruff_linter::logging::LogLevel;
use ruff_linter::registry::Rule;
Expand Down Expand Up @@ -1321,7 +1321,7 @@ impl ConfigurationTransformer for ExplicitConfigOverrides {
config.extension = Some(extension.iter().cloned().collect());
}
if let Some(detect_string_imports) = &self.detect_string_imports {
config.import_map.detect_string_imports = Some(*detect_string_imports);
config.graph.detect_string_imports = Some(*detect_string_imports);
}

config
Expand Down
10 changes: 5 additions & 5 deletions crates/ruff/src/commands/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::resolve::resolve;
use crate::{resolve_default_files, ExitStatus};
use anyhow::Result;
use log::{debug, warn};
use ruff_import_map::{Direction, ImportMap, ModuleDb, ModuleImports};
use ruff_graph::{Direction, ImportMap, ModuleDb, ModuleImports};
use ruff_linter::warn_user_once;
use ruff_python_ast::{PySourceType, SourceType};
use ruff_workspace::resolver::{python_files_in_path, ResolvedFile};
Expand Down Expand Up @@ -81,11 +81,11 @@ pub(crate) fn import_map(

// Resolve the per-file settings.
let settings = resolver.resolve(&path);
let string_imports = settings.import_map.detect_string_imports;
let include_dependencies = settings.import_map.include_dependencies.get(&path).cloned();
let string_imports = settings.graph.detect_string_imports;
let include_dependencies = settings.graph.include_dependencies.get(&path).cloned();

// Ignore non-Python files.
let source_type = match settings.import_map.extension.get(&path) {
let source_type = match settings.graph.extension.get(&path) {
None => match SourceType::from(&path) {
SourceType::Python(source_type) => source_type,
SourceType::Toml(_) => {
Expand All @@ -104,7 +104,7 @@ pub(crate) fn import_map(
scope.spawn(move |_| {
// Identify any imports via static analysis.
let mut imports =
ruff_import_map::generate(&path, package.as_deref(), string_imports, &db)
ruff_graph::generate(&path, package.as_deref(), string_imports, &db)
.unwrap_or_else(|err| {
warn!(
"Failed to generate import map for {path}: {err}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ruff_import_map"
name = "ruff_graph"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::collector::Collector;
pub use crate::db::ModuleDb;
use crate::resolver::Resolver;
pub use crate::settings::{Direction, ImportMapSettings};
pub use crate::settings::{Direction, GraphSettings};
use anyhow::Result;
use ruff_python_ast::helpers::to_module_path;
use ruff_python_parser::{parse, Mode};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::fmt;
use std::path::PathBuf;

#[derive(Debug, Default, Clone, CacheKey)]
pub struct ImportMapSettings {
pub struct GraphSettings {
pub detect_string_imports: bool,
pub include_dependencies: BTreeMap<PathBuf, (PathBuf, Vec<String>)>,
pub extension: ExtensionMapping,
}

impl fmt::Display for ImportMapSettings {
impl fmt::Display for GraphSettings {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "\n# Import Map Settings")?;
display_settings! {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = { workspace = true }
[dependencies]
ruff_cache = { workspace = true }
ruff_formatter = { workspace = true }
ruff_import_map = { workspace = true, features = ["serde", "schemars"] }
ruff_graph = { workspace = true, features = ["serde", "schemars"] }
ruff_linter = { workspace = true }
ruff_macros = { workspace = true }
ruff_python_ast = { workspace = true }
Expand Down
30 changes: 15 additions & 15 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use strum::IntoEnumIterator;

use ruff_cache::cache_dir;
use ruff_formatter::IndentStyle;
use ruff_import_map::{Direction, ImportMapSettings};
use ruff_graph::{Direction, GraphSettings};
use ruff_linter::line_width::{IndentWidth, LineLength};
use ruff_linter::registry::RuleNamespace;
use ruff_linter::registry::{Rule, RuleSet, INCOMPATIBLE_CODES};
Expand All @@ -47,7 +47,7 @@ use crate::options::{
Flake8ErrMsgOptions, Flake8GetTextOptions, Flake8ImplicitStrConcatOptions,
Flake8ImportConventionsOptions, Flake8PytestStyleOptions, Flake8QuotesOptions,
Flake8SelfOptions, Flake8TidyImportsOptions, Flake8TypeCheckingOptions,
Flake8UnusedArgumentsOptions, FormatOptions, ImportMapOptions, IsortOptions, LintCommonOptions,
Flake8UnusedArgumentsOptions, FormatOptions, GraphOptions, IsortOptions, LintCommonOptions,
LintOptions, McCabeOptions, Options, Pep8NamingOptions, PyUpgradeOptions, PycodestyleOptions,
PydocstyleOptions, PyflakesOptions, PylintOptions, RuffOptions,
};
Expand Down Expand Up @@ -144,7 +144,7 @@ pub struct Configuration {

pub lint: LintConfiguration,
pub format: FormatConfiguration,
pub import_map: ImportMapConfiguration,
pub graph: ImportMapConfiguration,
}

impl Configuration {
Expand Down Expand Up @@ -210,17 +210,17 @@ impl Configuration {
.unwrap_or(format_defaults.docstring_code_line_width),
};

let import_map = self.import_map;
let import_map_defaults = ImportMapSettings::default();
let graph = self.graph;
let graph_defaults = GraphSettings::default();

let import_map = ImportMapSettings {
let graph = GraphSettings {
extension: self.extension.clone().unwrap_or_default(),
detect_string_imports: import_map
detect_string_imports: graph
.detect_string_imports
.unwrap_or(import_map_defaults.detect_string_imports),
include_dependencies: import_map
.unwrap_or(graph_defaults.detect_string_imports),
include_dependencies: graph
.include_dependencies
.unwrap_or(import_map_defaults.include_dependencies),
.unwrap_or(graph_defaults.include_dependencies),
};

let lint = self.lint;
Expand Down Expand Up @@ -417,7 +417,7 @@ impl Configuration {
},

formatter,
import_map,
graph,
})
}

Expand Down Expand Up @@ -551,8 +551,8 @@ impl Configuration {
options.format.unwrap_or_default(),
project_root,
)?,
import_map: ImportMapConfiguration::from_options(
options.import_map.unwrap_or_default(),
graph: ImportMapConfiguration::from_options(
options.graph.unwrap_or_default(),
project_root,
)?,
})
Expand Down Expand Up @@ -594,7 +594,7 @@ impl Configuration {

lint: self.lint.combine(config.lint),
format: self.format.combine(config.format),
import_map: self.import_map.combine(config.import_map),
graph: self.graph.combine(config.graph),
}
}
}
Expand Down Expand Up @@ -1223,7 +1223,7 @@ pub struct ImportMapConfiguration {

impl ImportMapConfiguration {
#[allow(clippy::needless_pass_by_value)]
pub fn from_options(options: ImportMapOptions, project_root: &Path) -> Result<Self> {
pub fn from_options(options: GraphOptions, project_root: &Path) -> Result<Self> {
Ok(Self {
direction: options.direction,
detect_string_imports: options.detect_string_imports,
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use strum::IntoEnumIterator;
use crate::options_base::{OptionsMetadata, Visit};
use crate::settings::LineEnding;
use ruff_formatter::IndentStyle;
use ruff_import_map::Direction;
use ruff_graph::Direction;
use ruff_linter::line_width::{IndentWidth, LineLength};
use ruff_linter::rules::flake8_import_conventions::settings::BannedAliases;
use ruff_linter::rules::flake8_pytest_style::settings::SettingsError;
Expand Down Expand Up @@ -439,7 +439,7 @@ pub struct Options {

/// Options to configure import map generation.
#[option_group]
pub import_map: Option<ImportMapOptions>,
pub graph: Option<GraphOptions>,
}

/// Configures how Ruff checks your code.
Expand Down Expand Up @@ -3319,7 +3319,7 @@ pub struct FormatOptions {
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ImportMapOptions {
pub struct GraphOptions {
/// Whether to generate a map from file to files that it depends on (dependencies) or files that
/// depend on it (dependents).
#[option(
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_workspace/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use path_absolutize::path_dedot;
use ruff_cache::cache_dir;
use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
use ruff_import_map::ImportMapSettings;
use ruff_graph::GraphSettings;
use ruff_linter::display_settings;
use ruff_linter::settings::types::{
ExtensionMapping, FilePattern, FilePatternSet, OutputFormat, UnsafeFixes,
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct Settings {
pub file_resolver: FileResolverSettings,
pub linter: LinterSettings,
pub formatter: FormatterSettings,
pub import_map: ImportMapSettings,
pub graph: GraphSettings,
}

impl Default for Settings {
Expand All @@ -52,7 +52,7 @@ impl Default for Settings {
linter: LinterSettings::new(project_root),
file_resolver: FileResolverSettings::new(project_root),
formatter: FormatterSettings::default(),
import_map: ImportMapSettings::default(),
graph: GraphSettings::default(),
}
}
}
Expand All @@ -72,7 +72,7 @@ impl fmt::Display for Settings {
self.file_resolver | nested,
self.linter | nested,
self.formatter | nested,
self.import_map | nested,
self.graph | nested,
]
}
Ok(())
Expand Down
24 changes: 12 additions & 12 deletions ruff.schema.json

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

0 comments on commit 9509dc7

Please sign in to comment.