|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +"""The setup script.""" |
| 5 | + |
| 6 | +from setuptools import setup, find_packages |
| 7 | +from setuptools.command.build_py import build_py |
| 8 | +from os import system, environ |
| 9 | +from sys import exit |
| 10 | + |
| 11 | +# find path of pkgs from environment vars |
| 12 | +prefix = '/sonic'; debs = environ["STRETCH_DEBS_PATH"] |
| 13 | +deps_path = '{}/{}'.format(prefix, debs) |
| 14 | +# dependencies |
| 15 | +libyang = '{}/{}'.format(deps_path, environ["LIBYANG"]) |
| 16 | +libyangCpp = '{}/{}'.format(deps_path, environ["LIBYANG_CPP"]) |
| 17 | +libyangPy2 = '{}/{}'.format(deps_path, environ["LIBYANG_PY2"]) |
| 18 | +libyangPy3 = '{}/{}'.format(deps_path, environ["LIBYANG_PY3"]) |
| 19 | + |
| 20 | +# important reuirements parameters |
| 21 | +build_requirements = [libyang, libyangCpp, libyangPy2, libyangPy3,] |
| 22 | + |
| 23 | +setup_requirements = ['pytest-runner'] |
| 24 | + |
| 25 | +test_requirements = ['pytest>=3'] |
| 26 | + |
| 27 | +# read me |
| 28 | +with open('README.rst') as readme_file: |
| 29 | + readme = readme_file.read() |
| 30 | + |
| 31 | +# class for prerequisites to build this package |
| 32 | +class pkgBuild(build_py): |
| 33 | + """Custom Build PLY""" |
| 34 | + |
| 35 | + def run (self): |
| 36 | + # install libyang |
| 37 | + for req in build_requirements: |
| 38 | + if '.deb'in req: |
| 39 | + pkg_install_cmd = "sudo dpkg -i {}".format(req) |
| 40 | + if (system(pkg_install_cmd)): |
| 41 | + print("{} installation failed".format(req)) |
| 42 | + exit(1) |
| 43 | + else: |
| 44 | + print("{} installed".format(req)) |
| 45 | + |
| 46 | + # json file for YANG model test cases. |
| 47 | + test_yangJson_file = './tests/yang_model_tests/yangTest.json' |
| 48 | + # YANG models are in below dir |
| 49 | + yang_model_dir = './yang-models/' |
| 50 | + # yang model tester python module |
| 51 | + yang_test_py = './tests/yang_model_tests/yangModelTesting.py' |
| 52 | + # run tests for yang models |
| 53 | + test_yang_cmd = "python {} -f {} -y {}".format(yang_test_py, test_yangJson_file, yang_model_dir) |
| 54 | + if (system(test_yang_cmd)): |
| 55 | + print("YANG Tests failed\n") |
| 56 | + # below line will be uncommented after libyang python support PR # |
| 57 | + exit(1) |
| 58 | + else: |
| 59 | + print("YANG Tests passed\n") |
| 60 | + |
| 61 | + # Generate YANG Tree |
| 62 | + pyang_tree_cmd = "pyang -f tree ./yang-models/*.yang > ./yang-models/sonic_yang_tree" |
| 63 | + if (system(pyang_tree_cmd)): |
| 64 | + print("Failed: {}".format(pyang_tree_cmd)) |
| 65 | + else: |
| 66 | + print("Passed: {}".format(pyang_tree_cmd)) |
| 67 | + |
| 68 | + # Continue usual build steps |
| 69 | + build_py.run(self) |
| 70 | + |
| 71 | +setup( |
| 72 | + cmdclass={ |
| 73 | + 'build_py': pkgBuild, |
| 74 | + }, |
| 75 | + author="lnos-coders", |
| 76 | + |
| 77 | + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', |
| 78 | + classifiers=[ |
| 79 | + 'Development Status :: 2 - Pre-Alpha', |
| 80 | + 'Intended Audience :: Developers', |
| 81 | + 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', |
| 82 | + 'Natural Language :: English', |
| 83 | + "Programming Language :: Python :: 2", |
| 84 | + 'Programming Language :: Python :: 2.7', |
| 85 | + 'Programming Language :: Python :: 3', |
| 86 | + 'Programming Language :: Python :: 3.5', |
| 87 | + 'Programming Language :: Python :: 3.6', |
| 88 | + 'Programming Language :: Python :: 3.7', |
| 89 | + 'Programming Language :: Python :: 3.8', |
| 90 | + ], |
| 91 | + description="Package contains YANG models for sonic.", |
| 92 | + tests_require = test_requirements, |
| 93 | + license="GNU General Public License v3", |
| 94 | + long_description=readme + '\n\n', |
| 95 | + include_package_data=True, |
| 96 | + keywords='sonic_yang_models', |
| 97 | + name='sonic_yang_models', |
| 98 | + py_modules=[], |
| 99 | + packages=find_packages(), |
| 100 | + setup_requires=setup_requirements, |
| 101 | + version='1.0', |
| 102 | + data_files=[ |
| 103 | + ('yang-models', ['./yang-models/sonic-types.yang', |
| 104 | + './yang-models/sonic-extension.yang', |
| 105 | + './yang-models/sonic-acl.yang', |
| 106 | + './yang-models/sonic-interface.yang', |
| 107 | + './yang-models/sonic-loopback-interface.yang', |
| 108 | + './yang-models/sonic-port.yang', |
| 109 | + './yang-models/sonic-portchannel.yang', |
| 110 | + './yang-models/sonic-vlan.yang', |
| 111 | + './yang-models/sonic_yang_tree']), |
| 112 | + ], |
| 113 | + zip_safe=False, |
| 114 | +) |
0 commit comments