@@ -174,7 +174,9 @@ def build(sources: List[BuildSource],
174
174
for source in sources :
175
175
if source .path :
176
176
# Include directory of the program file in the module search path.
177
- dir = remove_cwd_prefix_from_path (dirname (source .path ))
177
+ dir = remove_cwd_prefix_from_path (
178
+ dirname (source .path ), namespaces_allowed = options .namespace_packages
179
+ )
178
180
if dir not in lib_path :
179
181
lib_path .insert (0 , dir )
180
182
@@ -711,21 +713,23 @@ def stats_summary(self) -> Mapping[str, object]:
711
713
return self .stats
712
714
713
715
714
- def remove_cwd_prefix_from_path (p : str ) -> str :
716
+ def remove_cwd_prefix_from_path (p : str , namespaces_allowed : bool ) -> str :
715
717
"""Remove current working directory prefix from p, if present.
716
718
717
719
Also crawl up until a directory without __init__.py is found.
718
720
719
721
If the result would be empty, return '.' instead.
720
722
"""
723
+ def is_pkg (p : str ) -> bool :
724
+ return (os .path .isfile (os .path .join (p , '__init__.py' ))
725
+ or os .path .isfile (os .path .join (p , '__init__.pyi' )))
726
+
721
727
cur = os .getcwd ()
722
728
# Add separator to the end of the path, unless one is already present.
723
729
if basename (cur ) != '' :
724
730
cur += os .sep
725
731
# Compute root path.
726
- while (p and
727
- (os .path .isfile (os .path .join (p , '__init__.py' )) or
728
- os .path .isfile (os .path .join (p , '__init__.pyi' )))):
732
+ while (p and (namespaces_allowed or is_pkg (p ))):
729
733
dir , base = os .path .split (p )
730
734
if not base :
731
735
break
0 commit comments