Skip to content

Commit 2473f90

Browse files
committed
initial attempt
1 parent 2893239 commit 2473f90

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/table.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str, exclude: &[Vec<Strin
300300

301301
// remove `name` from `exclude`s (and skip if `name` is not a prefix)
302302
let prefix = parse_ident(name).expect("could not parse prefix");
303-
let exclude: BTreeSet<_> = exclude.into_iter().filter_map(|id| {
304-
let (prefix_2, rest) = id.split_at(prefix.len()+1);
305-
(prefix == prefix_2).then_some(rest)
306-
}).collect();
303+
let exclude: BTreeSet<_> = exclude.into_iter().filter_map(|id|
304+
id.strip_prefix(prefix.as_slice())
305+
).collect();
306+
dbg!(&exclude);
307307

308308
let mut main = tables.table_set[*main_positions.first().unwrap()].borrow_mut();
309309
for key in sub_table_keys {
@@ -313,6 +313,10 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str, exclude: &[Vec<Strin
313313
}
314314
let mut sub = tables.table_set[*sub_positions.first().unwrap()].borrow_mut();
315315
let sub_name = key.strip_prefix(sub_name_prefix.as_str()).unwrap();
316+
let sub_path = parse_ident(sub_name).unwrap();
317+
if exclude.contains(sub_path.as_slice()) {
318+
continue;
319+
}
316320
let mut header = false;
317321
for child in sub.iter() {
318322
let kind = child.kind();
@@ -362,8 +366,6 @@ pub fn parse_ident(ident: &str) -> Result<Vec<String>, String> {
362366
return Err(format!("semantic error: {e}"));
363367
}
364368

365-
dbg!(&root.errors());
366-
367369
// We cannot use `.into_syntax()` since only the DOM transformation
368370
// allows accessing ident `.value()`s without quotes.
369371
let mut node = root;
@@ -381,3 +383,7 @@ pub fn parse_ident(ident: &str) -> Result<Vec<String>, String> {
381383
}
382384
Ok(parts)
383385
}
386+
387+
fn prefixes<T>(slice: &[T]) -> impl Iterator<Item = &[T]> + DoubleEndedIterator {
388+
(0..=slice.len()).map(|len| &slice[..len])
389+
}

pyproject-fmt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ default = ["extension-module"]
2525
[dev-dependencies]
2626
rstest = "0.26.1" # parametrized tests
2727
indoc = { version = "2.0.6" } # dedented test cases for literal strings
28+
pretty_assertions = { version = "1.4.1", features = ["alloc"] }

pyproject-fmt/rust/src/tests/project_tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use common::taplo::parser::parse;
33
use common::taplo::syntax::SyntaxElement;
44
use indoc::indoc;
55
use rstest::rstest;
6+
use pretty_assertions::assert_eq;
67

78
use crate::project::fix;
89
use common::table::Tables;
@@ -539,6 +540,47 @@ fn evaluate(
539540
true,
540541
&[],
541542
)]
543+
544+
#[case::project_entry_points_no_collapse(
545+
indoc ! {r#"
546+
[project]
547+
entry-points.tox = {"tox-uv" = "tox_uv.plugin", "tox" = "tox.plugin"}
548+
[project.scripts]
549+
virtualenv = "virtualenv.__main__:run_with_catch"
550+
[project.gui-scripts]
551+
hello-world = "timmins:hello_world"
552+
[project.entry-points."virtualenv.activate"]
553+
bash = "virtualenv.activation.bash:BashActivator"
554+
[project.entry-points]
555+
B = {base = "vehicle_crash_prevention.main:VehicleBase"}
556+
[project.entry-points."no_crashes.vehicle"]
557+
base = "vehicle_crash_prevention.main:VehicleBase"
558+
[project.entry-points.plugin-namespace]
559+
plugin-name1 = "pkg.subpkg1"
560+
plugin-name2 = "pkg.subpkg2:func"
561+
"#},
562+
indoc ! {r#"
563+
[project]
564+
classifiers = [
565+
"Programming Language :: Python :: 3 :: Only",
566+
"Programming Language :: Python :: 3.9",
567+
]
568+
scripts.virtualenv = "virtualenv.__main__:run_with_catch"
569+
gui-scripts.hello-world = "timmins:hello_world"
570+
[project.entry-points]
571+
B.base = "vehicle_crash_prevention.main:VehicleBase"
572+
"no_crashes.vehicle".base = "vehicle_crash_prevention.main:VehicleBase"
573+
plugin-namespace.plugin-name1 = "pkg.subpkg1"
574+
plugin-namespace.plugin-name2 = "pkg.subpkg2:func"
575+
tox.tox = "tox.plugin"
576+
tox.tox-uv = "tox_uv.plugin"
577+
"virtualenv.activate".bash = "virtualenv.activation.bash:BashActivator"
578+
"#},
579+
true,
580+
(3, 9),
581+
true,
582+
&[vec!["project".to_string(), "entry-points".to_string()]],
583+
)]
542584
#[case::project_preserve_implementation_classifiers(
543585
indoc ! {r#"
544586
[project]

0 commit comments

Comments
 (0)