21132: Expand arvados.api_resources docstring with more detail about its purpose
[arvados.git] / sdk / python / setup.py
1 #!/usr/bin/env python3
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 from __future__ import absolute_import
7 import os
8 import sys
9 import re
10
11 from pathlib import Path
12 from setuptools import setup, find_packages
13 from setuptools.command import build_py
14
15 SETUP_DIR = os.path.dirname(__file__) or '.'
16 README = os.path.join(SETUP_DIR, 'README.rst')
17
18 import arvados_version
19 version = arvados_version.get_version(SETUP_DIR, "arvados")
20
21 short_tests_only = False
22 if '--short-tests-only' in sys.argv:
23     short_tests_only = True
24     sys.argv.remove('--short-tests-only')
25
26 class BuildPython(build_py.build_py):
27     """Extend setuptools `build_py` to generate API documentation
28
29     This class implements a setuptools subcommand, so it follows
30     [the SubCommand protocol][1]. Most of these methods are required by that
31     protocol, except `should_run`, which we register as the subcommand
32     predicate.
33
34     [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
35     """
36     # This is implemented as functionality on top of `build_py`, rather than a
37     # dedicated subcommand, because that's the only way I can find to run this
38     # code during both `build` and `install`. setuptools' `install` command
39     # normally calls specific `build` subcommands directly, rather than calling
40     # the entire command, so it skips custom subcommands.
41     user_options = build_py.build_py.user_options + [
42         ('discovery-json=', 'J', 'JSON discovery document used to build pydoc'),
43         ('discovery-output=', 'O', 'relative path to write discovery document pydoc'),
44     ]
45
46     def initialize_options(self):
47         super().initialize_options()
48         self.discovery_json = 'arvados-v1-discovery.json'
49         self.discovery_output = str(Path('arvados', 'api_resources.py'))
50
51     def _relative_path(self, src, optname):
52         retval = Path(src)
53         if retval.is_absolute():
54             raise Exception(f"--{optname} should be a relative path")
55         else:
56             return retval
57
58     def finalize_options(self):
59         super().finalize_options()
60         self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
61         self.out_path = Path(
62             self.build_lib,
63             self._relative_path(self.discovery_output, 'discovery-output'),
64         )
65
66     def run(self):
67         super().run()
68         import discovery2pydoc
69         arglist = ['--output-file', str(self.out_path), str(self.json_path)]
70         returncode = discovery2pydoc.main(arglist)
71         if returncode != 0:
72             raise Exception(f"discovery2pydoc exited {returncode}")
73
74     def get_outputs(self):
75         retval = super().get_outputs()
76         retval.append(str(self.out_path))
77         return retval
78
79     def get_source_files(self):
80         retval = super().get_source_files()
81         retval.append(str(self.json_path))
82         return retval
83
84     def get_output_mapping(self):
85         retval = super().get_output_mapping()
86         retval[str(self.json_path)] = str(self.out_path)
87         return retval
88
89
90 setup(name='arvados-python-client',
91       version=version,
92       description='Arvados client library',
93       long_description=open(README).read(),
94       author='Arvados',
95       author_email='info@arvados.org',
96       url="https://arvados.org",
97       download_url="https://github.com/arvados/arvados.git",
98       license='Apache 2.0',
99       cmdclass={
100           'build_py': BuildPython,
101       },
102       packages=find_packages(),
103       scripts=[
104           'bin/arv-copy',
105           'bin/arv-get',
106           'bin/arv-keepdocker',
107           'bin/arv-ls',
108           'bin/arv-migrate-docker19',
109           'bin/arv-federation-migrate',
110           'bin/arv-normalize',
111           'bin/arv-put',
112           'bin/arv-ws'
113       ],
114       data_files=[
115           ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
116       ],
117       install_requires=[
118           'ciso8601 >=2.0.0',
119           'future',
120           'google-api-core <2.11.0', # 2.11.0rc1 is incompatible with google-auth<2
121           'google-api-python-client >=2.1.0',
122           'google-auth <2',
123           'httplib2 >=0.9.2, <0.20.2',
124           'pycurl >=7.19.5.1, <7.45.0',
125           'ruamel.yaml >=0.15.54, <0.17.22',
126           'setuptools >=40.3.0',
127           # As of 4.8.0rc1, typing_extensions does not parse in Python 3.7
128           'typing_extensions >=3.7.4, <4.8; python_version<"3.8"',
129           'ws4py >=0.4.2',
130           'protobuf <4.0.0dev',
131           'pyparsing <3',
132           'setuptools >=40.3.0',
133           'dataclasses; python_version<"3.7"',
134       ],
135       classifiers=[
136           'Programming Language :: Python :: 3',
137       ],
138       test_suite='tests',
139       tests_require=['pbr<1.7.0', 'mock>=1.0,<4', 'PyYAML', 'parameterized'],
140       zip_safe=False
141       )