From 7d6eb2dde37a53b421cda71709422574eadc8874 Mon Sep 17 00:00:00 2001 From: lihsai0 Date: Mon, 21 Aug 2023 15:26:51 +0800 Subject: [PATCH] fix setup lost some packages by find_packages (#438) * fix setup lost some packages by find_packages * tweak test cases to test with other buckets --- CHANGELOG.md | 3 +++ qiniu/__init__.py | 2 +- setup.py | 21 ++------------------- test_qiniu.py | 44 ++++++++++++++++++++++---------------------- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2651d981..53ed46a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 7.11.1(2023-08-16) +* 修复 setup.py 打包丢失部分包(v7.11.0 引入) + ## 7.11.0(2023-03-28) * 对象存储,更新 api 默认域名 * 对象存储,新增 api 域名的配置与获取 diff --git a/qiniu/__init__.py b/qiniu/__init__.py index 778a0454..a0a26b77 100644 --- a/qiniu/__init__.py +++ b/qiniu/__init__.py @@ -9,7 +9,7 @@ # flake8: noqa -__version__ = '7.11.0' +__version__ = '7.11.1' from .auth import Auth, QiniuMacAuth diff --git a/setup.py b/setup.py index 34badc36..e7e37cce 100644 --- a/setup.py +++ b/setup.py @@ -5,24 +5,7 @@ import os import re -try: - import setuptools - - setup = setuptools.setup -except ImportError: - setuptools = None - from distutils.core import setup - -packages = [ - 'qiniu', - 'qiniu.services', - 'qiniu.services.storage', - 'qiniu.services.processing', - 'qiniu.services.compute', - 'qiniu.services.cdn', - 'qiniu.services.sms', - 'qiniu.services.pili', -] +from setuptools import setup, find_packages def read(*names, **kwargs): @@ -52,7 +35,7 @@ def find_version(*file_paths): license='MIT', url='https://github.com/qiniu/python-sdk', platforms='any', - packages=packages, + packages=find_packages(), classifiers=[ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', diff --git a/test_qiniu.py b/test_qiniu.py index 151b861a..25e5f8bb 100644 --- a/test_qiniu.py +++ b/test_qiniu.py @@ -17,7 +17,7 @@ build_batch_delete, DomainManager from qiniu import urlsafe_base64_encode, urlsafe_base64_decode, canonical_mime_header_key -from qiniu.compat import is_py2, is_py3, b +from qiniu.compat import is_py2, is_py3, b, json from qiniu.services.storage.uploader import _form_put @@ -414,7 +414,7 @@ def test_list(self): assert len(ret.get('items')) == 4 ret, eof, info = self.bucket.list(bucket_name, limit=1000) print(ret, eof, info) - assert eof is False + assert info.status_code == 200 def test_buckets(self): ret, info = self.bucket.buckets() @@ -699,14 +699,26 @@ def test_putWithoutKey(self): assert info.status_code == 403 # key not match def test_withoutRead_withoutSeek_retry(self): - key = 'retry' - data = 'hello retry!' - set_default(default_zone=Zone('http://a', 'https://upload.qiniup.com')) - token = self.q.upload_token(bucket_name) - ret, info = put_data(token, key, data) - print(info) - assert ret['key'] == key - assert ret['hash'] == 'FlYu0iBR1WpvYi4whKXiBuQpyLLk' + try: + key = 'retry' + data = 'hello retry!' + zone = Zone() + try: + hosts = json.loads( + zone.bucket_hosts(access_key, bucket_name) + ).get('hosts') + up_host_backup = 'https://' + hosts[0].get('up', {}).get('domains')[0] + except IndexError: + up_host_backup = 'https://upload.qiniup.com' + set_default(default_zone=Zone('http://a', up_host_backup)) + token = self.q.upload_token(bucket_name) + ret, info = put_data(token, key, data) + print(info) + assert ret['key'] == key + assert ret['hash'] == 'FlYu0iBR1WpvYi4whKXiBuQpyLLk' + finally: + set_default(default_zone=Zone()) + qiniu.config._is_customized_default['default_zone'] = False def test_putData_without_fname(self): if is_travis(): @@ -780,7 +792,6 @@ def test_put_stream(self): localfile = __file__ key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(__file__), size, hostscache_dir, @@ -792,7 +803,6 @@ def test_put_stream_v2_without_bucket_name(self): localfile = __file__ key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(__file__), size, hostscache_dir, @@ -804,7 +814,6 @@ def test_put_2m_stream_v2(self): localfile = create_temp_file(2 * 1024 * 1024 + 1) key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir, @@ -817,7 +826,6 @@ def test_put_4m_stream_v2(self): localfile = create_temp_file(4 * 1024 * 1024) key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir, @@ -830,7 +838,6 @@ def test_put_10m_stream_v2(self): localfile = create_temp_file(10 * 1024 * 1024 + 1) key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir, @@ -844,7 +851,6 @@ def test_put_stream_v2_without_key(self): localfile = create_temp_file(part_size + 1) key = None size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir, @@ -858,7 +864,6 @@ def test_put_stream_v2_with_empty_return_body(self): localfile = create_temp_file(part_size + 1) key = 'test_file_empty_return_body' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key, policy={'returnBody': ' '}) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir, @@ -873,7 +878,6 @@ def test_big_file(self): token = self.q.upload_token(bucket_name, key) localfile = create_temp_file(4 * 1024 * 1024 + 1) progress_handler = lambda progress, total: progress - qiniu.set_default(default_zone=Zone('http://a', 'https://upload.qiniup.com')) ret, info = put_file(token, key, localfile, self.params, self.mime_type, progress_handler=progress_handler) print(info) assert ret['key'] == key @@ -882,7 +886,6 @@ def test_big_file(self): def test_retry(self): localfile = __file__ key = 'test_file_r_retry' - qiniu.set_default(default_zone=Zone('http://a', 'https://upload.qiniup.com')) token = self.q.upload_token(bucket_name, key) ret, info = put_file(token, key, localfile, self.params, self.mime_type) print(info) @@ -893,7 +896,6 @@ def test_put_stream_with_key_limits(self): localfile = __file__ key = 'test_file_r' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key, policy={'keylimit': ['test_file_d']}) ret, info = put_stream(token, key, input_stream, os.path.basename(__file__), size, hostscache_dir, @@ -910,7 +912,6 @@ def test_put_stream_with_metadata(self): localfile = __file__ key = 'test_put_stream_with_metadata' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(__file__), size, hostscache_dir, @@ -927,7 +928,6 @@ def test_put_stream_v2_with_metadata(self): localfile = create_temp_file(part_size + 1) key = 'test_put_stream_v2_with_metadata' size = os.stat(localfile).st_size - set_default(default_zone=Zone('https://upload.qiniup.com')) with open(localfile, 'rb') as input_stream: token = self.q.upload_token(bucket_name, key) ret, info = put_stream(token, key, input_stream, os.path.basename(localfile), size, hostscache_dir,