diff --git a/autorelease-travis.yml b/autorelease-travis.yml index 850d67f..82e897f 100644 --- a/autorelease-travis.yml +++ b/autorelease-travis.yml @@ -1,6 +1,6 @@ -# AUTORELEASE v0.0.17 +# AUTORELEASE v0.0.18 import: - - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.0.17 - - dwhswenson/autorelease:travis_stages/cut_release.yml@v0.0.17 - - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.0.17 - - dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.0.17 + - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.0.18 + - dwhswenson/autorelease:travis_stages/cut_release.yml@v0.0.18 + - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.0.18 + - dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.0.18 diff --git a/autorelease/scripts/bump_dev_version.py b/autorelease/scripts/bump_dev_version.py index 4cf25a0..da22e59 100644 --- a/autorelease/scripts/bump_dev_version.py +++ b/autorelease/scripts/bump_dev_version.py @@ -1,4 +1,5 @@ import argparse +import time try: from configparser import ConfigParser, NoSectionError, NoOptionError except ImportError: @@ -11,8 +12,8 @@ def get_latest_pypi(package, index="https://test.pypi.org/pypi"): url = "/".join([index, package, 'json']) req = requests.get(url) - version = req.json()['info']['version'] - return version + version = max([Version(v) for v in req.json()['releases'].keys()]) + return str(version) def _strip_dev(version_str): version = Version(version_str) # to normalize @@ -39,31 +40,76 @@ def select_version(v_pypi, v_setup): else: raise RuntimeError("Why does pypi have a newer version than setup?") -def make_parser(): +def shared_parser(): parser = argparse.ArgumentParser() parser.add_argument("-i", "--index", type=str, default="https://test.pypi.org/pypi", help="pypi index to search for versions") parser.add_argument("-c", "--conf", type=str, default="setup.cfg", help="setup.cfg file to use") - parser.add_argument("-o", "--output", type=str, - help="output file; defaults to same as input") + return parser + parser.add_argument('--get-max', action='store_true') return parser -def main(): - parser = make_parser() - opts = parser.parse_args() - output = opts.conf if opts.output is None else opts.output +def get_version_info(conf_name, index): conf = ConfigParser() - conf.read(opts.conf) + conf.read(conf_name) v_setup = conf.get('metadata', 'version') package = conf.get('metadata', 'name') - v_pypi = get_latest_pypi(package, opts.index) + v_pypi = get_latest_pypi(package, index) + return conf, package, v_setup, v_pypi + +def wait_for_max(): + parser = shared_parser() + opts = parser.parse_args() + + found_desired = False + while not found_desired: + _, package, v_setup, v_pypi = get_version_info(opts.conf, + opts.index) + print("Looking for version with base : %s" % v_setup) + print("Maximum version on index: %s" % v_pypi) + vv_setup = Version(v_setup) + vv_pypi = Version(v_pypi) + if vv_setup.base_version > vv_pypi.base_version: + print("Waiting 5 seconds to see if package registers") + time.sleep(5) + elif vv_setup.base_version < vv_pypi.base_version: + raise RuntimeError("Why is this version less than the index?") + else: # we are equal + found_desired = True + + +def get_max(): + parser = argparse.ArgumentParser() + parser.add_argument("package", type=str) + parser.add_argument("-i", "--index", type=str, + default="https://test.pypi.org/pypi", + help="pypi index to search for versions") + opts = parser.parse_args() + print(get_latest_pypi(opts.package, opts.index)) + + +def main(): + parser = shared_parser() + parser.add_argument("-o", "--output", type=str, + help="output file; defaults to same as input") + parser.add_argument('--dry', action='store_true') + opts = parser.parse_args() + output = opts.conf if opts.output is None else opts.output + + conf, package, v_setup, v_pypi = get_version_info(opts.conf, opts.index) version_to_bump = select_version(v_pypi, v_setup) new_version = bump_dev_version(version_to_bump) - conf.set('metadata', 'version', new_version) - with open(output, 'w') as f: - conf.write(f) + + print("Local version: ", v_setup) + print("Remote version: ", v_pypi) + print("Bumped version: ", new_version) + + if not opts.dry: + conf.set('metadata', 'version', new_version) + with open(output, 'w') as f: + conf.write(f) if __name__ == "__main__": main() diff --git a/autorelease/shell/wait-for-testpypi b/autorelease/shell/wait-for-testpypi deleted file mode 100755 index b822ea5..0000000 --- a/autorelease/shell/wait-for-testpypi +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Usage: takes setup.py as input (NOT setup.cfg!) - -SETUP_PY=$1 - -VERSION=`python $SETUP_PY --version` -PROJECT=`python $SETUP_PY --name` - -echo "Searching test.pypi for $VERSION" - -MISSING_VERSION=true -while $MISSING_VERSION; do - pip_results=`pip search -i https://test.pypi.org/pypi $PROJECT` - pip search -i https://test.pypi.org/pypi $PROJECT - #echo $pip_results - grepped=`echo $pip_results | grep $PROJECT` - #echo "Grepped:" $grepped - if [ -n "$grepped" ]; then - MISSING_VERSION=false - else - echo "Looking for $PROJECT $VERSION" - echo "Found: $grepped ..." - echo "Waiting 5 seconds for the version to register" - sleep 5 - fi -done diff --git a/autorelease/tests/test_bump_dev_version.py b/autorelease/tests/test_bump_dev_version.py index b744a6b..4ecfd5f 100644 --- a/autorelease/tests/test_bump_dev_version.py +++ b/autorelease/tests/test_bump_dev_version.py @@ -1,12 +1,12 @@ import pytest from autorelease.scripts.bump_dev_version import * -def test_make_parser(): - parser = make_parser() +def test_shared_parser(): + parser = shared_parser() opts = parser.parse_args([]) assert opts.index == "https://test.pypi.org/pypi" assert opts.conf == "setup.cfg" - assert opts.output is None + # assert opts.output is None @pytest.mark.parametrize("v_pypi, v_setup, expected", [ ("1.0", "1.1", "1.1"), diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index 25b0d62..7c43371 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -1,7 +1,7 @@ package: name: autorelease # add ".dev0" for unreleased versions - version: "0.0.17" + version: "0.0.18" source: path: ../../ @@ -42,5 +42,5 @@ test: about: home: https://github.com/dwhswenson/autorelease - license: LGPL-2.1 or later + license: MIT summary: "Check the version and branches in release cycle" diff --git a/setup.cfg b/setup.cfg index 63de6be..63c9c7a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,13 @@ [metadata] name = autorelease -version = 0.0.17 +version = 0.0.18 # version should end in .dev0 if this isn't to be released short_description = Tools to keep the release process clean. description = Tools to keep the release process clean. long_description = file: README.md long_description_content_type = text/markdown +author = David W.H. Swenson +author_email = dwhs@hyperblazer.net license = MIT url = https://github.com/dwhswenson/autorelease classifiers = @@ -34,14 +36,14 @@ install_requires = requests python-dateutil packages = find: -scripts = - autorelease/shell/wait-for-testpypi [options.entry_points] console_scripts = autorelease-release = autorelease.scripts.release:main write-release-notes = autorelease.scripts.write_release_notes:main bump-dev-version = autorelease.scripts.bump_dev_version:main + pypi-max-version = autorelease.scripts.bump_dev_version:get_max + wait-for-testpypi = autorelease.scripts.bump_dev_version:wait_for_max [bdist_wheel] universal=1 diff --git a/travis_stages/deploy_testpypi.yml b/travis_stages/deploy_testpypi.yml index d9dc638..f52e3b5 100644 --- a/travis_stages/deploy_testpypi.yml +++ b/travis_stages/deploy_testpypi.yml @@ -5,10 +5,14 @@ jobs: # deployment to testpypi works. if: "(branch = stable) and (type = pull_request)" install: - - pip install twine #autorelease + - pip install twine + #- pip install autorelease + # this is for debugging anything in autorelease used here (change + # the branch tag to whatever is needed) + - pip install git+https://github.com/dwhswenson/autorelease.git@release-0.0.18#egg=autorelease - hash -r script: - #- bump-dev-version # comes from autorelease + - bump-dev-version # comes from autorelease - python setup.py --version - python setup.py sdist bdist_wheel - twine check dist/* diff --git a/travis_stages/test_testpypi.yml b/travis_stages/test_testpypi.yml index 4afe417..13258e5 100644 --- a/travis_stages/test_testpypi.yml +++ b/travis_stages/test_testpypi.yml @@ -7,10 +7,15 @@ jobs: if: "(branch = stable) and (type = pull_request)" install: #- pip install autorelease + # this is for debugging anything in autorelease used here (change + # the branch tag to whatever is needed) + - pip install git+https://github.com/dwhswenson/autorelease.git@release-0.0.18#egg=autorelease - hash -r - #- wait-for-testpypi setup.py + - wait-for-testpypi - export PROJECT=`python setup.py --name` - - pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple $PROJECT + - export VERSION=`pypi-max-version $PROJECT` + - echo "Installing ${PROJECT}==${VERSION} (allowing pre-releases)" + - pip install --pre --force-reinstall --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ${PROJECT}==${VERSION} script: | if [ -n "$AUTORELEASE_TEST_TESTPYPI" ]; then eval $AUTORELEASE_TEST_TESTPYPI