2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
10 from pathlib import Path
11 from setuptools import setup, find_packages
12 from setuptools.command import build_py
14 import arvados_version
15 version = arvados_version.get_version()
16 short_tests_only = arvados_version.short_tests_only()
17 README = os.path.join(arvados_version.SETUP_DIR, 'README.rst')
19 class BuildPython(build_py.build_py):
20 """Extend setuptools `build_py` to generate API documentation
22 This class implements a setuptools subcommand, so it follows
23 [the SubCommand protocol][1]. Most of these methods are required by that
24 protocol, except `should_run`, which we register as the subcommand
27 [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
29 # This is implemented as functionality on top of `build_py`, rather than a
30 # dedicated subcommand, because that's the only way I can find to run this
31 # code during both `build` and `install`. setuptools' `install` command
32 # normally calls specific `build` subcommands directly, rather than calling
33 # the entire command, so it skips custom subcommands.
34 user_options = build_py.build_py.user_options + [
35 ('discovery-json=', 'J', 'JSON discovery document used to build pydoc'),
36 ('discovery-output=', 'O', 'relative path to write discovery document pydoc'),
39 def initialize_options(self):
40 super().initialize_options()
41 self.discovery_json = 'arvados-v1-discovery.json'
42 self.discovery_output = str(Path('arvados', 'api_resources.py'))
44 def _relative_path(self, src, optname):
46 if retval.is_absolute():
47 raise Exception(f"--{optname} should be a relative path")
51 def finalize_options(self):
52 super().finalize_options()
53 self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
56 self._relative_path(self.discovery_output, 'discovery-output'),
61 import discovery2pydoc
62 arglist = ['--output-file', str(self.out_path), str(self.json_path)]
63 returncode = discovery2pydoc.main(arglist)
65 raise Exception(f"discovery2pydoc exited {returncode}")
67 def get_outputs(self):
68 retval = super().get_outputs()
69 retval.append(str(self.out_path))
72 def get_source_files(self):
73 retval = super().get_source_files()
74 retval.append(str(self.json_path))
77 def get_output_mapping(self):
78 retval = super().get_output_mapping()
79 retval[str(self.json_path)] = str(self.out_path)
83 setup(name='arvados-python-client',
85 description='Arvados client library',
86 long_description=open(README).read(),
88 author_email='info@arvados.org',
89 url="https://arvados.org",
90 download_url="https://github.com/arvados/arvados.git",
93 'build_py': BuildPython,
95 packages=find_packages(),
101 'bin/arv-migrate-docker19',
102 'bin/arv-federation-migrate',
108 ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
111 *arvados_version.iter_dependencies(version),
113 'google-api-python-client >=2.1.0',
117 'setuptools >=40.3.0',
120 python_requires="~=3.8",
122 'Programming Language :: Python :: 3',
125 tests_require=['PyYAML', 'parameterized'],