Skip to content

Commit 7314a11

Browse files
committed
If we are building from the sdist, we are already in package form.
Fixes #500. Change-Id: Ie13464dcb4bee249acc833d60b7fb15f65eeaf34 Reviewed-on: https://code-review.googlesource.com/c/re2/+/63430 Reviewed-by: Alejandro Sedeño <asedeno@google.com> Reviewed-by: Paul Wankadia <junyer@google.com>
1 parent 433ab9c commit 7314a11

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

python/setup.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,24 @@ def include_dirs():
108108
# modules can't have `.pyi` files, so munge the module into a package.
109109
PACKAGE = 're2'
110110
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__', 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():
151153
except:
152154
raise
153155
else:
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

Comments
 (0)