From 18266f843b047531ba4ec5c5ef5cb5f148863a1a Mon Sep 17 00:00:00 2001 From: dfilppi Date: Tue, 26 Dec 2017 21:54:15 +0000 Subject: Updated build to create wheel and push to Pypi Change-Id: I8cb80cf56ed5c0d459a64af8c6a9198c1c4f9fae Issue-ID: SO-362 Signed-off-by: DeWayne Filppi --- aria/aria-rest-server/build.py | 77 +++++++++++++++++++ aria/aria-rest-server/pom.xml | 88 +++++++++++----------- .../src/main/python/aria-rest/setup.py | 1 + 3 files changed, 121 insertions(+), 45 deletions(-) create mode 100644 aria/aria-rest-server/build.py (limited to 'aria') diff --git a/aria/aria-rest-server/build.py b/aria/aria-rest-server/build.py new file mode 100644 index 0000000000..6076c2ffce --- /dev/null +++ b/aria/aria-rest-server/build.py @@ -0,0 +1,77 @@ +import subprocess +import os +import sys +import glob +import xml.etree.ElementTree as etree + +# create and enter venv +def create_venv( name): + if subprocess.call("virtualenv {}".format(name), shell = True): + raise Exception("virtualenv create failed") + ret = subprocess.call(". {}/bin/activate && python {} run". \ + format(name,__file__), shell = True) + sys.exit(ret) + +def init_venv(): + subprocess.call("pip install -U pip", shell = True) + subprocess.call("pip install -U setuptools", shell = True) + subprocess.call("pip install wheel", shell = True) + subprocess.call("pip install twine", shell = True) + + +if len(sys.argv) == 1: + create_venv ("mavenvenv") +else: + init_venv() + + if os.environ['MVN_PHASE'] == 'package': + wheelname = os.environ['WHEEL_NAME'] + inputdir = os.environ['INPUT_DIR'] + outputdir = os.environ['OUTPUT_DIR'] + savedir = os.getcwd() + os.chdir(inputdir) + + if subprocess.call( [ "python", + "setup.py", + "bdist_wheel", + "-d", + outputdir + ]): + sys.stderr("wheel create failed") + sys.exit(1) + f = glob.glob(outputdir+"/*.whl")[0] + os.rename(f , outputdir+"/"+ wheelname) + + elif os.environ['MVN_PHASE'] == 'deploy': + + it = etree.iterparse(os.environ['SETTINGS_FILE']) + for _, el in it: + el.tag = el.tag.split('}', 1)[1] # strip namespace + settings = it.root + + username = settings.find('.//server[id="{}"]/username'.format( + os.environ['PYPI_SERVERID'])).text + password = settings.find('.//server[id="{}"]/password'.format( + os.environ['PYPI_SERVERID'])).text + + try: + if subprocess.call( [ "twine", + "upload", + "--username", + username, + "--password", + password, + "--repository-url", + os.environ["PYPI_SERVER_BASEURL"], + os.environ["WHEEL_PATH"] + ] ): + sys.stderr.write("pypi upload failed") + sys.exit(1) + finally: + subprocess.call("rm -rf mavenvenv", shell = True) + + sys.exit(0) + else: + sys.stderr.write("Unrecognized phase '{}'\n".format( + os.environ('MVN_PHASE'))) + sys.exit(1) diff --git a/aria/aria-rest-server/pom.xml b/aria/aria-rest-server/pom.xml index 7af381c220..cf39f262e9 100644 --- a/aria/aria-rest-server/pom.xml +++ b/aria/aria-rest-server/pom.xml @@ -33,18 +33,13 @@ 1.1.0-SNAPSHOT - - - jitpack.io - https://jitpack.io - - - - 2.7 + 2 UTF-8 - ${project.artifactId}-${python_version}-py2-none-any.whl + ${project.artifactId}-${project.version}-py${python_version}-none-any.whl ${project.basedir}/src/main/python/aria-rest + http://192.168.33.1:8081/repository/pypi-internal/ + ecomp-snapshots @@ -67,48 +62,51 @@ false - - attach-artifacts - package - - attach-artifact - - - - - ${project.build.directory}/maven-python/dist/${wheel.name} - whl - - - - - com.github.UltimateDogg - maven-python-distribute-plugin - 0.2.0 - - ${python_version} - ${python.sourceDirectory} - wheel - + org.codehaus.mojo + exec-maven-plugin + 1.6.0 - package - prepare-package - - package - - - - process - process-sources - - process-sources - + package + package + exec + + python + + ${session.executionRootDirectory}/build.py + + + package + ${wheel.name} + ${session.executionRootDirectory}/src/main/python/aria-rest + ${project.build.directory} + + - + + deploy + deploy + exec + + python + + ${session.executionRootDirectory}/build.py + + + deploy + ${project.version} + ${onap.nexus.dockerregistry.snapshot} + ${onap.nexus.dockerregistry.release} + ${onap.nexus.pypiserver.baseurl} + ${onap.nexus.pypiserver.serverid} + ${project.build.directory}/${wheel.name} + + + + diff --git a/aria/aria-rest-server/src/main/python/aria-rest/setup.py b/aria/aria-rest-server/src/main/python/aria-rest/setup.py index 81beb0f9a7..84e9a19560 100644 --- a/aria/aria-rest-server/src/main/python/aria-rest/setup.py +++ b/aria/aria-rest-server/src/main/python/aria-rest/setup.py @@ -34,6 +34,7 @@ setup( license='LICENSE', description='Aria REST API for ONAP', install_requires=[ + 'distribute', 'Flask==0.12.2', 'flask-autodoc==0.1.2', 'apache-ariatosca==0.1.1' -- cgit 1.2.3-korg