From 2f139848f88591db20467c9617fd5d0c69107060 Mon Sep 17 00:00:00 2001 From: chfw Date: Sun, 3 Oct 2021 13:51:26 +0100 Subject: [PATCH] :fire: remove the pinning on xlrd < 2. fix #46 --- .moban.d/custom_README.rst.jj2 | 12 +++++++++++- changelog.yml | 1 + pyexcel-xls.yml | 2 +- pyexcel_xls/__init__.py | 26 ++++++++++++++++++++++---- tests/test_bug_fixes.py | 4 +++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.moban.d/custom_README.rst.jj2 b/.moban.d/custom_README.rst.jj2 index 661d558..700f5c4 100644 --- a/.moban.d/custom_README.rst.jj2 +++ b/.moban.d/custom_README.rst.jj2 @@ -8,6 +8,16 @@ write data in {{file_type}} format and it can read xlsx and xlsm fromat. You are likely to use it with `pyexcel `_. +Update: + +1. v0.6.3 removed the pin on xlrd < 2. If you have xlrd >= 2, this +library will NOT read 'xlsx' format and you need to install pyexcel-xlsx. Othwise, +this library can use xlrd < 2 to read xlsx format for you. So 'xlsx' support +in this library will vary depending on the installed version of xlrd. + +2. 0.6.3 can write datetime.timedelta. but when the value is read out, +you will get datetime.datetime. so you as the developer decides what to do with it. + New flag: `detect_merged_cells` allows you to spread the same value among all merged cells. But be aware that this may slow down its reading performance. @@ -20,7 +30,7 @@ please use pyexcel-xlsx. Warning ================================================================================ -xls file cannot contain more than 65,000 rows. You are risking the reputation +**xls file cannot contain more than 65,000 rows**. You are risking the reputation of yourself/your company/ `your country `_ if you keep using xls and are not aware of its row limit. diff --git a/changelog.yml b/changelog.yml index a755d32..41c68cb 100644 --- a/changelog.yml +++ b/changelog.yml @@ -4,6 +4,7 @@ releases: - changes: - action: Updated details: + - "`#46`: remove the hard pin on xlrd version < 2.0" - "`#47`: limit support to persist datetime.timedelta. see more details in doc" date: tbd version: 0.6.3 diff --git a/pyexcel-xls.yml b/pyexcel-xls.yml index d8dbfef..3130bb8 100644 --- a/pyexcel-xls.yml +++ b/pyexcel-xls.yml @@ -8,7 +8,7 @@ file_type: xls is_on_conda: true dependencies: - pyexcel-io>=0.6.2 - - xlrd<2 + - xlrd - xlwt test_dependencies: - pyexcel diff --git a/pyexcel_xls/__init__.py b/pyexcel_xls/__init__.py index a688b5b..35c2ed7 100644 --- a/pyexcel_xls/__init__.py +++ b/pyexcel_xls/__init__.py @@ -4,9 +4,10 @@ The lower level xls/xlsx/xlsm file format handler using xlrd/xlwt - :copyright: (c) 2016-2020 by Onni Software Ltd + :copyright: (c) 2016-2021 by Onni Software Ltd :license: New BSD License """ +import xlrd # flake8: noqa from pyexcel_io.io import get_data as read_data @@ -19,20 +20,37 @@ from pyexcel_io.plugins import IOPluginInfoChainV2 __FILE_TYPE__ = "xls" + +def xlrd_version_2_or_greater(): + xlrd_version = getattr(xlrd, "__version__") + + if xlrd_version: + major = int(xlrd_version.split(".")[0]) + if major >= 2: + return True + return False + + +XLRD_VERSION_2_OR_ABOVE = xlrd_version_2_or_greater() +supported_file_formats = [__FILE_TYPE__, "xlsx", "xlsm"] +if XLRD_VERSION_2_OR_ABOVE: + supported_file_formats.remove("xlsx") + + IOPluginInfoChainV2(__name__).add_a_reader( relative_plugin_class_path="xlsr.XLSInFile", locations=["file"], - file_types=[__FILE_TYPE__, "xlsx", "xlsm"], + file_types=supported_file_formats, stream_type="binary", ).add_a_reader( relative_plugin_class_path="xlsr.XLSInMemory", locations=["memory"], - file_types=[__FILE_TYPE__, "xlsx", "xlsm"], + file_types=supported_file_formats, stream_type="binary", ).add_a_reader( relative_plugin_class_path="xlsr.XLSInContent", locations=["content"], - file_types=[__FILE_TYPE__, "xlsx", "xlsm"], + file_types=supported_file_formats, stream_type="binary", ).add_a_writer( relative_plugin_class_path="xlsw.XLSWriter", diff --git a/tests/test_bug_fixes.py b/tests/test_bug_fixes.py index f38abfc..85a97dd 100644 --- a/tests/test_bug_fixes.py +++ b/tests/test_bug_fixes.py @@ -10,7 +10,7 @@ from unittest.mock import MagicMock, patch import pyexcel as pe from _compact import OrderedDict -from pyexcel_xls import save_data +from pyexcel_xls import XLRD_VERSION_2_OR_ABOVE, save_data from pyexcel_xls.xlsr import xldate_to_python_date from pyexcel_xls.xlsw import XLSWriter as Writer @@ -97,6 +97,8 @@ def test_issue_20(): def test_issue_151(): + if XLRD_VERSION_2_OR_ABOVE: + raise SkipTest() s = pe.get_sheet( file_name=get_fixture("pyexcel_issue_151.xlsx"), skip_hidden_row_and_column=False,