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 README = os.path.join(arvados_version.SETUP_DIR, 'README.rst')
18 class BuildPython(build_py.build_py):
19 """Extend setuptools `build_py` to generate API documentation
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
26 [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
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'),
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'))
43 def _relative_path(self, src, optname):
45 if retval.is_absolute():
46 raise Exception(f"--{optname} should be a relative path")
50 def finalize_options(self):
51 super().finalize_options()
52 self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
55 self._relative_path(self.discovery_output, 'discovery-output'),
60 import discovery2pydoc
61 arglist = ['--output-file', str(self.out_path), str(self.json_path)]
62 returncode = discovery2pydoc.main(arglist)
64 raise Exception(f"discovery2pydoc exited {returncode}")
66 def get_outputs(self):
67 retval = super().get_outputs()
68 retval.append(str(self.out_path))
71 def get_source_files(self):
72 retval = super().get_source_files()
73 retval.append(str(self.json_path))
76 def get_output_mapping(self):
77 retval = super().get_output_mapping()
78 retval[str(self.json_path)] = str(self.out_path)
82 setup(name='arvados-python-client',
84 description='Arvados client library',
85 long_description=open(README).read(),
87 author_email='info@arvados.org',
88 url="https://arvados.org",
89 download_url="https://github.com/arvados/arvados.git",
92 'build_py': BuildPython,
94 packages=find_packages(),
100 'bin/arv-migrate-docker19',
101 'bin/arv-federation-migrate',
107 ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
110 *arvados_version.iter_dependencies(version),
112 'google-api-python-client >=2.1.0',
116 'setuptools >=40.3.0',
119 python_requires="~=3.8",
121 'Programming Language :: Python :: 3',
124 tests_require=['PyYAML', 'parameterized'],