21721: Remove pycurl version pin
[arvados.git] / sdk / python / setup.py
index ae8831d623a946e10a809b61dd323377c9d7ece3..a2ec703556ab41e6e6e67bf8d1fb4290f62dfdaf 100644 (file)
@@ -4,28 +4,21 @@
 # SPDX-License-Identifier: Apache-2.0
 
 from __future__ import absolute_import
-import distutils.command.build
 import os
-import setuptools
 import sys
 import re
 
 from pathlib import Path
 from setuptools import setup, find_packages
-
-SETUP_DIR = os.path.dirname(__file__) or '.'
-README = os.path.join(SETUP_DIR, 'README.rst')
+from setuptools.command import build_py
 
 import arvados_version
-version = arvados_version.get_version(SETUP_DIR, "arvados")
-
-short_tests_only = False
-if '--short-tests-only' in sys.argv:
-    short_tests_only = True
-    sys.argv.remove('--short-tests-only')
+version = arvados_version.get_version()
+short_tests_only = arvados_version.short_tests_only()
+README = os.path.join(arvados_version.SETUP_DIR, 'README.rst')
 
-class BuildDiscoveryPydoc(setuptools.Command):
-    """Run discovery2pydoc as part of the build process
+class BuildPython(build_py.build_py):
+    """Extend setuptools `build_py` to generate API documentation
 
     This class implements a setuptools subcommand, so it follows
     [the SubCommand protocol][1]. Most of these methods are required by that
@@ -34,16 +27,18 @@ class BuildDiscoveryPydoc(setuptools.Command):
 
     [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#setuptools.command.build.SubCommand
     """
-    NAME = 'discovery2pydoc'
-    description = "build skeleton Python from the Arvados discovery document"
-    editable_mode = False
-    user_options = [
+    # This is implemented as functionality on top of `build_py`, rather than a
+    # dedicated subcommand, because that's the only way I can find to run this
+    # code during both `build` and `install`. setuptools' `install` command
+    # normally calls specific `build` subcommands directly, rather than calling
+    # the entire command, so it skips custom subcommands.
+    user_options = build_py.build_py.user_options + [
         ('discovery-json=', 'J', 'JSON discovery document used to build pydoc'),
         ('discovery-output=', 'O', 'relative path to write discovery document pydoc'),
     ]
 
     def initialize_options(self):
-        self.build_lib = None
+        super().initialize_options()
         self.discovery_json = 'arvados-v1-discovery.json'
         self.discovery_output = str(Path('arvados', 'api_resources.py'))
 
@@ -55,8 +50,7 @@ class BuildDiscoveryPydoc(setuptools.Command):
             return retval
 
     def finalize_options(self):
-        # Set self.build_lib to match whatever the build_py subcommand uses.
-        self.set_undefined_options('build_py', ('build_lib', 'build_lib'))
+        super().finalize_options()
         self.json_path = self._relative_path(self.discovery_json, 'discovery-json')
         self.out_path = Path(
             self.build_lib,
@@ -64,30 +58,28 @@ class BuildDiscoveryPydoc(setuptools.Command):
         )
 
     def run(self):
+        super().run()
         import discovery2pydoc
-        self.mkpath(str(self.out_path.parent))
         arglist = ['--output-file', str(self.out_path), str(self.json_path)]
         returncode = discovery2pydoc.main(arglist)
         if returncode != 0:
             raise Exception(f"discovery2pydoc exited {returncode}")
 
-    def should_run(self):
-        return True
-
     def get_outputs(self):
-        return [str(self.out_path)]
+        retval = super().get_outputs()
+        retval.append(str(self.out_path))
+        return retval
 
     def get_source_files(self):
-        return [str(self.json_path)]
+        retval = super().get_source_files()
+        retval.append(str(self.json_path))
+        return retval
 
     def get_output_mapping(self):
-        return {
-            str(self.json_path): str(self.out_path),
-        }
-# Run discovery2pydoc as the first subcommand of build.
-distutils.command.build.build.sub_commands.insert(
-    0, (BuildDiscoveryPydoc.NAME, BuildDiscoveryPydoc.should_run),
-)
+        retval = super().get_output_mapping()
+        retval[str(self.json_path)] = str(self.out_path)
+        return retval
+
 
 setup(name='arvados-python-client',
       version=version,
@@ -99,7 +91,7 @@ setup(name='arvados-python-client',
       download_url="https://github.com/arvados/arvados.git",
       license='Apache 2.0',
       cmdclass={
-          BuildDiscoveryPydoc.NAME: BuildDiscoveryPydoc,
+          'build_py': BuildPython,
       },
       packages=find_packages(),
       scripts=[
@@ -117,24 +109,21 @@ setup(name='arvados-python-client',
           ('share/doc/arvados-python-client', ['LICENSE-2.0.txt', 'README.rst']),
       ],
       install_requires=[
+          *arvados_version.iter_dependencies(version),
           'ciso8601 >=2.0.0',
           'future',
-          'google-api-core <2.11.0', # 2.11.0rc1 is incompatible with google-auth<2
           'google-api-python-client >=2.1.0',
-          'google-auth<2',
-          'httplib2 >=0.9.2, <0.20.2',
-          'pycurl >=7.19.5.1, <7.45.0',
-          'ruamel.yaml >=0.15.54, <0.17.22',
-          'setuptools',
-          'ws4py >=0.4.2',
-          'protobuf<4.0.0dev',
-          'pyparsing<3',
-          'setuptools>=40.3.0',
+          'google-auth',
+          'httplib2 >=0.9.2',
+          'pycurl >=7.19.5.1',
+          'setuptools >=40.3.0',
+          'websockets >=11.0',
       ],
+      python_requires="~=3.8",
       classifiers=[
           'Programming Language :: Python :: 3',
       ],
       test_suite='tests',
-      tests_require=['pbr<1.7.0', 'mock>=1.0,<4', 'PyYAML', 'parameterized'],
+      tests_require=['PyYAML', 'parameterized'],
       zip_safe=False
       )