Generation of .py in setup install for IM import as dependency 74/7974/8 feature7928
authorFelipe Vicens <felipe.vicens@atos.net>
Wed, 25 Sep 2019 12:19:33 +0000 (14:19 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 15 Oct 2019 14:50:59 +0000 (16:50 +0200)
Change-Id: Iacc62488a4044f43b94d10e74e9152406c904eb1
Signed-off-by: Felipe Vicens <felipe.vicens@atos.net>
MANIFEST.in [new file with mode: 0644]
setup.py
stdeb.cfg

diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644 (file)
index 0000000..b804618
--- /dev/null
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+# 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.
+
+recursive-include models *.yang
\ No newline at end of file
index cda4c73..ef8da90 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,14 +1,75 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# 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.
+
+import subprocess
+import sys
+import os
 from setuptools import setup, find_packages
+from setuptools.command.install import install
+
+
+class Install_osm_im(install):
+    """Generation of .py files from yang models"""
+    model_dir = "models/yang"
+    im_dir = "osm_im"
+
+    def pipinstall(self, package):
+        """pip install for executable dependencies"""
+        subprocess.call([sys.executable, "-m", "pip", "install", package])
+
+    def run(self):
+        self.pipinstall('pyang')
+        self.pipinstall('pyangbind')
+        import pyangbind
+        print("Creating dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
+        path = "{}/{}".format(os.getcwd(), self.im_dir)
+        if not os.path.exists(path):
+            os.makedirs(path)
+        open("{}/{}/__init__.py".format(os.getcwd(), self.im_dir), 'a').close()
+        for files_item in ['vnfd', 'nsd', 'nst']:
+            protoc_command = ["pyang",
+                              "-Werror",
+                              "--plugindir",
+                              "{}/plugin".format(os.path.dirname(pyangbind.__file__)),
+                              "--path",
+                              self.model_dir,
+                              "-f", "pybind",
+                              "-o",
+                              "{}/{}.py".format(self.im_dir, files_item),
+                              "{}/{}.yang".format(self.model_dir, files_item)]
+            print("Generating {}.py from {}.yang".format(files_item, files_item))
+            if subprocess.call(protoc_command) != 0:
+                sys.exit(-1)
+        # To ensure generated files are copied to the python installation folder
+        self.copy_tree(self.im_dir, "{}{}".format(self.install_lib, self.im_dir))
+        install.run(self)
+
 
 setup(
     name='osm_im',
     description='OSM Information Model',
-    long_description = open('README.rst').read(),
+    long_description=open('README.rst').read(),
     version_command=('git describe --tags --long --dirty --match v*', 'pep440-git-full'),
     author='Mike Marchetti',
     author_email='mmarchetti@sandvine.com',
     packages=find_packages(),
     include_package_data=True,
     setup_requires=['setuptools-version-command'],
+    install_requires=['pyang', 'pyangbind'],
     test_suite='nose.collector',
+    url='https://osm.etsi.org/gitweb/?p=osm/IM.git;a=summary',
+    license='Apache 2.0',
+    cmdclass={'install': Install_osm_im},
 )
index 7b85a12..ec4c256 100644 (file)
--- a/stdeb.cfg
+++ b/stdeb.cfg
@@ -1,5 +1,20 @@
+# -*- coding: utf-8 -*-
+# 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.
+
 [DEFAULT]
 Suite: xenial
+Build-Depends: dh-python
 Maintainer: Gerardo Garcia <gerardo.garciadeblas@telefonica.com>
 Depends: osm-imdocs
 Depends3: osm-imdocs