Skip to content

Commit 13ca8d4

Browse files
authored
Move wheel building to prep-relase script (#120)
* move building of wheels to prep release script * Add egg info to gitignore * Change variable name of version inside build_wheels * Change verison to python version to not confuse sed command * update variable name * Remove build stuff from script and add SDK_VERSION to setup.py * Remove build from template and add comment to template
1 parent 52e113b commit 13ca8d4

File tree

8 files changed

+68
-96
lines changed

8 files changed

+68
-96
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.idea
33
*__pycache__
44
dist/
5-
onepassword.egg-info/
65
.DS_Store
76
build/
8-
.python-version
7+
.python-version
8+
onepassword_sdk.egg-info/

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PYTHON_VERSIONS := 3.9 3.10 3.11 3.12
22

33
release:
4-
src/release/scripts/release.sh $(PYTHON_VERSIONS)
4+
src/release/scripts/release.sh
55

66
prep-release:
7-
src/release/scripts/prep-release.sh
7+
src/release/scripts/prep-release.sh $(PYTHON_VERSIONS)
88

99
release/install-dependencies:
1010
# Install pyenv

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22
from setuptools import setup, find_packages
33
from sysconfig import get_platform
4+
from version import SDK_VERSION
45
import platform
56
import os
67

@@ -46,7 +47,7 @@ def get_shared_library_data_to_include():
4647

4748
setup(
4849
name="onepassword-sdk",
49-
version="0.1.1",
50+
version=SDK_VERSION,
5051
author="1Password",
5152
long_description= (Path(__file__).parent / "README.md").read_text(),
5253
long_description_content_type='text/markdown',

src/release/scripts/prep-release.sh

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22

33
# Helper script to prepare a release for the Python SDK.
44

5-
output_version_file="src/release/version.py"
5+
output_version_file="version.py"
66
version_template_file="src/release/templates/version.tpl.py"
77

8+
# The list of python verisons the SDKs release for
9+
python_versions=("$@")
10+
11+
# Minimum glibc version we support
12+
glibc_version=2-32
13+
14+
# These versions are being supported due to the SDKs supporting Python 3.9+
15+
macOS_version_x86_64=10.9
16+
macOS_version_arm64=11.0
17+
818
# Extracts the current build/version number for comparison and backup
9-
current_build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "$output_version_file")
1019
current_version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "$output_version_file")
1120

1221
# Function to execute upon exit
1322
cleanup() {
1423
echo "Performing cleanup tasks..."
1524
# Revert changes to file if any
16-
sed -e "s/{{ build }}/$current_build/" -e "s/{{ version }}/$current_version/" "$version_template_file" > "$output_version_file"
25+
sed -e "s/{{ version }}/$current_version/" "$version_template_file" > "$output_version_file"
1726
exit 1
1827
}
1928

@@ -50,27 +59,38 @@ update_and_validate_version() {
5059
done
5160
}
5261

53-
# Function to validate the build number format.
54-
# SEMVER Format: Mmmppbb - 7 Digits
55-
update_and_validate_build() {
56-
while true; do
57-
# Prompt the user to input the build number
58-
read -p "Enter the build number (format: Mmmppbb): " build
59-
60-
# Validate the build number format
61-
if [[ "${build}" =~ ^[0-9]{7}$ ]]; then
62-
if (( 10#$current_build < 10#$build )); then
63-
# Write the valid build number to the file
64-
echo "New build number is: ${build}"
65-
return 0
62+
build_wheels() {
63+
os_platform=$1
64+
machine_platform=$2
65+
66+
export PYTHON_OS_PLATFORM=$os_platform
67+
export PYTHON_MACHINE_PLATFORM=$machine_platform
68+
69+
case "$os_platform" in
70+
Darwin)
71+
macos_version=
72+
if [[ "$machine_platform" == "x86_64" ]]; then
73+
macos_version=$macOS_version_x86_64
6674
else
67-
echo "New build version should be higher than current build version."
75+
macos_version=$macOS_version_arm64
6876
fi
69-
else
70-
echo "Invalid build number format: ${build}"
71-
echo "Please enter a build number in the 'Mmmppbb' format."
72-
fi
73-
done
77+
78+
export _PYTHON_HOST_PLATFORM="macosx-${macos_version}-${PYTHON_MACHINE_PLATFORM}"
79+
;;
80+
Linux)
81+
export _PYTHON_HOST_PLATFORM="manylinux-${glibc_version}-${PYTHON_MACHINE_PLATFORM}"
82+
;;
83+
Windows)
84+
export _PYTHON_HOST_PLATFORM="win-${PYTHON_MACHINE_PLATFORM}"
85+
;;
86+
*)
87+
echo "Unsupported OS: $os_platform"
88+
exit 1
89+
;;
90+
esac
91+
92+
pyenv exec python setup.py bdist_wheel
93+
rm -rf build
7494
}
7595

7696
# Ensure working directory is clean
@@ -79,11 +99,21 @@ enforce_latest_code
7999
# Update and validate the version number
80100
update_and_validate_version
81101

82-
# Update and validate the build number
83-
update_and_validate_build
84-
85-
# Update version & build number in version.py
86-
sed -e "s/{{ build }}/$build/" -e "s/{{ version }}/$version/" "$version_template_file" > "$output_version_file"
102+
# Update version in version.py
103+
sed -e "s/{{ version }}/$version/" "$version_template_file" > "$output_version_file"
104+
105+
# Acquire the wheels for different OS
106+
for python_version in "${python_versions[@]}"; do
107+
pyenv local $python_version
108+
build_wheels Darwin x86_64
109+
build_wheels Darwin arm64
110+
build_wheels Linux x86_64
111+
build_wheels Linux aarch64
112+
build_wheels Windows amd64
113+
done
114+
115+
# Build Source as well incase wheels fails, pypi can install this as backup (standard practice)
116+
python3 -m build --sdist
87117

88118
printf "Press ENTER to edit the RELEASE-NOTES in your default editor...\n"
89119
read -r _ignore

src/release/scripts/release.sh

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,8 @@
44

55
set -e
66

7-
# The list of python verisons the SDKs release for
8-
python_versions=("$@")
9-
10-
# Minimum glibc version we support
11-
glibc_version=2-32
12-
13-
# These versions are being supported due to the SDKs supporting Python 3.9+
14-
macOS_version_x86_64=10.9
15-
macOS_version_arm64=11.0
16-
17-
build_wheels() {
18-
os_platform=$1
19-
machine_platform=$2
20-
21-
export PYTHON_OS_PLATFORM=$os_platform
22-
export PYTHON_MACHINE_PLATFORM=$machine_platform
23-
24-
case "$os_platform" in
25-
Darwin)
26-
version=
27-
if [[ "$machine_platform" == "x86_64" ]]; then
28-
version=$macOS_version_x86_64
29-
else
30-
version=$macOS_version_arm64
31-
fi
32-
33-
export _PYTHON_HOST_PLATFORM="macosx-${version}-${PYTHON_MACHINE_PLATFORM}"
34-
;;
35-
Linux)
36-
export _PYTHON_HOST_PLATFORM="manylinux-${glibc_version}-${PYTHON_MACHINE_PLATFORM}"
37-
;;
38-
Windows)
39-
export _PYTHON_HOST_PLATFORM="win-${PYTHON_MACHINE_PLATFORM}"
40-
;;
41-
*)
42-
echo "Unsupported OS: $os_platform"
43-
exit 1
44-
;;
45-
esac
46-
47-
pyenv exec python setup.py bdist_wheel
48-
rm -rf build
49-
}
50-
517
# Read the contents of the files into variables
52-
version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "src/release/version.py")
53-
build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "src/release/version.py")
8+
version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "version.py")
549
release_notes=$(< src/release/RELEASE-NOTES)
5510

5611
# Check if Github CLI is installed
@@ -72,20 +27,6 @@ git push origin tag "v${version}"
7227

7328
gh release create "v${version}" --title "Release ${version}" --notes "${release_notes}" --repo github.com/1Password/onepassword-sdk-python
7429

75-
76-
# Acquire the wheels for different OS
77-
for version in "${python_versions[@]}"; do
78-
pyenv local $version
79-
build_wheels Darwin x86_64
80-
build_wheels Darwin arm64
81-
build_wheels Linux x86_64
82-
build_wheels Linux aarch64
83-
build_wheels Windows amd64
84-
done
85-
86-
# Build Source as well incase wheels fails, pypi can install this as backup (standard practice)
87-
python3 -m build --sdist
88-
8930
# Release on PyPi
9031
python3 -m twine upload dist/*
9132

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SDK_VERSION = "{{ version }}"
2-
SDK_BUILD_NUMBER = "{{ build }}"
1+
# TODO: Refactor so SDK_BUILD_NUMBER can be inside and not hardcoded in defaults.py
2+
SDK_VERSION = "{{ version }}"

src/release/version.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TODO: Refactor so SDK_BUILD_NUMBER can be inside and not hardcoded in defaults.py
2+
SDK_VERSION = "0.1.1"

0 commit comments

Comments
 (0)