Skip to content

Commit

Permalink
Improve release script [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Jan 25, 2018
1 parent f4715da commit 587bc9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions build_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from pathlib import Path
from subprocess import check_call

try:
from packaging.version import parse as Version, InvalidVersion
except ImportError: # Should not happen, but at worst in most case this is the same
from pip._vendor.packaging.version import parse as Version, InvalidVersion

DEFAULT_DEST_FOLDER = "./dist"

def create_package(name, dest_folder=DEFAULT_DEST_FOLDER):
Expand All @@ -29,21 +34,27 @@ def travis_build_package():
travis_tag = os.environ.get('TRAVIS_TAG')
if not travis_tag:
print("TRAVIS_TAG environment variable is not present")
return
return "TRAVIS_TAG environment variable is not present"

try:
name, version = travis_tag.split("_")
except ValueError:
print("TRAVIS_TAG is not '<package_name>_<version>' (tag is: {})".format(travis_tag))
return "TRAVIS_TAG is not '<package_name>_<version>' (tag is: {})".format(travis_tag)

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
try:
version = Version(version)
except InvalidVersion:
print("Version must be a valid PEP440 version (version is: {})".format(version))
return "Version must be a valid PEP440 version (version is: {})".format(version)

name, version = matching.groups()
abs_dist_path = Path(os.environ['TRAVIS_BUILD_DIR'], 'dist')
create_package(name, str(abs_dist_path))

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

pattern = "*{}*".format(version)
packages = list(Path('./dist').glob(pattern))
packages = list(abs_dist_path.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")
Expand Down
1 change: 1 addition & 0 deletions scripts/packaging_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cookiecutter
packaging

0 comments on commit 587bc9a

Please sign in to comment.