@@ -106,36 +106,49 @@ def include_dirs():
106
106
107
107
# We need `re2` to be a package, not a module, because it appears that
108
108
# modules can't have `.pyi` files, so munge the module into a package.
109
- os .makedirs ('re2' )
110
- with open ('re2.py' , 'r' ) as file :
111
- contents = file .read ()
112
- contents = re .sub (r'^(?=import _)' , 'from . ' , contents , flags = re .MULTILINE )
113
- with open (f're2/__init__.py' , 'x' ) as file :
114
- file .write (contents )
115
- # TODO(junyer): `.pyi` files as per https://github.com/google/re2/issues/496.
116
-
117
- setuptools .setup (
118
- name = 'google-re2' ,
119
- version = '1.1.20240601' ,
120
- description = 'RE2 Python bindings' ,
121
- long_description = long_description ,
122
- long_description_content_type = 'text/plain' ,
123
- author = 'The RE2 Authors' ,
124
-
125
- url = 'https://github.com/google/re2' ,
126
- packages = ['re2' ],
127
- ext_package = 're2' ,
128
- ext_modules = [ext_module ],
129
- classifiers = [
130
- 'Development Status :: 5 - Production/Stable' ,
131
- 'Intended Audience :: Developers' ,
132
- 'License :: OSI Approved :: BSD License' ,
133
- 'Programming Language :: C++' ,
134
- 'Programming Language :: Python :: 3.8' ,
135
- ],
136
- options = options (),
137
- cmdclass = {'build_ext' : BuildExt },
138
- python_requires = '~=3.8' ,
139
- )
140
-
141
- shutil .rmtree ('re2' )
109
+ PACKAGE = 're2'
110
+ try :
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__' , contents )
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
127
+
128
+ setuptools .setup (
129
+ name = 'google-re2' ,
130
+ version = '1.1.20240601' ,
131
+ description = 'RE2 Python bindings' ,
132
+ long_description = long_description ,
133
+ long_description_content_type = 'text/plain' ,
134
+ author = 'The RE2 Authors' ,
135
+
136
+ url = 'https://github.com/google/re2' ,
137
+ packages = [PACKAGE ],
138
+ ext_package = PACKAGE ,
139
+ ext_modules = [ext_module ],
140
+ classifiers = [
141
+ 'Development Status :: 5 - Production/Stable' ,
142
+ 'Intended Audience :: Developers' ,
143
+ 'License :: OSI Approved :: BSD License' ,
144
+ 'Programming Language :: C++' ,
145
+ 'Programming Language :: Python :: 3.8' ,
146
+ ],
147
+ options = options (),
148
+ cmdclass = {'build_ext' : BuildExt },
149
+ python_requires = '~=3.8' ,
150
+ )
151
+ except :
152
+ raise
153
+ else :
154
+ shutil .rmtree (PACKAGE )
0 commit comments