[SEBA-946]
Fix Swagger documentation generation, update to Python 3
Change-Id: I0a55c4805a993dcac9f0721be87bbefbf8b9b348
diff --git a/docs/.gitignore b/docs/.gitignore
index d1adcde..e67364c 100644
--- a/docs/.gitignore
+++ b/docs/.gitignore
@@ -1,2 +1,2 @@
_book/
-venv-xosdocs
+venv_xosdocs
diff --git a/docs/Makefile b/docs/Makefile
index 86248c0..8888328 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -49,11 +49,15 @@
swagger: swagger_clean swagger_docs swagger_serve_spec
-venv-xosdocs:
- ./venv-xosdocs.sh
+venv_xosdocs:
+ virtualenv -p python3 $@ ;\
+ source ./$@/bin/activate ;\
+ pip install --upgrade pip ;\
+ pip install -e ../lib/xos-genx
-swagger_docs: venv-xosdocs
- bash -c 'source $(DOCSDIR)venv-xosdocs/bin/activate && python $(DOCSDIR)scripts/swagger_docs.py'
+swagger_docs: venv_xosdocs
+ source ./$</bin/activate ; set -u ;\
+ python $(DOCSDIR)scripts/swagger_docs.py
swagger_clean:
rm -rf swagger/specs/*
diff --git a/docs/scripts/swagger_docs.py b/docs/scripts/swagger_docs.py
index 7a01bc7..f22d1c2 100644
--- a/docs/scripts/swagger_docs.py
+++ b/docs/scripts/swagger_docs.py
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
import os
import traceback
from xosgenx.generator import XOSProcessor, XOSProcessorArgs
@@ -23,13 +25,14 @@
class Args:
pass
+
def generate_swagger_docs(xproto):
# if not os.path.isfile(xproto):
# print "ERROR: Couldn't find xproto file for %s at: %s" % (service, xproto)
# return
- print "Generating swagger docs for %s" % (xproto)
+ print("Generating swagger docs for %s" % (xproto))
args = XOSProcessorArgs()
args.files = xproto
args.target = 'swagger.xtarget'
@@ -40,9 +43,10 @@
try:
XOSProcessor.process(args)
except Exception:
- print "ERROR: Couldn't generate swagger specs"
+ print("ERROR: Couldn't generate swagger specs")
traceback.print_exc()
+
def get_xproto_recursively(root):
files = []
items = os.listdir(root)
@@ -63,9 +67,7 @@
elif os.path.isfile(item_abs_path) and ".xproto" in item_abs_path:
files.append(item_abs_path)
- protos = [f for f in files if "xproto" in f]
-
- protos = sorted(protos)
+ protos = sorted([f for f in files if "xproto" in f])
# remove the core xproto...
core_proto = None
@@ -81,12 +83,6 @@
return protos
-def main():
-
- protos = get_xproto_recursively(REPO_DIR)
-
- generate_swagger_docs(protos)
-
-
if __name__ == '__main__':
- main()
+ protos = get_xproto_recursively(REPO_DIR)
+ generate_swagger_docs(protos)
diff --git a/docs/venv-xosdocs.sh b/docs/venv-xosdocs.sh
deleted file mode 100755
index ca51fef..0000000
--- a/docs/venv-xosdocs.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-set -e -o pipefail
-
-BASEDIR=$(pwd)
-VENVDIR=venv-xosdocs
-
-# create venv if it's not yet there
-if [ ! -d "$BASEDIR/$VENVDIR" ]; then
- echo "Setting up virtualenv for XOS Swagger Docs"
- virtualenv -q $BASEDIR/$VENVDIR --no-site-packages
- source $BASEDIR/$VENVDIR/bin/activate
- pip install --upgrade pip
- echo "Virtualenv created."
-fi
-
-# activate the virtual env
-if [ ! $VIRTUAL_ENV ]; then
- source $BASEDIR/$VENVDIR/bin/activate
- echo "Virtualenv activated."
-fi
-
-# install pip packages
-pip install -e $BASEDIR/$VENVDIR/../../lib/xos-genx