Skip to content

Commit 3a6cbc0

Browse files
Merge pull request #24 from appoptics/NH-14860-pack-and-dist
NH-14860 Fix sdist and wheel creation
2 parents 6d06f64 + 542a5f2 commit 3a6cbc0

File tree

5 files changed

+219
-99
lines changed

5 files changed

+219
-99
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# VS Code
132+
.vscode/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# build development environment to locally build appoptics_apm Python agent and publish RC versions
1+
# build development environment to locally build solarwinds_apm Python agent and publish RC versions
22
FROM quay.io/pypa/manylinux2014_x86_64
33

44
# install packages need to build Ruby and dependencies need to build agent locally

Makefile

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 SolarWinds, LLC
1+
# Copyright 2022 SolarWinds, LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -19,6 +19,16 @@ SHELL=bash
1919
# By default, 'make' does nothing and only prints available options
2020
nothing:
2121
@echo -e "\nHi! How can I help you?"
22+
@echo -e " - 'make package-and-publish':"
23+
@echo -e " Build the agent package distribution and upload it to packagecloud."
24+
@echo -e " - 'make package':"
25+
@echo -e " Build the agent package distribution (sdist and bdist (wheels))."
26+
@echo -e " - 'make sdist':"
27+
@echo -e " Just build the agent package in sdist format."
28+
@echo -e " - 'make manylinux-wheels':"
29+
@echo -e " Just build manylinux 64-bit Python wheels (bdist)."
30+
@echo -e " - 'make aws-lambda':"
31+
@echo -e " Build the AWS Lambda layer (zip archive)."
2232
@echo -e " - 'make wrapper':"
2333
@echo -e " Locally generate SWIG wrapper for C/C++ headers."
2434
@echo -e " - 'STAGING_OBOE=1 make wrapper':"
@@ -107,11 +117,105 @@ download-bson-headers:
107117
# download all required header and library files
108118
download-all: download-headers download-liboboe
109119

120+
#----------------------------------------------------------------------------------------------------------------------#
121+
# check if SWIG is installed
122+
#----------------------------------------------------------------------------------------------------------------------#
123+
124+
check-swig:
125+
@echo -e "Is SWIG installed?"
126+
@command -v swig >/dev/null 2>&1 || \
127+
{ echo >&2 "Swig is required to build the distribution. Aborting."; exit 1;}
128+
@echo -e "Yes."
129+
130+
#----------------------------------------------------------------------------------------------------------------------#
131+
# recipes for building the package distribution
132+
#----------------------------------------------------------------------------------------------------------------------#
133+
134+
wheel_tag := 'manylinux2014_x86_64'
135+
136+
# Build the Python wrapper from liboboe headers inside build container
137+
wrapper: check-swig download-all
138+
@echo -e "Generating SWIG wrapper for C/C++ headers."
139+
@cd solarwinds_apm/extension && ./gen_bindings.sh
140+
141+
# Create package source distribution archive
142+
sdist: wrapper
143+
@echo -e "Generating python agent sdist package"
144+
@python3.8 setup.py sdist
145+
@echo -e "\nDone."
146+
147+
# Build the Python agent package bdist (wheels) for 64 bit many linux systems (except Alpine).
148+
# The recipe builds the wheels for all Python versions available in the docker image, similarly to the example provided
149+
# in the corresponding repo of the Docker images: https://github.com/pypa/manylinux#example.
150+
manylinux-wheels: wrapper
151+
@echo -e "Generating python agent package any-linux wheels for 64 bit systems"
152+
@set -e; for PYBIN in /opt/python/*/bin; do "$${PYBIN}/pip" wheel . -w ./tmp_dist/ --no-deps; done
153+
@echo -e "Tagging wheels with $(wheel_tag)"
154+
@set -e; for whl in ./tmp_dist/*.whl; do auditwheel repair --plat $(wheel_tag) "$$whl" -w ./dist/; done
155+
@rm -rf ./tmp_dist
156+
@echo -e "\nDone."
157+
158+
# Build the full Python agent distribution (sdist and wheels)
159+
package: sdist manylinux-wheels
160+
161+
# Build the AWS lambda layer.
162+
# temporary target directory for AWS Lambda build artifacts
163+
# TODO cp39 and cp310
164+
target_dir := "./tmp/python"
165+
aws-lambda: wrapper
166+
@if [ -f ./dist/solarwinds_apm_lambda.zip ]; then \
167+
echo -e "Deleting old solarwinds_apm_lambda.zip"; \
168+
rm ./dist/solarwinds_apm_lambda.zip; \
169+
fi
170+
rm -rf ./tmp
171+
@echo -e "Creating target directory ${target_dir} for AWS Lambda layer artifacts."
172+
mkdir -p ${target_dir}
173+
@echo -e "Install solarwinds_apm to be packed up in zip archive to target directory."
174+
@/opt/python/cp38-cp38/bin/pip3.8 install . -t ${target_dir}
175+
@echo -e "Removing non-lambda C-extension library files generated by pip install under target directory."
176+
@rm ${target_dir}/solarwinds_apm/extension/*.so*
177+
@echo -e "Building AWS Lambda version of C-extensions for all supported Python versions in target directory."
178+
@set -e; for PYBIN in cp36-cp36m cp37-cp37m cp38-cp38; do /opt/python/$${PYBIN}/bin/python setup.py build_ext_lambda -b ${target_dir}; done
179+
@echo -e "Copying AWS Lambda specific Oboe library liboboe-1.0-lambda-x86_64.so.0.0.0 into target directory."
180+
@cp solarwinds_apm/extension/liboboe-1.0-lambda-x86_64.so.0.0.0 ${target_dir}/solarwinds_apm/extension/liboboe-1.0.so.0
181+
@rm -rf ${target_dir}/*-info
182+
@find ${target_dir} -type d -name '__pycache__' | xargs rm -rf
183+
@if [[ ! -d dist ]]; then mkdir dist; fi
184+
@pushd ./tmp && zip -r ../dist/solarwinds_apm_lambda.zip ./python && popd
185+
@rm -rf ./tmp ./build
186+
@echo -e "\nDone."
110187

111188
#----------------------------------------------------------------------------------------------------------------------#
112-
# DEPRECATED: variable definitions and recipes for copying required header and library files from neighbouring local liboboe directory
189+
# variable and recipe definitions for distribution/ publishing workflow
113190
#----------------------------------------------------------------------------------------------------------------------#
114191

192+
# current version of solarwinds_apm package
193+
package_version :=$(shell grep __version__ ./solarwinds_apm/version.py | cut -d= -f 2 | tr -d ' "')
194+
# Build package from working tree and upload to packagecloud
195+
package-and-publish: package upload-to-packagecloud clean
196+
@echo -e "Built the agent package from local code and uploaded to packagecloud.io"
197+
198+
# Go through the build process and publish AWS Lambda layer RC version
199+
publish-lambda-layer-rc: aws-lambda
200+
@python3.8 publish_lambda_layer.py rc
201+
@echo -e "Done: Built the AWS Lambda layer and uploaded it to AWS."
202+
203+
# Upload built package to packagecloud
204+
pc_repo := "solarwinds/solarwinds-apm-python/python"
205+
pc_token := $(PACKAGECLOUD_TOKEN)
206+
upload-to-packagecloud:
207+
@if [ -z $(pc_token) ]; then \
208+
echo "PACKAGECLOUD_TOKEN environment variable is not set but required to upload to package cloud."; \
209+
exit 1; \
210+
fi
211+
@PACKAGECLOUD_TOKEN=$(pc_token) /usr/local/rvm/bin/rvm 2.5.1 do package_cloud push $(pc_repo) dist/solarwinds_apm-$(package_version).tar.gz
212+
@PACKAGECLOUD_TOKEN=$(pc_token) /usr/local/rvm/bin/rvm 2.5.1 do package_cloud push $(pc_repo) dist/solarwinds_apm-$(package_version)*.whl
213+
214+
#----------------------------------------------------------------------------------------------------------------------#
215+
# recipes for local development
216+
#----------------------------------------------------------------------------------------------------------------------#
217+
218+
# neighbouring local liboboe directory
115219
OTELOBOEREPO := /code/solarwinds-apm-liboboe/liboboe
116220

117221
# Copy the pre-compiled liboboe shared library from source specified in OTELOBOEREPO
@@ -154,8 +258,13 @@ copy-bson-headers:
154258
# copy artifacts from local oboe
155259
copy-all: copy-headers copy-liboboe
156260

261+
# Build the Python wrapper from liboboe headers inside build container
262+
wrapper-from-local: check-swig copy-all
263+
@echo -e "Generating SWIG wrapper for C/C++ headers, from local neighbouring oboe checkout"
264+
@cd solarwinds_apm/extension && ./gen_bindings.sh
265+
157266
#----------------------------------------------------------------------------------------------------------------------#
158-
# variable definitions and recipes for testing and linting
267+
# variable definitions and recipes for testing, linting, cleanup
159268
#----------------------------------------------------------------------------------------------------------------------#
160269

161270
# Example: make tox OPTIONS="-e py37-nh-staging"
@@ -168,32 +277,6 @@ format:
168277
lint:
169278
@echo -e "Not implemented."
170279

171-
#----------------------------------------------------------------------------------------------------------------------#
172-
# recipes for building the package distribution
173-
#----------------------------------------------------------------------------------------------------------------------#
174-
# Check if SWIG is installed
175-
check-swig:
176-
@echo -e "Is SWIG installed?"
177-
@command -v swig >/dev/null 2>&1 || \
178-
{ echo >&2 "Swig is required to build the distribution. Aborting."; exit 1;}
179-
@echo -e "Yes."
180-
181-
# Build the Python wrapper from liboboe headers inside build container
182-
wrapper: check-swig download-all
183-
@echo -e "Generating SWIG wrapper for C/C++ headers."
184-
@cd solarwinds_apm/extension && ./gen_bindings.sh
185-
186-
# Build the Python wrapper from liboboe headers inside build container
187-
wrapper-from-local: check-swig copy-all
188-
@echo -e "Generating SWIG wrapper for C/C++ headers, from local neighbouring oboe checkout"
189-
@cd solarwinds_apm/extension && ./gen_bindings.sh
190-
191-
# Create package source distribution archive
192-
sdist: wrapper
193-
@echo -e "Generating python agent sdist package"
194-
@python3.8 setup.py sdist
195-
@echo -e "\nDone."
196-
197280
# clean up everything.
198281
clean:
199282
@echo -e "Cleaning intermediate files."
@@ -210,4 +293,4 @@ clean:
210293
@rm -f .coverage.*
211294
@echo -e "Done."
212295

213-
.PHONY: nothing verify-oboe-version download-liboboe download-headers download-bson-headers download-all copy-liboboe copy-headers copy-bson-headers copy-all test test-all format lint check-swig wrapper wrapper-from-local sdist clean
296+
.PHONY: nothing verify-oboe-version download-liboboe download-headers download-bson-headers download-all check-swig wrapper sdist manylinux-wheels package aws-lambda package-and-publish publish-lambda-layer-rc upload-to-packagecloud copy-liboboe copy-headers copy-bson-headers copy-all wrapper-from-local tox format lint clean

setup.cfg

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

0 commit comments

Comments
 (0)