Skip to content

Commit

Permalink
If we are building from the sdist, we are already in package form.
Browse files Browse the repository at this point in the history
Fixes #500.

Change-Id: Ie13464dcb4bee249acc833d60b7fb15f65eeaf34
Reviewed-on: https://code-review.googlesource.com/c/re2/+/63430
Reviewed-by: Alejandro Sedeño <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Jul 1, 2024
1 parent 433ab9c commit 7314a11
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,24 @@ def include_dirs():
# modules can't have `.pyi` files, so munge the module into a package.
PACKAGE = 're2'
try:
os.makedirs(PACKAGE)
for filename in (
're2.py',
# TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
# 're2.pyi',
# '_re2.pyi',
):
with open(filename, 'r') as file:
contents = file.read()
filename = re.sub(r'^re2(?=\.py)', '__init__', filename)
contents = re.sub(r'^(?=import _)', 'from . ', contents, flags=re.MULTILINE)
with open(f'{PACKAGE}/{filename}', 'x') as file:
file.write(contents)
# TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
# with open(f'{PACKAGE}/py.typed', 'x') as file:
# pass
# If we are building from the sdist, we are already in package form.
if not os.path.exists('PKG-INFO'):
os.makedirs(PACKAGE)
for filename in (
're2.py',
# TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
# 're2.pyi',
# '_re2.pyi',
):
with open(filename, 'r') as file:
contents = file.read()
filename = re.sub(r'^re2(?=\.py)', '__init__', filename)
contents = re.sub(r'^(?=import _)', 'from . ', contents, flags=re.MULTILINE)
with open(f'{PACKAGE}/{filename}', 'x') as file:
file.write(contents)
# TODO(junyer): Populate as per https://github.com/google/re2/issues/496.
# with open(f'{PACKAGE}/py.typed', 'x') as file:
# pass

setuptools.setup(
name='google-re2',
Expand Down Expand Up @@ -151,4 +153,6 @@ def include_dirs():
except:
raise
else:
shutil.rmtree(PACKAGE)
# If we are building from the sdist, we are already in package form.
if not os.path.exists('PKG-INFO'):
shutil.rmtree(PACKAGE)

0 comments on commit 7314a11

Please sign in to comment.