From 3adb0264373a8c4ba5410399cf332814b68184a7 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Sat, 4 Mar 2017 20:06:56 -0500 Subject: [PATCH] Create lftools cli lftools cli becomes a wrapper for Shell scripts as well as a cli for lftools Python components. Use the 'version' script as a starting point. This patch also: * Initializes automated Shell docs * Improves version script to be callable from lftools cli Change-Id: I21c7997745af0d3852d5b86d928832e7a8486fa4 Signed-off-by: Thanh Ha --- .gitignore | 1 + MANIFEST.in | 1 + docs/index.rst | 5 ++--- docs/shell.rst | 5 +++++ lftools/__init__.py | 0 lftools/cli.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + setup.py | 19 ++++++++++++++-- shell/version | 6 ++++++ 9 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 MANIFEST.in create mode 100644 docs/shell.rst create mode 100644 lftools/__init__.py create mode 100644 lftools/cli.py diff --git a/.gitignore b/.gitignore index 89c04ef1..d366ccc4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ target/ # Python .tox/ __pycache__/ +*.egg-info/ *.pyc docs/_build/ dist/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..f9bd1455 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include requirements.txt diff --git a/docs/index.rst b/docs/index.rst index 7febcc29..814b0f50 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,9 +9,9 @@ Linux Foundation Release Engineering Tools Contents: .. toctree:: - :maxdepth: 2 - + :maxdepth: 2 + shell Indices and tables ================== @@ -19,4 +19,3 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` - diff --git a/docs/shell.rst b/docs/shell.rst new file mode 100644 index 00000000..5330b34d --- /dev/null +++ b/docs/shell.rst @@ -0,0 +1,5 @@ +############## +Shell Commands +############## + +.. autofunction:: lftools.cli.version diff --git a/lftools/__init__.py b/lftools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lftools/cli.py b/lftools/cli.py new file mode 100644 index 00000000..ff1ac7f1 --- /dev/null +++ b/lftools/cli.py @@ -0,0 +1,62 @@ +import click +import subprocess + +@click.group() +@click.pass_context +@click.version_option() +def cli(ctx): + pass + +############################################################################### +# Shell +############################################################################### + +@click.command() +@click.argument('command', type=click.Choice(['bump', 'release'])) +@click.argument('release-tag') +@click.pass_context +def version(ctx, command, release_tag): + """Version bump script for Maven based projects + + Uses *release-tag* to bump versions for Maven projects. + + :arg str command: Version subcommand to call (bump|release) + :arg str release-tag: When used for the 'release' command it is the + tag to use to bump all the versions to. When used for the 'bump' + command it is the tag to determine if a version should be bumped by + x.1.z. + + In general, versions should be: ..[-] + + * Human readable tag should not have any dots in it + * SNAPSHOT is used for development + + Scenarios:: + + master before release: x.y.z-SNAPSHOT (or x.y-SNAPSHOT in which case we treat it as x.y.0-SNAPSHOT) + at release: x.y.z-Helium + stable/helium after release: x.y.(z+1)-SNAPSHOT + master after release: x.(y+1).0-SNAPSHOT + Autorelease on master: is "PreLithium-" + Autorelease on stable/helium: is "PreHeliumSR1-" + Release job on master: is "Lithium" + Release job on stable/helium: is "HeliumSR1" + + Some things have a date for a version, e.g., 2014.09.24.4 + + * We treat this as YYYY.MM.DD. + * Note that all such dates currently in ODL are in YANG tools + * They are all now YYYY.MM.DD.7 since 7 is the minor version for yangtools + + The goal of this script is to: + + #. take all x.y.z-SNAPSHOT to x.y.z-Helium + #. take all x.y.z-Helium versions to x.y.(z+1)-SNAPSHOT and + #. take all x.y.z-SNAPSHOT versions to x.(y+1).0-SNAPSHOT + """ + subprocess.call(['version', command, release_tag]) + +cli.add_command(version) + +if __name__ == '__main__': + cli(obj={}) diff --git a/requirements.txt b/requirements.txt index 76616bd8..80be7391 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +click sphinx>=1.4.9 sphinx_bootstrap_theme>=0.4.14 diff --git a/setup.py b/setup.py index 2ee98dc6..4f225a05 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,12 @@ -from distutils.core import setup +from setuptools import find_packages +from setuptools import setup + +with open('requirements.txt') as f: + install_reqs = f.read().splitlines() setup( name='lftools', - version='0.0.2', + version='0.0.5', author='Thanh Ha', author_email='thanh.ha@linuxfoundation.org', url='', @@ -21,6 +25,17 @@ setup( 'Programming Language :: Python', 'Programming Language :: Python :: 3.5', ], + install_requires=install_reqs, + packages=find_packages(exclude=[ + '*.tests', + '*.tests.*', + 'tests.*', + 'tests' + ]), + entry_points=''' + [console_scripts] + lftools=lftools.cli:cli + ''', scripts=[ 'shell/patch-odl-release', 'shell/version', diff --git a/shell/version b/shell/version index da17ae70..f17a73cc 100755 --- a/shell/version +++ b/shell/version @@ -101,3 +101,9 @@ version_release() { find . -type f -name "$name" -exec perl -i -pe "s/SNAPSHOT/$RELEASE_TAG/g" {} + done } + +# Only run the script if it is being called directly and not sourced. +if [[ "${BASH_SOURCE[0]}" == "${0}" ]] +then + version "$@" +fi -- 2.16.6