Skip to content

Commit

Permalink
Improve Travis deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Jun 26, 2017
1 parent 674e992 commit d0dd58a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ script:
- python ./azure_nosetests.py
after_success:
- bash <(curl -s https://codecov.io/bash)
before_deploy:
- python ./before_deploy.py
deploy:
provider: pypi
user: Laurent.Mazuel
# password: use $PYPI_PASSWORD
# server: $PYPI_SERVER to override PyPI (e.g. https://testpypi.python.org/)
distributions: check # Hack, packages will be created by "before deploy" script
distributions: travis_deploy # Personal step
skip_upload_docs: true
on:
tags: true
Expand Down
34 changes: 0 additions & 34 deletions before_deploy.py

This file was deleted.

34 changes: 33 additions & 1 deletion build_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import argparse
import os
import sys
import re
from pathlib import Path
from subprocess import check_call

DEFAULT_DEST_FOLDER = "./dist"
Expand All @@ -17,11 +20,40 @@ def create_package(name, dest_folder=DEFAULT_DEST_FOLDER):
check_call(['python', 'setup.py', 'bdist_wheel', '-d', dest_folder], cwd=absdirpath)
check_call(['python', 'setup.py', "sdist", "--format", "zip", '-d', dest_folder], cwd=absdirpath)

def travis_build_package():
"""Assumed called on Travis, to prepare a package to be deployed
This method prints on stdout for Travis.
Return is obj to pass to sys.exit() directly
"""
travis_tag = os.environ.get('TRAVIS_TAG')
if not travis_tag:
print("TRAVIS_TAG environment variable is not present")
return

matching = re.match(r"^(?P<name>azure[a-z\-]*)_(?P<version>[.0-9]+[rc0-9]*)$", travis_tag)
if not matching:
print("TRAVIS_TAG is not '<package_name> <version>' (tag is: {})".format(travis_tag))
return

name, version = matching.groups()
create_package(name, '../dist')

print("Produced:\n{}".format(list(Path('./dist').glob('*'))))

pattern = "*{}*".format(version)
packages = list(Path('./dist').glob(pattern))
if not packages:
return "Package version does not match tag {}, abort".format(version)
pypi_server = os.environ.get("PYPI_SERVER", "default PyPI server")
print("Package created as expected and will be pushed to {}".format(pypi_server))


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Build Azure package.')
parser.add_argument('name', help='The package name')
parser.add_argument('--dest', '-d', default=DEFAULT_DEST_FOLDER,
help='Destination folder. Relative to the package dir. [default: %(default)s]')

args = parser.parse_args()
create_package(args.name, args.dest)
create_package(args.name, args.dest)
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import copy
import sys
import runpy
from build_package import travis_build_package

root_folder = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -36,6 +37,8 @@
# Package final:
if "install" in sys.argv:
packages = content_package
elif "travis_deploy" in sys.argv:
sys.exit(travis_build_package())
else:
packages = nspkg_packages + content_package + meta_package

Expand Down

0 comments on commit d0dd58a

Please sign in to comment.