From 7314a11875c278c489034f02d705777dfece8264 Mon Sep 17 00:00:00 2001 From: Paul Wankadia Date: Sun, 30 Jun 2024 21:02:26 +0000 Subject: [PATCH] If we are building from the sdist, we are already in package form. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #500. Change-Id: Ie13464dcb4bee249acc833d60b7fb15f65eeaf34 Reviewed-on: https://code-review.googlesource.com/c/re2/+/63430 Reviewed-by: Alejandro SedeƱo Reviewed-by: Paul Wankadia --- python/setup.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/python/setup.py b/python/setup.py index e19949a8..3dbf88f5 100644 --- a/python/setup.py +++ b/python/setup.py @@ -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', @@ -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)