aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorckl <ckl@google.com>2023-06-18 23:25:59 -0700
committerCopybara-Service <copybara-worker@google.com>2023-06-18 23:27:13 -0700
commitdbe5cec2ae547f4216c5850742c375c1e886d73c (patch)
tree7400de481904617375535b4f1ce9c9c48accdd89 /python
parent494bac342fb4e0c2f8b6648b3fcea4be830856ed (diff)
downloadtink-dbe5cec2ae547f4216c5850742c375c1e886d73c.tar.gz
Fix sdist WORKSPACE patching.
PiperOrigin-RevId: 541527414
Diffstat (limited to 'python')
-rw-r--r--python/setup.py16
-rwxr-xr-xpython/tools/distribution/create_release.sh7
2 files changed, 17 insertions, 6 deletions
diff --git a/python/setup.py b/python/setup.py
index df164570d..4c13a1a05 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -27,6 +27,7 @@ import textwrap
import setuptools
from setuptools.command import build_ext
+from setuptools.command import sdist
_PROJECT_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -135,7 +136,7 @@ def _patch_workspace(workspace_file):
workspace_content = _patch_with_local_path(workspace_content, base_path)
elif 'TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION' in os.environ:
- tagged_version = os.environ['TINK_PYTHON_SETUP_TOOLS_TAGGED_VERSION']
+ tagged_version = os.environ['TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION']
archive_filename = 'v{}.zip'.format(tagged_version)
archive_prefix = 'tink-{}'.format(tagged_version)
workspace_content = _patch_with_http_archive(workspace_content,
@@ -242,6 +243,14 @@ class BuildBazelExtension(build_ext.build_ext):
shutil.copyfile(ext_bazel_bin_path, ext_dest_path)
+class SdistCmd(sdist.sdist):
+ """A command that patches the workspace before creating an sdist."""
+
+ def run(self):
+ _patch_workspace('WORKSPACE')
+ sdist.sdist.run(self)
+
+
def main():
# Generate compiled protocol buffers.
protoc_command = _get_protoc_command()
@@ -262,7 +271,10 @@ def main():
# Contained modules and scripts.
packages=setuptools.find_packages(),
install_requires=_parse_requirements('requirements.in'),
- cmdclass=dict(build_ext=BuildBazelExtension),
+ cmdclass={
+ 'build_ext': BuildBazelExtension,
+ 'sdist': SdistCmd,
+ },
ext_modules=[
BazelExtension('//tink/cc/pybind:tink_bindings'),
],
diff --git a/python/tools/distribution/create_release.sh b/python/tools/distribution/create_release.sh
index 8b19cd419..a15d9c41e 100755
--- a/python/tools/distribution/create_release.sh
+++ b/python/tools/distribution/create_release.sh
@@ -103,16 +103,15 @@ __create_and_test_sdist_for_linux() {
# Patch the workspace to use http_archive rules which specify the release tag.
#
# This is done so that an already patched version of WORKSPACE is present in
- # the sdist. THen, when building from the sdist, the default patching logic
+ # the sdist. Then, when building from the sdist, the default patching logic
# in performed by setup.py will be a no-op.
#
# TODO(b/281635529): Use a container for a more hermetic testing environment.
cp WORKSPACE WORKSPACE.bak
- TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION="${TINK_VERSION}" \
- python3 -c "import setup; _patch_workspace('WORKSPACE')"
# Build source distribution.
- python3 setup.py sdist --owner=root --group=root
+ TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION="${TINK_VERSION}" \
+ python3 setup.py sdist --owner=root --group=root
local sdist_filename="tink-${TINK_VERSION}.tar.gz"
cp "dist/${sdist_filename}" release/