Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Fix Python setup.py and create_release.sh.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 384860018
  • Loading branch information
chuckx authored and copybara-github committed Jul 15, 2021
1 parent 4eb63c6 commit 465753a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
29 changes: 16 additions & 13 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ def _patch_workspace(workspace_content):
base_path = os.environ['TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH']
return _patch_with_local_path(workspace_content, base_path)

if 'TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION' in os.eviron:
if 'TINK_PYTHON_SETUPTOOLS_TAGGED_VERSION' in os.environ:
archive_filename = 'v{}.zip'.format(_TINK_VERSION)
return _patch_with_http_archive(workspace_content, archive_filename)
archive_prefix = 'tink-{}'.format(_TINK_VERSION)
return _patch_with_http_archive(workspace_content,
archive_filename, archive_prefix)

return _patch_with_http_archive(workspace_content, 'master.zip')
return _patch_with_http_archive(workspace_content,
'master.zip', 'tink-master')


def _patch_with_local_path(workspace_content, base_path):
Expand All @@ -147,7 +150,7 @@ def _patch_with_local_path(workspace_content, base_path):
return workspace_content


def _patch_with_http_archive(workspace_content, filename):
def _patch_with_http_archive(workspace_content, filename, prefix):
"""Replaces local_repository() rules with http_archive() rules."""

workspace_lines = workspace_content.split('\n')
Expand All @@ -169,28 +172,28 @@ def _patch_with_http_archive(workspace_content, filename):
local_repository(
name = "tink_cc",
path = "../cc",
))
)
''')

base_patched = textwrap.dedent(
'''\
# Modified by setup.py
http_archive(
name = "tink_base",
urls = ["https://github.com/google/tink/archive/{}.zip"],
strip_prefix = "tink-master/",
))
'''.format(filename))
urls = ["https://github.com/google/tink/archive/{}"],
strip_prefix = "{}/",
)
'''.format(filename, prefix))

cc_patched = textwrap.dedent(
'''\
# Modified by setup.py
http_archive(
name = "tink_cc",
urls = ["https://github.com/google/tink/archive/{}.zip"],
strip_prefix = "tink-master/cc",
))
'''.format(filename))
urls = ["https://github.com/google/tink/archive/{}"],
strip_prefix = "{}/cc",
)
'''.format(filename, prefix))

workspace_content = workspace_content.replace(base, base_patched)
workspace_content = workspace_content.replace(cc, cc_patched)
Expand Down
28 changes: 11 additions & 17 deletions python/tools/distribution/create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ readonly PYTHON_VERSIONS

readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"

readonly TINK_SRC_PATH="${PWD}/.."
export TINK_SRC_PATH="${PWD}/.."
readonly TINK_VERSION="$(grep ^TINK "${TINK_SRC_PATH}/tink_version.bzl" \
| awk '{gsub(/"/, "", $3); print $3}')"

Expand All @@ -39,13 +39,6 @@ readonly IMAGE="${IMAGE_NAME}@${IMAGE_DIGEST}"
build_linux() {
echo "### Building Linux binary wheels ###"

if [[ -n "${KOKORO_ROOT}" ]] ; then
eval "$(pyenv init -)"
pyenv versions
fi

mkdir -p release

# Use signatures for getting images from registry (see
# https://docs.docker.com/engine/security/trust/content_trust/).
export DOCKER_CONTENT_TRUST=1
Expand Down Expand Up @@ -73,23 +66,21 @@ build_linux() {

# Test install from source distribution.
python3 --version
pip3 list
pip3 install -v "release/${sdist_filename}"
pip3 list
python3 -m pip list
python3 -m pip install -v "release/${sdist_filename}"
python3 -m pip list
find tink/ -not -path "*cc/pybind*" -type f -name "*_test.py" -print0 \
| xargs -0 -n1 python3
}

build_macos() {
echo "### Building macOS binary wheels ###"

mkdir -p release

for v in "${PYTHON_VERSIONS[@]}"; do
enable_py_version "${v}"

# Build binary wheel.
pip3 wheel -w release .
python3 -m pip wheel -w release .

# Test binary wheel.
# TODO(ckl): Implement test.
Expand All @@ -108,9 +99,9 @@ enable_py_version() {
pyenv shell "${version}"

# Update environment.
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install --upgrade wheel
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade wheel
}

# setuptools does not replicate the distutils feature of explicitly setting
Expand All @@ -130,6 +121,9 @@ set_owner_within_tar() {
}

main() {
eval "$(pyenv init -)"
mkdir -p release

if [[ "${PLATFORM}" == 'linux' ]]; then
build_linux
elif [[ "${PLATFORM}" == 'darwin' ]]; then
Expand Down

0 comments on commit 465753a

Please sign in to comment.