Merge branch 'main' into 21720-material-ui-upgrade
[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 import os
7 import sys
8 import re
9
10 from pathlib import Path
11 from setuptools import setup, find_packages
12 from setuptools.command import build_py
13
14 import arvados_version
15 version = arvados_version.get_version()
16 README = os.path.join(arvados_version.SETUP_DIR, 'README.rst')
17
18 class BuildPython(build_py.build_py):
19     """Extend setuptools `build_py` to generate API documentation
20
21     This class implements a setuptools subcommand, so it follows
22     [the SubCommand protocol][1]. Most of these methods are required by that
23     protocol, except `should_run`, which we register as the subcommand
24     predicate.
25
26     [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
27     """
28     # This is implemented as functionality on top of `build_py`, rather than a
29     # dedicated subcommand, because that's the only way I can find to run this
30     # code during both `build` and `install`. setuptools' `install` command
31     # normally calls specific `build` subcommands directly, rather than calling
32     # the entire command, so it skips custom subcommands.
33     user_options = build_py.build_py.user_options + [
34         ('discovery-json=', 'J', 'JSON discovery document used to build pydoc'),
35         ('discovery-output=', 'O', 'relative path to write discovery document pydoc'),
36     ]
37
38     def initialize_options(self):
39         super().initialize_options()
40         self.discovery_json = 'arvados-v1-discovery.json'
41         self.discovery_output = str(Path('arvados', 'api_resources.py'))
42
43     def _relative_path(self, src, optname):
44         retval = Path(src)
45         if retval.is_absolute():
46             raise Exception(f"--{optname} should be a relative path")
47         else:
48             return retval
49
50     def finalize_options(self):
51         super().finalize_options()
52         self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
53         self.out_path = Path(
54             self.build_lib,
55             self._relative_path(self.discovery_output, 'discovery-output'),
56         )
57
58     def run(self):
59         super().run()
60         import discovery2pydoc
61         arglist = ['--output-file', str(self.out_path), str(self.json_path)]
62         returncode = discovery2pydoc.main(arglist)
63         if returncode != 0:
64             raise Exception(f"discovery2pydoc exited {returncode}")
65
66     def get_outputs(self):
67         retval = super().get_outputs()
68         retval.append(str(self.out_path))
69         return retval
70
71     def get_source_files(self):
72         retval = super().get_source_files()
73         retval.append(str(self.json_path))
74         return retval
75
76     def get_output_mapping(self):
77         retval = super().get_output_mapping()
78         retval[str(self.json_path)] = str(self.out_path)
79         return retval
80
81
82 setup(name='arvados-python-client',
83       version=version,
84       description='Arvados client library',
85       long_description=open(README).read(),
86       author='Arvados',
87       author_email='info@arvados.org',
88       url="https://arvados.org",
89       download_url="https://github.com/arvados/arvados.git",
90       license='Apache 2.0',
91       cmdclass={
92           'build_py': BuildPython,
93       },
94       packages=find_packages(),
95       scripts=[
96           'bin/arv-copy',
97           'bin/arv-get',
98           'bin/arv-keepdocker',
99           'bin/arv-ls',
100           'bin/arv-federation-migrate',
101           'bin/arv-normalize',
102           'bin/arv-put',
103           'bin/arv-ws'
104       ],
105       data_files=[
106           ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
107       ],
108       install_requires=[
109           *arvados_version.iter_dependencies(version),
110           'ciso8601 >=2.0.0',
111           'google-api-python-client >=2.1.0',
112           'google-auth',
113           'httplib2 >=0.9.2',
114           'pycurl >=7.19.5.1',
115           'setuptools >=40.3.0',
116           'websockets >=11.0',
117       ],
118       python_requires="~=3.8",
119       classifiers=[
120           'Programming Language :: Python :: 3',
121       ],
122       test_suite='tests',
123       tests_require=['PyYAML', 'parameterized'],
124       zip_safe=False
125       )