@@ -25,19 +25,20 @@ class Generator:
2525 stderr = None
2626 output_file = None
2727 excluded_patterns = None
28- mapping = {}
2928
30- def __init__ (self , stderr , output_file , excluded_patterns ):
29+ def __init__ (self , stderr , output_file , excluded_patterns , include_stub_packages ):
3130 self .stderr = stderr
3231 self .output_file = output_file
3332 self .excluded_patterns = [re .compile (pattern ) for pattern in excluded_patterns ]
33+ self .include_stub_packages = include_stub_packages
34+ self .mapping = {}
3435
3536 # dig_wheel analyses the wheel .whl file determining the modules it provides
3637 # by looking at the directory structure.
3738 def dig_wheel (self , whl ):
3839 # Skip stubs and types wheels.
3940 wheel_name = get_wheel_name (whl )
40- if wheel_name .endswith (("_stubs" , "_types" )):
41+ if wheel_name .endswith (("_stubs" , "_types" )) and self . include_stub_packages :
4142 self .mapping [wheel_name .lower ()] = wheel_name .lower ()
4243 return
4344 with zipfile .ZipFile (whl , "r" ) as zip_file :
@@ -150,8 +151,11 @@ def data_has_purelib_or_platlib(path):
150151 description = "Generates the modules mapping used by the Gazelle manifest." ,
151152 )
152153 parser .add_argument ("--output_file" , type = str )
154+ parser .add_argument ("--include_stub_packages" , type = bool )
153155 parser .add_argument ("--exclude_patterns" , nargs = "+" , default = [])
154156 parser .add_argument ("--wheels" , nargs = "+" , default = [])
155157 args = parser .parse_args ()
156- generator = Generator (sys .stderr , args .output_file , args .exclude_patterns )
158+ generator = Generator (
159+ sys .stderr , args .output_file , args .exclude_patterns , args .include_stub_packages
160+ )
157161 exit (generator .run (args .wheels ))
0 commit comments