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