@@ -495,12 +495,20 @@ def check_present(files: list[str], patterns: list[str], dist_type: str) -> list
495495 return errors
496496
497497
498- def check_absent (files : list [str ], patterns : list [str ], dist_type : str ) -> list [str ]:
499- """Return error strings for any *patterns* found in *files*."""
498+ def check_absent (files : list [str ], patterns : list [str ], dist_type : str , * , present_patterns : list [str ] | None = None ) -> list [str ]:
499+ """Return error strings for any *patterns* found in *files*.
500+
501+ When *present_patterns* is given, files nested inside a directory
502+ that matches a present pattern are not flagged. This avoids false
503+ positives like ``lerna/tests/fake_package/pyproject.toml`` being
504+ flagged as unwanted when ``lerna`` is a required present pattern.
505+ """
500506 errors : list [str ] = []
501507 for pattern in patterns :
502508 translated = translate_extension (pattern )
503509 matching = [f for f in files if matches_pattern (f , pattern )]
510+ if matching and present_patterns :
511+ matching = [f for f in matching if not any (matches_pattern (f , pp ) for pp in present_patterns )]
504512 if matching :
505513 msg = f"{ dist_type } : unwanted pattern '{ pattern } ' matched: { ', ' .join (matching )} "
506514 if translated != pattern :
@@ -745,7 +753,7 @@ def check_dist(
745753 messages .append (f" Warning: could not compare against VCS: { exc } " )
746754
747755 errors .extend (check_present (sdist_files , config ["sdist" ]["present" ], "sdist" ))
748- errors .extend (check_absent (sdist_files , config ["sdist" ]["absent" ], "sdist" ))
756+ errors .extend (check_absent (sdist_files , config ["sdist" ]["absent" ], "sdist" , present_patterns = config [ "sdist" ][ "present" ] ))
749757 errors .extend (check_wrong_platform_extensions (sdist_files , "sdist" ))
750758
751759 # ── wheel checks ─────────────────────────────────────────
@@ -757,7 +765,7 @@ def check_dist(
757765 messages .append (f" { f } " )
758766
759767 errors .extend (check_present (wheel_files , config ["wheel" ]["present" ], "wheel" ))
760- errors .extend (check_absent (wheel_files , config ["wheel" ]["absent" ], "wheel" ))
768+ errors .extend (check_absent (wheel_files , config ["wheel" ]["absent" ], "wheel" , present_patterns = config [ "wheel" ][ "present" ] ))
761769 errors .extend (check_wrong_platform_extensions (wheel_files , "wheel" ))
762770 finally :
763771 if pre_built is None :
0 commit comments