From 0bb0756b805016a74e0669a8e052940800359d47 Mon Sep 17 00:00:00 2001 From: Rahul Gurujala Date: Thu, 8 Aug 2024 20:15:29 +0530 Subject: [PATCH] Added and fixed some bugs --- .flake8 | 15 +++++++++++++++ excel_helper/__init__.py | 5 +++++ excel_helper/excel_helper.py | 7 ++++--- setup.py | 4 ++-- tests/conftest.py | 4 ++++ tests/test_excel_helper.py | 7 ++++++- 6 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 .flake8 create mode 100644 tests/conftest.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6581821 --- /dev/null +++ b/.flake8 @@ -0,0 +1,15 @@ +[flake8] +max-line-length = 120 +extend-ignore = E203, E266, E501, W503 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 +exclude = + .git, + __pycache__, + build, + dist, + venv, + .venv +per-file-ignores = + # imported but unused + __init__.py: F401 \ No newline at end of file diff --git a/excel_helper/__init__.py b/excel_helper/__init__.py index e69de29..d603b6e 100644 --- a/excel_helper/__init__.py +++ b/excel_helper/__init__.py @@ -0,0 +1,5 @@ +from .excel_helper import ExcelHelper + +__all__ = ["ExcelHelper"] + +__version__ = "0.1.0" diff --git a/excel_helper/excel_helper.py b/excel_helper/excel_helper.py index 1b276ee..01af6c0 100644 --- a/excel_helper/excel_helper.py +++ b/excel_helper/excel_helper.py @@ -1,7 +1,8 @@ +from typing import Any, Dict, List + import openpyxl -from openpyxl.utils import get_column_letter from openpyxl.formula.translate import Translator -from typing import List, Dict, Any +from openpyxl.utils import get_column_letter class ExcelHelper: @@ -89,7 +90,7 @@ def auto_fit_columns(self): try: if len(str(cell.value)) > max_length: max_length = len(cell.value) - except: + except Exception: pass adjusted_width = max_length + 2 self.active_sheet.column_dimensions[column_letter].width = adjusted_width diff --git a/setup.py b/setup.py index 68550a5..58ca0c7 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() @@ -29,4 +29,4 @@ install_requires=[ "openpyxl>=3.0.0", ], -) \ No newline at end of file +) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1406b77 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,4 @@ +import os +import sys + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) diff --git a/tests/test_excel_helper.py b/tests/test_excel_helper.py index 7496cb6..c7a7f9c 100644 --- a/tests/test_excel_helper.py +++ b/tests/test_excel_helper.py @@ -1,5 +1,7 @@ -import pytest import os + +import pytest + from excel_helper import ExcelHelper @@ -117,3 +119,6 @@ def test_auto_fit_columns(excel_helper): excel_helper.active_sheet.column_dimensions["A"].width < excel_helper.active_sheet.column_dimensions["B"].width ) + +if __name__ == "__main__": + pytest.main([__file__]) \ No newline at end of file