Skip to content

Commit 7a6ddbc

Browse files
committed
Move docxcompose to optional dependency
1 parent d9bb19c commit 7a6ddbc

6 files changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/codestyle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ['3.9', '3.10', '3.11','3.12','3.13']
10+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Set up Python ${{ matrix.python-version }}
@@ -22,4 +22,4 @@ jobs:
2222
run: |
2323
pip install flake8
2424
# stop the build if there are code styling problems. The GitHub editor is 127 chars wide.
25-
flake8 . --count --max-line-length=127 --show-source --statistics
25+
flake8 . --count --max-line-length=127 --show-source --statistics

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.20.2 *(Unreleased)*
2+
-------------------
3+
- Move docxcompose to optional dependency (Thanks to Waket Zheng)
4+
15
0.20.1 (2025-07-15)
26
-------------------
37
- Fix and improve get_undeclared_template_variables() method (Thanks to Pablo Esteban)

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ Please see tests/inline_image.py for an example.
286286
Sub-documents
287287
-------------
288288

289+
> Need to install with the subdoc extra: `pip install "docxtpl[subdoc]"`
290+
289291
A template variable can contain a complex subdoc object and be built from scratch using python-docx document methods.
290292
To do so, first, get the sub-document object from your template object, then use it by treating it as a python-docx document object.
291293
See example in `tests/subdoc.py`.

docxtpl/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
55
@author: Eric Lapouyade
66
"""
7+
78
__version__ = "0.20.1"
89

910
# flake8: noqa
1011
from .inline_image import InlineImage
1112
from .listing import Listing
1213
from .richtext import RichText, R, RichTextParagraph, RP
13-
from .subdoc import Subdoc
1414
from .template import DocxTemplate
15+
try:
16+
from .subdoc import Subdoc
17+
except ImportError:
18+
pass

docxtpl/template.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"""
77

88
from os import PathLike
9-
from typing import Any, Optional, IO, Union, Dict, Set
10-
from .subdoc import Subdoc
9+
from typing import TYPE_CHECKING, Any, Optional, IO, Union, Dict, Set
1110
import functools
1211
import io
1312
from lxml import etree
@@ -29,6 +28,9 @@
2928
import os
3029
import zipfile
3130

31+
if TYPE_CHECKING:
32+
from .subdoc import Subdoc
33+
3234

3335
class DocxTemplate(object):
3436
"""Class for managing docx files as they were jinja2 templates"""
@@ -610,7 +612,9 @@ def fix_docpr_ids(self, tree):
610612
self.docx_ids_index += 1
611613
elt.attrib["id"] = str(self.docx_ids_index)
612614

613-
def new_subdoc(self, docpath=None):
615+
def new_subdoc(self, docpath=None) -> Subdoc:
616+
from .subdoc import Subdoc
617+
614618
self.init_docx()
615619
return Subdoc(self, docpath)
616620

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from setuptools import setup
21
import os
32
import re
43
import sys
54

5+
from setuptools import setup
6+
67
# To register onto Pypi :
78
# python setup.py sdist bdist_wheel upload
89

@@ -61,15 +62,16 @@ def get_version(pkg):
6162
"Programming Language :: Python :: 3.10",
6263
"Programming Language :: Python :: 3.11",
6364
"Programming Language :: Python :: 3.12",
65+
"Programming Language :: Python :: 3.13",
6466
],
6567
keywords="jinja2",
6668
url="https://github.com/elapouya/python-docx-template",
6769
author="Eric Lapouyade",
6870
license="LGPL-2.1-only",
6971
license_files=[],
7072
packages=["docxtpl"],
71-
install_requires=["python-docx>=1.1.1", "docxcompose", "jinja2", "lxml"],
72-
extras_require={"docs": ["Sphinx", "sphinxcontrib-napoleon"]},
73+
install_requires=["python-docx>=1.1.1", "jinja2", "lxml"],
74+
extras_require={"docs": ["Sphinx", "sphinxcontrib-napoleon"], "subdoc": ["docxcompose"]},
7375
eager_resources=["docs"],
7476
zip_safe=False,
7577
)

0 commit comments

Comments
 (0)