Skip to content

Commit b4370b8

Browse files
authored
Improve Python SDK Release Process (#128)
* Add build number to prep release script and seperate building of wheels into another script * Removal of checking if main is latest * Add new build_number file and edit script paths etc * Release v0.1.4 * revert version/build changes and remove newline from templates * remove newlines * Add MANIFEST.in file to include version.py in sdist and add Python 3.13 support * Added MANIFEST.in correctly * Fix comment * Add support for minimum macos version for Python 3.13 * update makefile with wider compatiablity installation and update readme * Add newline in MANIFEST and update readme as well as makefile to install pyenv * Make files POSIX compliant * Remove extra line
1 parent e7845ab commit b4370b8

File tree

11 files changed

+147
-67
lines changed

11 files changed

+147
-67
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include version.py

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
PYTHON_VERSIONS := 3.9 3.10 3.11 3.12
1+
PYTHON_VERSIONS := 3.9 3.10 3.11 3.12 3.13
22

33
release:
44
src/release/scripts/release.sh
55

66
prep-release:
7-
src/release/scripts/prep-release.sh $(PYTHON_VERSIONS)
7+
src/release/scripts/prep-release.sh
8+
9+
build-wheels:
10+
src/release/scripts/build-wheels.sh $(PYTHON_VERSIONS)
811

912
release/install-dependencies:
10-
# Install pyenv
13+
# Install latest version of pyenv if not already installed
1114
brew install pyenv
12-
13-
# Install build
14-
pip install build --break-system-packages
1515

1616
# Install all the python versions we support in one line
1717
pyenv install --skip-existing $(PYTHON_VERSIONS)
1818

1919
# Set pyenv local and install dependencies for each version
2020
for version in $(PYTHON_VERSIONS); do \
2121
pyenv local $$version; \
22-
pyenv exec pip install wheel setuptools; \
23-
done
22+
pyenv exec pip3 install wheel setuptools build --break-system-packages; \
23+
done
24+

src/onepassword/build_number.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SDK_BUILD_NUMBER = "0010301"

src/onepassword/defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import platform
2+
from onepassword.build_number import SDK_BUILD_NUMBER
23

34
SDK_LANGUAGE = "Python"
4-
SDK_VERSION = "0010301"
5+
SDK_VERSION = SDK_BUILD_NUMBER
56
DEFAULT_INTEGRATION_NAME = "Unknown"
67
DEFAULT_INTEGRATION_VERSION = "Unknown"
78
DEFAULT_REQUEST_LIBRARY = "reqwest"

src/release/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ make prep-release
1616
```
1717
Follow the scripts instructions and the release has now been prepped.
1818

19-
Step 3. Ensure that the correct files have been updated - i.e. version/build files, release-notes has been updated. Suggest doing a `git diff` to see the changes.
19+
Step 3. Ensure that the correct files have been updated - i.e. version/build files, release-notes has been updated. Check the latest commit on the branch to see your changes.
2020

21-
Step 4. Ensure your GITHUB_TOKEN environment variable is set as this will allow you to create the tags/release and push it.
21+
Step 4. To build the wheels and source distribution for PyPi, run in the root of the repo:
22+
```
23+
make build-wheels
24+
```
25+
26+
Step 5. Ensure your GITHUB_TOKEN environment variable is set as this will allow you to create the tags/release and push it.
2227

2328
Step 6. Ensure you have the PyPi credentials to login when uploading the source and wheels to PyPi.
2429

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# Helper script to build the required wheels for the Python SDK
4+
5+
output_version_file="version.py"
6+
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+
# Extracts the current verison number for cleanup function
18+
current_version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "$output_version_file")
19+
20+
# Function to execute upon exit
21+
cleanup() {
22+
echo "Performing cleanup tasks..."
23+
# Remove dist and egg-info and the potential release candidate if created
24+
rm -r dist src/*.egg-info/ onepassword_sdk-"${current_version}"
25+
exit 1
26+
}
27+
28+
# Set the trap to call the cleanup function on exit
29+
trap cleanup SIGINT
30+
31+
32+
enforce_latest_code() {
33+
if [[ -n "$(git status --porcelain=v1)" ]]; then
34+
echo "ERROR: working directory is not clean."
35+
echo "Please stash your changes and try again."
36+
exit 1
37+
fi
38+
}
39+
40+
build_wheels() {
41+
os_platform=$1
42+
machine_platform=$2
43+
44+
export PYTHON_OS_PLATFORM=$os_platform
45+
export PYTHON_MACHINE_PLATFORM=$machine_platform
46+
47+
case "$os_platform" in
48+
Darwin)
49+
macos_version=
50+
# Min MacOS version for Python 3.13+ is 10.13
51+
python_version=$(pyenv exec python3 --version 2>&1)
52+
if [[ "$python_version" == "Python 3.13"* ]]; then
53+
macos_version="10.13"
54+
else
55+
56+
if [[ "$machine_platform" == "x86_64" ]]; then
57+
macos_version=$macOS_version_x86_64
58+
else
59+
macos_version=$macOS_version_arm64
60+
fi
61+
fi
62+
63+
export _PYTHON_HOST_PLATFORM="macosx-${macos_version}-${PYTHON_MACHINE_PLATFORM}"
64+
;;
65+
Linux)
66+
export _PYTHON_HOST_PLATFORM="manylinux-${glibc_version}-${PYTHON_MACHINE_PLATFORM}"
67+
;;
68+
Windows)
69+
export _PYTHON_HOST_PLATFORM="win-${PYTHON_MACHINE_PLATFORM}"
70+
;;
71+
*)
72+
echo "Unsupported OS: $os_platform"
73+
exit 1
74+
;;
75+
esac
76+
77+
pyenv exec python3 -m build --wheel
78+
rm -rf build
79+
}
80+
81+
# Ensure that the current working directory is clean and building of wheels is made off of latest main
82+
enforce_latest_code
83+
84+
# Acquire the wheels for different OS
85+
for python_version in "${python_versions[@]}"; do
86+
pyenv local $python_version
87+
build_wheels Darwin x86_64
88+
build_wheels Darwin arm64
89+
build_wheels Linux x86_64
90+
build_wheels Linux aarch64
91+
build_wheels Windows amd64
92+
done
93+
94+
# Build Source as well incase wheels fails, pypi can install this as backup (standard practice)
95+
pyenv exec python3 -m build --sdist

src/release/scripts/prep-release.sh

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@
33
# Helper script to prepare a release for the Python SDK.
44

55
output_version_file="version.py"
6+
output_build_file="src/onepassword/build_number.py"
67
version_template_file="src/release/templates/version.tpl.py"
8+
build_number_template_file="src/release/templates/build_number.tpl.py"
79

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
1710

1811
# Extracts the current build/version number for comparison and backup
1912
current_version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "$output_version_file")
13+
current_build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "$output_build_file")
2014

2115
# Function to execute upon exit
2216
cleanup() {
2317
echo "Performing cleanup tasks..."
2418
# Revert changes to file if any
2519
sed -e "s/{{ version }}/$current_version/" "$version_template_file" > "$output_version_file"
20+
sed -e "s/{{ build }}/$current_build/" "$build_number_template_file" > "$output_build_file"
2621
exit 1
2722
}
2823

@@ -59,61 +54,42 @@ update_and_validate_version() {
5954
done
6055
}
6156

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
57+
# Function to validate the build number format.
58+
# SEMVER Format: Mmmppbb - 7 Digits
59+
update_and_validate_build() {
60+
while true; do
61+
# Prompt the user to input the build number
62+
read -p "Enter the build number (format: Mmmppbb): " build
63+
64+
# Validate the build number format
65+
if [[ "${build}" =~ ^[0-9]{7}$ ]]; then
66+
if (( 10#$current_build < 10#$build )); then
67+
# Write the valid build number to the file
68+
echo "New build number is: ${build}"
69+
return 0
7470
else
75-
macos_version=$macOS_version_arm64
76-
fi
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
71+
echo "New build version should be higher than current build version."
72+
fi
73+
else
74+
echo "Invalid build number format: ${build}"
75+
echo "Please enter a build number in the 'Mmmppbb' format."
76+
fi
77+
done
9478
}
9579

96-
# Ensure working directory is clean
80+
# Ensure that the current working directory is clean
9781
enforce_latest_code
9882

9983
# Update and validate the version number
10084
update_and_validate_version
10185

102-
# Update version in version.py
86+
# Update and validate the build number
87+
update_and_validate_build
88+
89+
# Update version & build number in version.py and build_number.py respectively
10390
sed -e "s/{{ version }}/$version/" "$version_template_file" > "$output_version_file"
91+
sed -e "s/{{ build }}/$build/" "$build_number_template_file" > "$output_build_file"
10492

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
11793

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

src/release/scripts/release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -e
66

77
# Read the contents of the files into variables
88
version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "version.py")
9+
build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "src/onepassword/build_number.py")
910
release_notes=$(< src/release/RELEASE-NOTES)
1011

1112
# Check if Github CLI is installed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SDK_BUILD_NUMBER = "{{ build }}"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# TODO: Refactor so SDK_BUILD_NUMBER can be inside and not hardcoded in defaults.py
21
SDK_VERSION = "{{ version }}"

0 commit comments

Comments
 (0)