Skip to content

Commit f96b0b6

Browse files
authored
Merge pull request #617 from waketzheng/project-section
feat: use project section
2 parents d9bb19c + 560b4b3 commit f96b0b6

8 files changed

Lines changed: 718 additions & 905 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

poetry.lock

Lines changed: 631 additions & 882 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
1-
[tool.poetry]
1+
[project]
22
name = "docxtpl"
3-
version = "0.17.0"
3+
dynamic = ["version"]
44
description = "Python docx template engine"
5-
authors = ["Eric Lapouyade"]
5+
authors = [{name="Eric Lapouyade", email="elapouya@proton.me"}]
66
readme = "README.rst"
7+
requires-python = ">=3.7"
8+
license = {text="LGPL-2.1-only"}
9+
classifiers=[
10+
"Intended Audience :: Developers",
11+
"Development Status :: 4 - Beta",
12+
"Programming Language :: Python :: 3",
13+
"Programming Language :: Python :: 3.7",
14+
"Programming Language :: Python :: 3.8",
15+
"Programming Language :: Python :: 3.9",
16+
"Programming Language :: Python :: 3.10",
17+
"Programming Language :: Python :: 3.11",
18+
"Programming Language :: Python :: 3.12",
19+
"Programming Language :: Python :: 3.13",
20+
]
21+
keywords = ["jinja2"]
22+
dependencies = [
23+
"python-docx",
24+
"jinja2",
25+
"lxml",
26+
]
27+
28+
[project.optional-dependencies]
29+
subdoc = ["docxcompose"]
30+
docs = ["Sphinx", "sphinxcontrib-napoleon"]
31+
32+
[dependency-groups]
33+
dev = [
34+
"mypy >=1.18.2; python_version >= '3.9'",
35+
"lxml-stubs >=0.5.1; python_version >= '3.9'",
36+
"flake8 >=7.3.0; python_version >= '3.9'"
37+
]
38+
39+
[project.urls]
40+
homepage = "https://github.com/elapouya/python-docx-template"
41+
repository = "https://github.com/elapouya/python-docx-template.git"
42+
document = "https://docxtpl.readthedocs.org"
43+
44+
[tool.poetry]
45+
version = "0.0.0"
46+
47+
[tool.poetry.requires-plugins]
48+
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
49+
50+
[tool.poetry-dynamic-versioning]
51+
enable = true
752

8-
[tool.poetry.dependencies]
9-
python = "^3.11"
10-
python-docx = "^1.1.2"
11-
docxcompose = "^1.4.0"
12-
jinja2 = "^3.1.4"
13-
black = "^24.4.2"
14-
twine = "^6.1.0"
53+
[tool.poetry-dynamic-versioning.from-file]
54+
source = "docxtpl/__init__.py"
55+
pattern = '__version__ = "(.+)"'
1556

57+
[tool.mypy]
58+
pretty = true
59+
python_version = "3.9"
60+
check_untyped_defs = true
61+
warn_unused_ignores = true
62+
exclude = ["docs", "build", "setup.py"]
1663

17-
[tool.poetry.group.dev.dependencies]
18-
flake8 = "^7.1.0"
64+
[[tool.mypy.overrides]]
65+
module = ["docxcompose.*"]
66+
ignore_missing_imports = true
1967

2068
[build-system]
21-
requires = ["poetry-core"]
22-
build-backend = "poetry.core.masonry.api"
69+
requires = ["poetry-core", "poetry-dynamic-versioning >=1.0.0,<2.0.0"]
70+
build-backend = "poetry_dynamic_versioning.backend"

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)