From eb2f91421d243eec7630cf6af403b61aa1b81025 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Thu, 26 Sep 2013 10:53:31 -0700 Subject: [PATCH] Use twine to upload python package to pypi. * modules/jenkins/files/slave_scripts/pypi-extract-metadata.py: Twine deals with metadata for us, this script is no longer needed. * modules/jenkins/files/slave_scripts/pypi-upload.sh: Use twine instead of calculating md5sum ourselves and extracting metadata then uploading with curl. * modules/openstack_project/manifests/pypi_slave.pp: Insteall twine (replaces pkginfo dependency). * modules/openstack_project/templates/pypirc.erb: Twine can use a pypirc to determine where and with what credentials to upload pacakges. Create a .pypirc for twine. Change-Id: I8a6aaf5d2c77151a60c2c660e1ff8570fc9255ea --- .../slave_scripts/pypi-extract-metadata.py | 56 ------------------- .../files/slave_scripts/pypi-upload.sh | 18 +----- .../openstack_project/manifests/pypi_slave.pp | 6 +- .../openstack_project/templates/pypicurl.erb | 1 - .../openstack_project/templates/pypirc.erb | 4 ++ 5 files changed, 8 insertions(+), 77 deletions(-) delete mode 100644 modules/jenkins/files/slave_scripts/pypi-extract-metadata.py delete mode 100644 modules/openstack_project/templates/pypicurl.erb create mode 100644 modules/openstack_project/templates/pypirc.erb diff --git a/modules/jenkins/files/slave_scripts/pypi-extract-metadata.py b/modules/jenkins/files/slave_scripts/pypi-extract-metadata.py deleted file mode 100644 index f400f023d6..0000000000 --- a/modules/jenkins/files/slave_scripts/pypi-extract-metadata.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2012 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# Extract package info metadata for use by curl. - -import pkginfo -import sys - -if len(sys.argv) < 3: - exit() - -info = pkginfo.SDist(sys.argv[1]) -curl_config = open(sys.argv[2], 'w') - -meta_items = { - 'metadata_version': info.metadata_version, - 'summary': info.summary, - 'home_page': info.home_page, - 'author': info.author, - 'author_email': info.author_email, - 'license': info.license, - 'description': info.description, - 'keywords': info.keywords, - 'platform': info.platforms, - 'classifiers': info.classifiers, - 'download_url': info.download_url, - 'provides': info.provides, - 'requires': info.requires, - 'obsoletes': info.obsoletes, -} - -for key, value in meta_items.items(): - if not value: - continue - if not isinstance(value, list): - value = [value] - for v in value: - v = v.replace('\n', r'\n') - v = v.replace('"', r'\"') - curl_config.write('form = "%s=%s"\n' % (key, v)) - -curl_config.write('\n') -curl_config.close() diff --git a/modules/jenkins/files/slave_scripts/pypi-upload.sh b/modules/jenkins/files/slave_scripts/pypi-upload.sh index 66d4ed5342..19e5f62d4c 100755 --- a/modules/jenkins/files/slave_scripts/pypi-upload.sh +++ b/modules/jenkins/files/slave_scripts/pypi-upload.sh @@ -33,20 +33,4 @@ curl --fail -o $FILENAME http://$TARBALL_SITE/$PROJECT/$FILENAME # Make sure we actually got a gzipped file file -b $FILENAME | grep gzip -MD5_DIGEST=`md5sum ${FILENAME} | cut -d' ' -f1` - -/usr/local/jenkins/slave_scripts/pypi-extract-metadata.py $FILENAME metadata.curl - -# Turn off xtrace and mute curl, since under some circumstances API -# errors may leak authentication credentials -set +x -curl --config /home/jenkins/.pypicurl \ - --config metadata.curl \ - -F "filetype=sdist" \ - -F "content=@${FILENAME};filename=${FILENAME}" \ - -F ":action=file_upload" \ - -F "protocol_version=1" \ - -F "name=${DISTNAME}" \ - -F "version=${TAG}" \ - -F "md5_digest=${MD5_DIGEST}" \ - https://pypi.python.org/pypi > /dev/null 2>&1 +twine upload $FILENAME diff --git a/modules/openstack_project/manifests/pypi_slave.pp b/modules/openstack_project/manifests/pypi_slave.pp index b6f44c4334..b43bf2a091 100644 --- a/modules/openstack_project/manifests/pypi_slave.pp +++ b/modules/openstack_project/manifests/pypi_slave.pp @@ -28,18 +28,18 @@ class openstack_project::pypi_slave ( include pip - package { 'pkginfo': + package { 'twine': ensure => present, provider => 'pip', require => Class['pip'], } - file { '/home/jenkins/.pypicurl': + file { '/home/jenkins/.pypirc': ensure => present, owner => 'jenkins', group => 'jenkins', mode => '0600', - content => template('openstack_project/pypicurl.erb'), + content => template('openstack_project/pypirc.erb'), require => File['/home/jenkins'], } diff --git a/modules/openstack_project/templates/pypicurl.erb b/modules/openstack_project/templates/pypicurl.erb deleted file mode 100644 index fe48657dd4..0000000000 --- a/modules/openstack_project/templates/pypicurl.erb +++ /dev/null @@ -1 +0,0 @@ -user = "<%= pypi_username %>:<%= pypi_password %>" diff --git a/modules/openstack_project/templates/pypirc.erb b/modules/openstack_project/templates/pypirc.erb new file mode 100644 index 0000000000..87bc32b7e7 --- /dev/null +++ b/modules/openstack_project/templates/pypirc.erb @@ -0,0 +1,4 @@ +[pypi] +repository: https://pypi.python.org/pypi +username: <%= pypi_username %> +password: <%= pypi_password %>