@@ -108,22 +108,24 @@ def include_dirs():
108108# modules can't have `.pyi` files, so munge the module into a package.
109109PACKAGE = 're2'
110110try :
111- os .makedirs (PACKAGE )
112- for filename in (
113- 're2.py' ,
114- # TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
115- # 're2.pyi',
116- # '_re2.pyi',
117- ):
118- with open (filename , 'r' ) as file :
119- contents = file .read ()
120- filename = re .sub (r'^re2(?=\.py)' , '__init__' , filename )
121- contents = re .sub (r'^(?=import _)' , 'from . ' , contents , flags = re .MULTILINE )
122- with open (f'{ PACKAGE } /{ filename } ' , 'x' ) as file :
123- file .write (contents )
124- # TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
125- # with open(f'{PACKAGE}/py.typed', 'x') as file:
126- # pass
111+ # If we are building from the sdist, we are already in package form.
112+ if not os .path .exists ('PKG-INFO' ):
113+ os .makedirs (PACKAGE )
114+ for filename in (
115+ 're2.py' ,
116+ # TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
117+ # 're2.pyi',
118+ # '_re2.pyi',
119+ ):
120+ with open (filename , 'r' ) as file :
121+ contents = file .read ()
122+ filename = re .sub (r'^re2(?=\.py)' , '__init__' , filename )
123+ contents = re .sub (r'^(?=import _)' , 'from . ' , contents , flags = re .MULTILINE )
124+ with open (f'{ PACKAGE } /{ filename } ' , 'x' ) as file :
125+ file .write (contents )
126+ # TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
127+ # with open(f'{PACKAGE}/py.typed', 'x') as file:
128+ # pass
127129
128130 setuptools .setup (
129131 name = 'google-re2' ,
@@ -151,4 +153,6 @@ def include_dirs():
151153except :
152154 raise
153155else :
154- shutil .rmtree (PACKAGE )
156+ # If we are building from the sdist, we are already in package form.
157+ if not os .path .exists ('PKG-INFO' ):
158+ shutil .rmtree (PACKAGE )
0 commit comments