blob: ef8da90c5dffe8cde7c72ef89d80532af19c1050 [file] [log] [blame]
Felipe Vicens65a69822019-09-25 14:19:33 +02001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import subprocess
17import sys
18import os
Mike Marchetti94b645e2017-08-04 14:33:54 -040019from setuptools import setup, find_packages
Felipe Vicens65a69822019-09-25 14:19:33 +020020from setuptools.command.install import install
21
22
23class Install_osm_im(install):
24 """Generation of .py files from yang models"""
25 model_dir = "models/yang"
26 im_dir = "osm_im"
27
28 def pipinstall(self, package):
29 """pip install for executable dependencies"""
30 subprocess.call([sys.executable, "-m", "pip", "install", package])
31
32 def run(self):
33 self.pipinstall('pyang')
34 self.pipinstall('pyangbind')
35 import pyangbind
36 print("Creating dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
37 path = "{}/{}".format(os.getcwd(), self.im_dir)
38 if not os.path.exists(path):
39 os.makedirs(path)
40 open("{}/{}/__init__.py".format(os.getcwd(), self.im_dir), 'a').close()
41 for files_item in ['vnfd', 'nsd', 'nst']:
42 protoc_command = ["pyang",
43 "-Werror",
44 "--plugindir",
45 "{}/plugin".format(os.path.dirname(pyangbind.__file__)),
46 "--path",
47 self.model_dir,
48 "-f", "pybind",
49 "-o",
50 "{}/{}.py".format(self.im_dir, files_item),
51 "{}/{}.yang".format(self.model_dir, files_item)]
52 print("Generating {}.py from {}.yang".format(files_item, files_item))
53 if subprocess.call(protoc_command) != 0:
54 sys.exit(-1)
55 # To ensure generated files are copied to the python installation folder
56 self.copy_tree(self.im_dir, "{}{}".format(self.install_lib, self.im_dir))
57 install.run(self)
58
Mike Marchetti94b645e2017-08-04 14:33:54 -040059
60setup(
61 name='osm_im',
garciadeblas825b76d2017-08-30 15:03:32 +020062 description='OSM Information Model',
Felipe Vicens65a69822019-09-25 14:19:33 +020063 long_description=open('README.rst').read(),
Mike Marchetti09a27102018-09-24 15:05:51 -040064 version_command=('git describe --tags --long --dirty --match v*', 'pep440-git-full'),
Mike Marchetti94b645e2017-08-04 14:33:54 -040065 author='Mike Marchetti',
66 author_email='mmarchetti@sandvine.com',
67 packages=find_packages(),
68 include_package_data=True,
Mike Marchetti94b645e2017-08-04 14:33:54 -040069 setup_requires=['setuptools-version-command'],
Felipe Vicens65a69822019-09-25 14:19:33 +020070 install_requires=['pyang', 'pyangbind'],
Mike Marchetti94b645e2017-08-04 14:33:54 -040071 test_suite='nose.collector',
Felipe Vicens65a69822019-09-25 14:19:33 +020072 url='https://osm.etsi.org/gitweb/?p=osm/IM.git;a=summary',
73 license='Apache 2.0',
74 cmdclass={'install': Install_osm_im},
Mike Marchetti94b645e2017-08-04 14:33:54 -040075)