Skip to content

Commit 52e113b

Browse files
authored
Publish the 1Password SDK for Python on PyPI (#114)
* Add pypy support. This commit pushes to testPyPi * Uncomment commented code * Update metadata and readme for PyPi and make code more modular * Fix setup.py and refactor script more * Add source package and wheel packaging of macos 10.9 and 11.0 * Change variable name and reduce scope of version to just Darwin case * Add new command to setup.py and refactor script * add new line at EOF * Revert from sdk_version to verson * remove --verbose flag * Add min pydantic version * Use pyenv to upload wheels for each Python Version and update release readme with new instructions * Remove support of Python 3.8 and update makefile to install required dependencies for pyenv * Add installation of pyenv to the make target and update readme * update setup.py to include more metadata * Add installing build to dependencies * add break system packages flag
1 parent c9443c4 commit 52e113b

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
dist/
55
onepassword.egg-info/
66
.DS_Store
7-
build/
7+
build/
8+
.python-version

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
PYTHON_VERSIONS := 3.9 3.10 3.11 3.12
2+
13
release:
2-
src/release/scripts/release.sh
4+
src/release/scripts/release.sh $(PYTHON_VERSIONS)
35

46
prep-release:
57
src/release/scripts/prep-release.sh
68

9+
release/install-dependencies:
10+
# Install pyenv
11+
brew install pyenv
12+
13+
# Install build
14+
pip install build --break-system-packages
15+
16+
# Install all the python versions we support in one line
17+
pyenv install --skip-existing $(PYTHON_VERSIONS)
718

19+
# Set pyenv local and install dependencies for each version
20+
for version in $(PYTHON_VERSIONS); do \
21+
pyenv local $$version; \
22+
pyenv exec pip install wheel setuptools; \
23+
done

setup.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from setuptools import setup, find_packages
23
from sysconfig import get_platform
34
import platform
@@ -13,14 +14,15 @@ def finalize_options(self):
1314
# This platform naming is sufficient for distributing this package via source cloning (e.g. pip + GitHub) since the wheel will be built locally
1415
# for each user's platform: https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#basic-platform-tags
1516
self.plat_name = get_platform().translate({"-": "_", ".": "_"})
17+
self.plat_name_supplied = True
1618
except ImportError:
1719
bdist_wheel = None
1820

1921

2022
def get_shared_library_data_to_include():
2123
# Return the correct uniffi C shared library extension for the given platform
2224
include_path = "lib"
23-
machine_type = platform.machine().lower()
25+
machine_type = os.getenv("PYTHON_MACHINE_PLATFORM") or platform.machine().lower()
2426
if machine_type in ["x86_64", "amd64"]:
2527
include_path = os.path.join(include_path, "x86_64")
2628
elif machine_type in ["aarch64", "arm64"]:
@@ -32,7 +34,8 @@ def get_shared_library_data_to_include():
3234
"Linux": "libop_uniffi_core.so",
3335
"Windows": "op_uniffi_core.dll",
3436
}
35-
c_shared_library_file_name = platform_to_lib.get(platform.system(), "")
37+
platform_name = os.getenv("PYTHON_OS_PLATFORM") or platform.system()
38+
c_shared_library_file_name = platform_to_lib.get(platform_name, "")
3639
c_shared_library_file_name = os.path.join(include_path, c_shared_library_file_name)
3740

3841
uniffi_bindings_file_name = "op_uniffi_core.py"
@@ -42,18 +45,34 @@ def get_shared_library_data_to_include():
4245

4346

4447
setup(
45-
name="onepassword",
48+
name="onepassword-sdk",
4649
version="0.1.1",
4750
author="1Password",
51+
long_description= (Path(__file__).parent / "README.md").read_text(),
52+
long_description_content_type='text/markdown',
4853
description="The 1Password Python SDK offers programmatic read access to your secrets in 1Password in an interface native to Python.",
4954
url="https://github.com/1Password/onepassword-sdk-python",
5055
packages=find_packages(
5156
where="src",
5257
),
58+
license="MIT",
59+
license_files="LICENSE",
5360
package_dir={"": "src"},
61+
python_requires=">=3.9",
62+
classifiers = [
63+
"Development Status :: 5 - Production/Stable",
64+
"Operating System :: MacOS",
65+
"Operating System :: POSIX :: Linux",
66+
"Operating System :: Microsoft :: Windows",
67+
"Programming Language :: Python :: 3.9",
68+
"Programming Language :: Python :: 3.10",
69+
"Programming Language :: Python :: 3.11",
70+
"Programming Language :: Python :: 3.12",
71+
"License :: OSI Approved :: MIT License"
72+
],
5473
cmdclass={"bdist_wheel": bdist_wheel},
5574
package_data={"": get_shared_library_data_to_include()},
5675
install_requires=[
57-
"pydantic",
76+
"pydantic>=2.5", # Minimum Pydantic version to run the Python SDK
5877
],
5978
)

src/release/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Before running this script, the user must make sure that they have the write permissions to the Python SDK repository.
44

5+
Run this make command to install all dependencies required for the Python SDK release process.
6+
```
7+
release/install-dependencies
8+
```
9+
510
Step 1. Make any changes to the SDK as required on a feature branch or main branch.
611
NOTE: If ran on a main branch, a release branch will be created.
712

@@ -15,8 +20,10 @@ Step 3. Ensure that the correct files have been updated - i.e. version/build fil
1520

1621
Step 4. Ensure your GITHUB_TOKEN environment variable is set as this will allow you to create the tags/release and push it.
1722

18-
Step 5. If everything looks good, at the root of the repo, run:
23+
Step 6. Ensure you have the PyPi credentials to login when uploading the source and wheels to PyPi.
24+
25+
Step 7. If everything looks good, at the root of the repo, run:
1926
```
2027
make release
2128
```
22-
Step 6. Congratulations, you have released the newest Python SDK!
29+
Step 8. Congratulations, you have released the newest Python SDK!

src/release/scripts/release.sh

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,55 @@
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+
751
# Read the contents of the files into variables
852
version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "src/release/version.py")
953
build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "src/release/version.py")
1054
release_notes=$(< src/release/RELEASE-NOTES)
1155

12-
1356
# Check if Github CLI is installed
1457
if ! command -v gh &> /dev/null; then
1558
echo "gh is not installed";\
@@ -29,3 +72,23 @@ git push origin tag "v${version}"
2972

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

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+
89+
# Release on PyPi
90+
python3 -m twine upload dist/*
91+
92+
# Delete the dist folder after published
93+
rm -r dist src/*.egg-info
94+

0 commit comments

Comments
 (0)