18799: Add Python 3.7 compatibility for TypedDict
[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 distutils.command.build
8 import os
9 import setuptools
10 import sys
11 import re
12
13 from pathlib import Path
14 from setuptools import setup, find_packages
15
16 SETUP_DIR = os.path.dirname(__file__) or '.'
17 README = os.path.join(SETUP_DIR, 'README.rst')
18
19 import arvados_version
20 version = arvados_version.get_version(SETUP_DIR, "arvados")
21
22 short_tests_only = False
23 if '--short-tests-only' in sys.argv:
24     short_tests_only = True
25     sys.argv.remove('--short-tests-only')
26
27 class BuildDiscoveryPydoc(setuptools.Command):
28     """Run discovery2pydoc as part of the build process
29
30     This class implements a setuptools subcommand, so it follows
31     [the SubCommand protocol][1]. Most of these methods are required by that
32     protocol, except `should_run`, which we register as the subcommand
33     predicate.
34
35     [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
36     """
37     NAME = 'discovery2pydoc'
38     description = "build skeleton Python from the Arvados discovery document"
39     editable_mode = False
40     user_options = [
41         ('discovery-json=', 'J', 'JSON discovery document used to build pydoc'),
42         ('discovery-output=', 'O', 'relative path to write discovery document pydoc'),
43     ]
44
45     def initialize_options(self):
46         self.build_lib = None
47         self.discovery_json = 'arvados-v1-discovery.json'
48         self.discovery_output = str(Path('arvados', 'api_resources.py'))
49
50     def _relative_path(self, src, optname):
51         retval = Path(src)
52         if retval.is_absolute():
53             raise Exception(f"--{optname} should be a relative path")
54         else:
55             return retval
56
57     def finalize_options(self):
58         # Set self.build_lib to match whatever the build_py subcommand uses.
59         self.set_undefined_options('build_py', ('build_lib', 'build_lib'))
60         self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
61         self.out_path = Path(
62             self.build_lib,
63             self._relative_path(self.discovery_output, 'discovery-output'),
64         )
65
66     def run(self):
67         import discovery2pydoc
68         self.mkpath(str(self.out_path.parent))
69         arglist = ['--output-file', str(self.out_path), str(self.json_path)]
70         returncode = discovery2pydoc.main(arglist)
71         if returncode != 0:
72             raise Exception(f"discovery2pydoc exited {returncode}")
73
74     def should_run(self):
75         return True
76
77     def get_outputs(self):
78         return [str(self.out_path)]
79
80     def get_source_files(self):
81         return [str(self.json_path)]
82
83     def get_output_mapping(self):
84         return {
85             str(self.json_path): str(self.out_path),
86         }
87 # Run discovery2pydoc as the first subcommand of build.
88 distutils.command.build.build.sub_commands.insert(
89     0, (BuildDiscoveryPydoc.NAME, BuildDiscoveryPydoc.should_run),
90 )
91
92 setup(name='arvados-python-client',
93       version=version,
94       description='Arvados client library',
95       long_description=open(README).read(),
96       author='Arvados',
97       author_email='info@arvados.org',
98       url="https://arvados.org",
99       download_url="https://github.com/arvados/arvados.git",
100       license='Apache 2.0',
101       cmdclass={
102           BuildDiscoveryPydoc.NAME: BuildDiscoveryPydoc,
103       },
104       packages=find_packages(),
105       scripts=[
106           'bin/arv-copy',
107           'bin/arv-get',
108           'bin/arv-keepdocker',
109           'bin/arv-ls',
110           'bin/arv-migrate-docker19',
111           'bin/arv-federation-migrate',
112           'bin/arv-normalize',
113           'bin/arv-put',
114           'bin/arv-ws'
115       ],
116       data_files=[
117           ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
118       ],
119       install_requires=[
120           'ciso8601 >=2.0.0',
121           'future',
122           'google-api-core <2.11.0', # 2.11.0rc1 is incompatible with google-auth<2
123           'google-api-python-client >=2.1.0',
124           'google-auth<2',
125           'httplib2 >=0.9.2, <0.20.2',
126           'pycurl >=7.19.5.1, <7.45.0',
127           'ruamel.yaml >=0.15.54, <0.17.22',
128           'setuptools>=40.3.0',
129           'typing_extensions; python_version<"3.8"',
130           'ws4py >=0.4.2',
131           'protobuf<4.0.0dev',
132           'pyparsing<3',
133       ],
134       classifiers=[
135           'Programming Language :: Python :: 3',
136       ],
137       test_suite='tests',
138       tests_require=['pbr<1.7.0', 'mock>=1.0,<4', 'PyYAML', 'parameterized'],
139       zip_safe=False
140       )