Skip to content

Commit 0d992b4

Browse files
committed
Even more setting up to run mypy as per google#496.
Change-Id: Ib1250ec954c0fecdaed606c41bbbbe00ff7bc1de Reviewed-on: https://code-review.googlesource.com/c/re2/+/63371 Reviewed-by: Paul Wankadia <[email protected]> Reviewed-by: Alex Chernyakhovsky <[email protected]>
1 parent f3c0709 commit 0d992b4

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

.github/workflows/python.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
"${PYTHON}" -m pip install --upgrade pip
4949
"${PYTHON}" -m pip install --upgrade setuptools build wheel auditwheel
50-
"${PYTHON}" -m pip install --upgrade absl-py
50+
"${PYTHON}" -m pip install --upgrade absl-py mypy
5151
"${PYTHON}" python/toolchains/generate.py
5252
shell: bash
5353
- name: Build wheel
@@ -111,7 +111,7 @@ jobs:
111111
run: |
112112
python -m pip install --upgrade pip
113113
python -m pip install --upgrade setuptools build wheel delocate
114-
python -m pip install --upgrade absl-py
114+
python -m pip install --upgrade absl-py mypy
115115
python python/toolchains/generate.py
116116
shell: bash
117117
- name: Build wheel
@@ -173,7 +173,7 @@ jobs:
173173
run: |
174174
python -m pip install --upgrade pip
175175
python -m pip install --upgrade setuptools build wheel delvewheel
176-
python -m pip install --upgrade absl-py
176+
python -m pip install --upgrade absl-py mypy
177177
python python/toolchains/generate.py
178178
shell: bash
179179
- name: Build wheel

python/setup.py

+46-33
Original file line numberDiff line numberDiff line change
@@ -106,36 +106,49 @@ def include_dirs():
106106

107107
# We need `re2` to be a package, not a module, because it appears that
108108
# 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-
author_email='[email protected]',
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+
author_email='[email protected]',
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

Comments
 (0)