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