blob: 92c7898ed9e53321aade4d784908a288e053820b [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# 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 Williams5c2ea232019-01-30 15:23:01 -070015from __future__ import absolute_import
16
Scott Baker96b995a2017-02-15 16:21:12 -080017import os
Zack Williams5c2ea232019-01-30 15:23:01 -070018from shutil import copyfile
19
20from setuptools import setup
Scott Bakerbcbd4cc2018-03-07 13:50:21 -080021from setuptools.command.install import install
22
Scott Bakerbcbd4cc2018-03-07 13:50:21 -080023
Zack Williams5c2ea232019-01-30 15:23:01 -070024def 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
32def 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 Baker96b995a2017-02-15 16:21:12 -080039
Zack Williams045b63d2019-01-22 16:30:57 -070040
Scott Bakerbcbd4cc2018-03-07 13:50:21 -080041class InstallFixChameleonPermissions(install):
Scott Bakerbef5fd92019-02-21 10:24:02 -080042 # Chameleon requires these files have executable permission set,
43 # but setup.py installs them without the execute bit.
Scott Bakerbcbd4cc2018-03-07 13:50:21 -080044 def run(self):
45 install.run(self)
46 for filepath in self.get_outputs():
Zack Williams045b63d2019-01-22 16:30:57 -070047 if filepath.endswith(
Scott Bakerbef5fd92019-02-21 10:24:02 -080048 "chameleon_client/protoc_plugins/gw_gen.py"
49 ):
Zack Williams045b63d2019-01-22 16:30:57 -070050 os.chmod(filepath, 0o777)
Scott Baker96b995a2017-02-15 16:21:12 -080051
Scott Baker96b995a2017-02-15 16:21:12 -080052
Zack Williams045b63d2019-01-22 16:30:57 -070053setup_result = setup(
54 name="xosapi",
Zack Williams5c2ea232019-01-30 15:23:01 -070055 version=version(),
56 classifiers=["License :: OSI Approved :: Apache Software License"],
57 license="Apache v2",
Zack Williams045b63d2019-01-22 16:30:57 -070058 cmdclass={"install": InstallFixChameleonPermissions},
Zack Williams5c2ea232019-01-30 15:23:01 -070059 description="XOS API client",
Zack Williams045b63d2019-01-22 16:30:57 -070060 packages=[
Scott Bakerbef5fd92019-02-21 10:24:02 -080061 "xosapi.chameleon_client",
62 "xosapi.chameleon_client.protos",
63 "xosapi.chameleon_client.protoc_plugins",
Zack Williams045b63d2019-01-22 16:30:57 -070064 "xosapi",
65 "xosapi.convenience",
66 ],
Zack Williams5c2ea232019-01-30 15:23:01 -070067 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 Williams045b63d2019-01-22 16:30:57 -070073 scripts=["xossh"],
74)