diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index 989d6cf..8893b64 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.12" + python-version: "3.13" - name: Install build tools run: | diff --git a/.gitignore b/.gitignore index f905dc0..26747ab 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pip-selfcheck.json /.cache/ dist/ +.idea/ diff --git a/HISTORY.txt b/HISTORY.txt index 87aea06..58337fb 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,6 +1,13 @@ Changelog ========= +1.4.1.post0+tes +------------------ + +- Migrated build system to PEP 517/621. +- Added pyproject.toml with modern metadata. +- Declared dynamic readme using setuptools to combine README.rst and HISTORY.txt. +- Removed legacy setup.py-based build path to avoid deprecation warnings. 1.4.1 (unreleased) ------------------ diff --git a/README.rst b/README.rst index 6ba0d20..5f82ea0 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,7 @@ *docxcompose* is a Python library for concatenating/appending Microsoft Word (.docx) files. +This fork fixes the DeprecationWarning on pkg_import, and modernizes the build system. Example usage ------------- diff --git a/docxcompose/properties.py b/docxcompose/properties.py index aa8cd2d..51f2ac0 100644 --- a/docxcompose/properties.py +++ b/docxcompose/properties.py @@ -15,7 +15,7 @@ from lxml.etree import QName from six import binary_type from six import text_type -import pkg_resources +import importlib.resources as importlib_resources import re @@ -108,8 +108,8 @@ def __init__(self, doc): self._element = parse_xml(part.blob) def _part_template(self): - return pkg_resources.resource_string( - 'docxcompose', 'templates/custom.xml') + ref = importlib_resources.files('docxcompose').joinpath('templates/custom.xml') + return ref.read_bytes() def _update_part(self): if self.part is None: diff --git a/pyproject.toml b/pyproject.toml index 4899954..ae24e9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,11 +4,17 @@ build-backend = "setuptools.build_meta" [project] name = "docxcompose_tes" -authors = [{ name="Telengsol", email="devops+test-pypi@telengsol.com" }] description = "Python library for concatenating/appending Microsoft Word (.docx) files." readme = "README.rst" license = {text = "MIT"} -dependencies = [] +requires-python = ">=3.13" +dependencies = [ + 'lxml', + 'python-docx >= 1.2.0', + 'six', + 'babel', +] + # Only version is dynamic dynamic = ["version"] @@ -33,3 +39,6 @@ tests = ["pytest"] version_scheme = "guess-next-dev" local_scheme = "node-and-date" +# declare readme dynamically via setuptools +[tool.setuptools.dynamic] +readme = { file = ["README.rst", "HISTORY.txt"], content-type = "text/x-rst" } diff --git a/setup.py b/setup.py deleted file mode 100644 index 1d7d53c..0000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -"""Installer for the docxcompose package.""" - -from setuptools import find_packages -from setuptools import setup - - -tests_require = [ - 'pytest', -] - -setup( - name='docxcompose', - version='1.4.1.dev0', - description="Compose .docx documents", - long_description=(open("README.rst").read() + "\n" + - open("HISTORY.txt").read()), - # Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - "License :: OSI Approved :: MIT License", - ], - keywords='Python DOCX Word OOXML', - author='Thomas Buchberger', - author_email='t.buchberger@4teamwork.ch', - url='https://github.com/4teamwork/docxcompose', - license='MIT license', - packages=find_packages(exclude=['ez_setup']), - include_package_data=True, - zip_safe=True, - install_requires=[ - 'lxml', - 'python-docx >= 0.8.8', - 'setuptools', - 'six', - 'babel', - ], - extras_require={ - 'test': tests_require, - 'tests': tests_require, - }, - entry_points={ - 'console_scripts': [ - 'docxcompose = docxcompose.command:main' - ] - }, -) diff --git a/tests/test_properties.py b/tests/test_properties.py index 99250a9..c8ca766 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1,4 +1,5 @@ from datetime import datetime +from datetime import timezone from docx import Document from docx.opc.constants import RELATIONSHIP_TYPE as RT from docx.oxml import parse_xml @@ -763,12 +764,12 @@ def test_get_doc_properties(): assert props['Text Property'] == 'Foo Bar' assert props['Number Property'] == 123 assert props['Boolean Property'] is True - assert props['Date Property'] == datetime(2019, 6, 11, 10, 0) + assert props['Date Property'] == datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc) assert props.get('Text Property') == 'Foo Bar' assert props.get('Number Property') == 123 assert props.get('Boolean Property') is True - assert props.get('Date Property') == datetime(2019, 6, 11, 10, 0) + assert props.get('Date Property') == datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc) def test_get_doc_property_is_case_insensitive(): @@ -792,8 +793,8 @@ def test_add_doc_properties(): props.add('My Number Property', 123) assert props.get('My Number Property') == 123 - props.add('My Date Property', datetime(2019, 10, 23, 15, 44, 50)) - assert props.get('My Date Property') == datetime(2019, 10, 23, 15, 44, 50) + props.add('My Date Property', datetime(2019, 10, 23, 15, 44, 50, tzinfo=timezone.utc)) + assert props.get('My Date Property') == datetime(2019, 10, 23, 15, 44, 50, tzinfo=timezone.utc) def test_add_utf8_property(): @@ -817,8 +818,8 @@ def test_set_doc_properties(): props['Number Property'] = 456 assert props['Number Property'] == 456 - props['Date Property'] = datetime(2019, 10, 20, 12, 0) - assert props['Date Property'] == datetime(2019, 10, 20, 12, 0) + props['Date Property'] = datetime(2019, 10, 20, 12, 0, tzinfo=timezone.utc) + assert props['Date Property'] == datetime(2019, 10, 20, 12, 0, tzinfo=timezone.utc) def test_set_doc_property_is_case_insensitive(): @@ -913,7 +914,7 @@ def test_doc_properties_values(): props = CustomProperties(document) assert props.values() == [ - 'Foo Bar', 123, True, datetime(2019, 6, 11, 10, 0), 1.1] + 'Foo Bar', 123, True, datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc), 1.1] def test_doc_properties_items(): @@ -924,7 +925,7 @@ def test_doc_properties_items(): ('Text Property', 'Foo Bar'), ('Number Property', 123), ('Boolean Property', True), - ('Date Property', datetime(2019, 6, 11, 10, 0)), + ('Date Property', datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc)), ('Float Property', 1.1), ] @@ -933,7 +934,7 @@ def test_vt2value_value2vt_roundtrip(): assert vt2value(value2vt(42)) == 42 assert vt2value(value2vt(True)) is True assert vt2value(value2vt(1.1)) == pytest.approx(1.1) - dt = datetime(2019, 6, 11, 10, 0) + dt = datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc) assert vt2value(value2vt(dt)) == dt assert vt2value(value2vt(u'foo')) == u'foo' assert vt2value(value2vt(u'')) == u''