Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 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 implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 15 | from __future__ import absolute_import |
| 16 | |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 17 | import os |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 18 | from shutil import copyfile |
| 19 | |
| 20 | from setuptools import setup |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 21 | from setuptools.command.install import install |
| 22 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 23 | |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 24 | def version(): |
| 25 | # Copy VERSION file of parent to module directory if not found |
| 26 | if not os.path.exists("xosapi/VERSION"): |
| 27 | copyfile("../../VERSION", "xosapi/VERSION") |
| 28 | with open("xosapi/VERSION") as f: |
| 29 | return f.read().strip() |
| 30 | |
| 31 | |
| 32 | def parse_requirements(filename): |
| 33 | # parse a requirements.txt file, allowing for blank lines and comments |
| 34 | requirements = [] |
| 35 | for line in open(filename): |
| 36 | if line and not line.startswith("#"): |
| 37 | requirements.append(line) |
| 38 | return requirements |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 39 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 40 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 41 | class InstallFixChameleonPermissions(install): |
Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 42 | # Chameleon requires these files have executable permission set, |
| 43 | # but setup.py installs them without the execute bit. |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 44 | def run(self): |
| 45 | install.run(self) |
| 46 | for filepath in self.get_outputs(): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 47 | if filepath.endswith( |
Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 48 | "chameleon_client/protoc_plugins/gw_gen.py" |
| 49 | ): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 50 | os.chmod(filepath, 0o777) |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 51 | |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 52 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 53 | setup_result = setup( |
| 54 | name="xosapi", |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 55 | version=version(), |
| 56 | classifiers=["License :: OSI Approved :: Apache Software License"], |
| 57 | license="Apache v2", |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 58 | cmdclass={"install": InstallFixChameleonPermissions}, |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 59 | description="XOS API client", |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 60 | packages=[ |
Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 61 | "xosapi.chameleon_client", |
| 62 | "xosapi.chameleon_client.protos", |
| 63 | "xosapi.chameleon_client.protoc_plugins", |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 64 | "xosapi", |
| 65 | "xosapi.convenience", |
| 66 | ], |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 67 | install_requires=parse_requirements("requirements.txt"), |
| 68 | include_package_data=True, |
| 69 | package_data={ |
| 70 | "xosapi.chameleon_client.protos": ["*.proto"], |
| 71 | "xosapi.chameleon_client.protoc_plugins": ["*.desc"], |
| 72 | }, |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 73 | scripts=["xossh"], |
| 74 | ) |