From dd0145624b7d7664239186cb01304669b557563c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 4 Feb 2023 08:21:24 -0500 Subject: [PATCH] Ignore direct root-children in implicit-namespace-package (#2565) --- src/checkers/filesystem.rs | 2 +- src/rules/flake8_no_pep420/rules.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/checkers/filesystem.rs b/src/checkers/filesystem.rs index 2c854328c4..8ce5f22425 100644 --- a/src/checkers/filesystem.rs +++ b/src/checkers/filesystem.rs @@ -13,7 +13,7 @@ pub fn check_file_path( // flake8-no-pep420 if settings.rules.enabled(&Rule::ImplicitNamespacePackage) { - if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.src) { + if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.project_root, &settings.src) { diagnostics.push(diagnostic); } } diff --git a/src/rules/flake8_no_pep420/rules.rs b/src/rules/flake8_no_pep420/rules.rs index 5bff1476f1..9b457e4952 100644 --- a/src/rules/flake8_no_pep420/rules.rs +++ b/src/rules/flake8_no_pep420/rules.rs @@ -22,11 +22,16 @@ impl Violation for ImplicitNamespacePackage { pub fn implicit_namespace_package( path: &Path, package: Option<&Path>, + project_root: &Path, src: &[PathBuf], ) -> Option { if package.is_none() // Ignore `.pyi` files, which don't require an `__init__.py`. && path.extension().map_or(true, |ext| ext != "pyi") + // Ignore any files that are direct children of the project root. + && !path + .parent() + .map_or(false, |parent| parent == project_root) // Ignore any files that are direct children of a source directory (e.g., `src/manage.py`). && !path .parent()