Skip to content

Commit 4086140

Browse files
author
Eric Lapouyade
committed
black
1 parent 9392b06 commit 4086140

File tree

9 files changed

+448
-250
lines changed

9 files changed

+448
-250
lines changed

.github/workflows/codestyle.yml

Lines changed: 1 addition & 1 deletion
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.7', '3.8', '3.9', '3.10']
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 }}

Pipfile.lock

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

docs/conf.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@
2626
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2727
# ones.
2828
extensions = [
29-
'sphinx.ext.autodoc',
29+
"sphinx.ext.autodoc",
3030
]
3131

3232
# Add any paths that contain templates here, relative to this directory.
33-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3434

3535
# The suffix of source filenames.
36-
source_suffix = '.rst'
36+
source_suffix = ".rst"
3737

3838
# The encoding of source files.
3939
# source_encoding = 'utf-8-sig'
4040

4141
# The master toctree document.
42-
master_doc = 'index'
42+
master_doc = "index"
4343

4444
# General information about the project.
45-
project = u'python-docx-template'
46-
copyright = u'2015, Eric Lapouyade'
45+
project = "python-docx-template"
46+
copyright = "2015, Eric Lapouyade"
4747

4848
# The version info for the project you're documenting, acts as replacement for
4949
# |version| and |release|, also used in various other places throughout the
5050
# built documents.
5151
#
5252
# The short X.Y version.
53-
version = '0.9'
53+
version = "0.9"
5454
# The full version, including alpha/beta/rc tags.
55-
release = '0.9.x'
55+
release = "0.9.x"
5656

5757
# The language for content autogenerated by Sphinx. Refer to documentation
5858
# for a list of supported languages.
@@ -66,7 +66,7 @@
6666

6767
# List of patterns, relative to source directory, that match files and
6868
# directories to ignore when looking for source files.
69-
exclude_patterns = ['_build']
69+
exclude_patterns = ["_build"]
7070

7171
# The reST default role (used for this markup: `text`) to use for all
7272
# documents.
@@ -84,7 +84,7 @@
8484
# show_authors = False
8585

8686
# The name of the Pygments (syntax highlighting) style to use.
87-
pygments_style = 'sphinx'
87+
pygments_style = "sphinx"
8888

8989
# A list of ignored prefixes for module index sorting.
9090
# modindex_common_prefix = []
@@ -97,7 +97,7 @@
9797

9898
# The theme to use for HTML and HTML Help pages. See the documentation for
9999
# a list of builtin themes.
100-
html_theme = 'default'
100+
html_theme = "default"
101101

102102
# Theme options are theme-specific and customize the look and feel of a theme
103103
# further. For a list of options available for each theme, see the
@@ -126,7 +126,7 @@
126126
# Add any paths that contain custom static files (such as style sheets) here,
127127
# relative to this directory. They are copied after the builtin static files,
128128
# so a file named "default.css" will overwrite the builtin "default.css".
129-
html_static_path = ['_static']
129+
html_static_path = ["_static"]
130130

131131
# Add any extra paths that contain custom files (such as robots.txt or
132132
# .htaccess) here, relative to this directory. These files are copied
@@ -175,7 +175,7 @@
175175
# html_file_suffix = None
176176

177177
# Output file base name for HTML help builder.
178-
htmlhelp_basename = 'python-docx-templatedoc'
178+
htmlhelp_basename = "python-docx-templatedoc"
179179

180180

181181
# -- Options for LaTeX output ---------------------------------------------
@@ -193,8 +193,13 @@
193193
# (source start file, target name, title,
194194
# author, documentclass [howto, manual, or own class]).
195195
latex_documents = [
196-
('index', 'python-docx-template.tex', u'python-docx-template Documentation',
197-
u'Eric Lapouyade', 'manual'),
196+
(
197+
"index",
198+
"python-docx-template.tex",
199+
"python-docx-template Documentation",
200+
"Eric Lapouyade",
201+
"manual",
202+
),
198203
]
199204

200205
# The name of an image file (relative to this directory) to place at the top of
@@ -223,8 +228,13 @@
223228
# One entry per manual page. List of tuples
224229
# (source start file, name, description, authors, manual section).
225230
man_pages = [
226-
('index', 'python-docx-template', u'python-docx-template Documentation',
227-
[u'Eric Lapouyade'], 1)
231+
(
232+
"index",
233+
"python-docx-template",
234+
"python-docx-template Documentation",
235+
["Eric Lapouyade"],
236+
1,
237+
)
228238
]
229239

230240
# If true, show URL addresses after external links.
@@ -237,9 +247,15 @@
237247
# (source start file, target name, title, author,
238248
# dir menu entry, description, category)
239249
texinfo_documents = [
240-
('index', 'python-docx-template', u'python-docx-template Documentation',
241-
u'Eric Lapouyade', 'python-docx-template', 'One line description of project.',
242-
'Miscellaneous'),
250+
(
251+
"index",
252+
"python-docx-template",
253+
"python-docx-template Documentation",
254+
"Eric Lapouyade",
255+
"python-docx-template",
256+
"One line description of project.",
257+
"Miscellaneous",
258+
),
243259
]
244260

245261
# Documents to append as an appendix to all manuals.

docxtpl/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def check_exists_ask_overwrite(arg_value, overwrite):
7878
if os.path.exists(arg_value) and not overwrite:
7979
try:
8080
msg = (
81-
"File %s already exists, would you like to overwrite the existing file? (y/n)"
82-
% arg_value
81+
"File %s already exists, would you like to overwrite the existing file? "
82+
"(y/n)" % arg_value
8383
)
8484
if input(msg).lower() == "y":
8585
return True
@@ -115,9 +115,8 @@ def get_json_data(json_path):
115115
return json_data
116116
except json.JSONDecodeError as e:
117117
print(
118-
"There was an error on line {e.lineno}, column {e.colno} while trying to parse file {json_path}".format(
119-
e=e, json_path=json_path
120-
)
118+
"There was an error on line {e.lineno}, column {e.colno} while trying "
119+
"to parse file {json_path}".format(e=e, json_path=json_path)
121120
)
122121
raise RuntimeError("Failed to get json data.")
123122

docxtpl/template.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ def cellbg(m):
195195
src_xml = re.sub(pat, r"\1 \2", src_xml, flags=re.DOTALL)
196196

197197
# add vMerge
198-
# use {% vm %} to make this table cell and its copies be vertically merged within a {% for %}
198+
# use {% vm %} to make this table cell and its copies
199+
# be vertically merged within a {% for %}
199200
def v_merge_tc(m):
200201
def v_merge(m1):
201202
return (
@@ -864,7 +865,8 @@ def _replace_docx_part_pics(self, doc_part, replaced_pics):
864865
replaced_pics[img_id] = True
865866
break
866867

867-
# FIXME: figure out what exceptions are thrown here and catch more specific exceptions
868+
# FIXME: figure out what exceptions are thrown here
869+
# and catch more specific exceptions
868870
except Exception:
869871
continue
870872

setup.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
def read(*names):
1111
values = dict()
1212
for name in names:
13-
filename = name + '.rst'
13+
filename = name + ".rst"
1414
if os.path.isfile(filename):
1515
fd = open(filename)
1616
value = fd.read()
1717
fd.close()
1818
else:
19-
value = ''
19+
value = ""
2020
values[name] = value
2121
return values
2222

@@ -27,13 +27,15 @@ def read(*names):
2727
News
2828
====
2929
%(CHANGES)s
30-
""" % read('README', 'CHANGES')
30+
""" % read(
31+
"README", "CHANGES"
32+
)
3133

3234

3335
def get_version(pkg):
34-
path = os.path.join(os.path.dirname(__file__), pkg, '__init__.py')
36+
path = os.path.join(os.path.dirname(__file__), pkg, "__init__.py")
3537
if sys.version_info >= (3, 0):
36-
fh = open(path, encoding='utf-8') # required to read utf-8 file on windows
38+
fh = open(path, encoding="utf-8") # required to read utf-8 file on windows
3739
else:
3840
fh = open(path) # encoding parameter does not exist in python 2
3941
with fh:
@@ -43,30 +45,29 @@ def get_version(pkg):
4345
raise RuntimeError("Unable to find __version__ string in %s." % path)
4446

4547

46-
setup(name='docxtpl',
47-
version=get_version('docxtpl'),
48-
description='Python docx template engine',
49-
long_description=long_description,
50-
classifiers=[
51-
"Intended Audience :: Developers",
52-
"Development Status :: 4 - Beta",
53-
"Programming Language :: Python :: 3",
54-
"Programming Language :: Python :: 3.7",
55-
"Programming Language :: Python :: 3.8",
56-
"Programming Language :: Python :: 3.9",
57-
"Programming Language :: Python :: 3.10",
58-
"Programming Language :: Python :: 3.11",
59-
"Programming Language :: Python :: 3.12",
60-
],
61-
keywords='jinja2',
62-
url='https://github.com/elapouya/python-docx-template',
63-
author='Eric Lapouyade',
64-
license='LGPL 2.1',
65-
packages=['docxtpl'],
66-
install_requires=['python-docx>=1.1.1',
67-
'docxcompose',
68-
'jinja2',
69-
'lxml'],
70-
extras_require={'docs': ['Sphinx', 'sphinxcontrib-napoleon']},
71-
eager_resources=['docs'],
72-
zip_safe=False)
48+
setup(
49+
name="docxtpl",
50+
version=get_version("docxtpl"),
51+
description="Python docx template engine",
52+
long_description=long_description,
53+
classifiers=[
54+
"Intended Audience :: Developers",
55+
"Development Status :: 4 - Beta",
56+
"Programming Language :: Python :: 3",
57+
"Programming Language :: Python :: 3.7",
58+
"Programming Language :: Python :: 3.8",
59+
"Programming Language :: Python :: 3.9",
60+
"Programming Language :: Python :: 3.10",
61+
"Programming Language :: Python :: 3.11",
62+
"Programming Language :: Python :: 3.12",
63+
],
64+
keywords="jinja2",
65+
url="https://github.com/elapouya/python-docx-template",
66+
author="Eric Lapouyade",
67+
license="LGPL 2.1",
68+
packages=["docxtpl"],
69+
install_requires=["python-docx>=1.1.1", "docxcompose", "jinja2", "lxml"],
70+
extras_require={"docs": ["Sphinx", "sphinxcontrib-napoleon"]},
71+
eager_resources=["docs"],
72+
zip_safe=False,
73+
)

tests/footnotes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
tpl = DocxTemplate("templates/footnotes_tpl.docx")
1313

14-
context = {
15-
"a_jinja_variable": "A Jinja variable!"
16-
}
14+
context = {"a_jinja_variable": "A Jinja variable!"}
1715

1816
tpl.render(context)
1917
tpl.save(DEST_FILE)

tests/inline_image.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@
2525
},
2626
{
2727
"image": InlineImage(tpl, "templates/zope.png", height=Mm(10)),
28-
"desc": "Zope is a leading Open Source Application Server and Content Management Framework",
28+
"desc": "Zope is a leading Open Source Application Server "
29+
"and Content Management Framework",
2930
},
3031
{
3132
"image": InlineImage(tpl, "templates/pyramid.png", height=Mm(10)),
32-
"desc": "Pyramid is a lightweight Python web framework aimed at taking small web apps into big web apps.",
33+
"desc": "Pyramid is a lightweight Python web framework aimed at taking "
34+
"small web apps into big web apps.",
3335
},
3436
{
3537
"image": InlineImage(tpl, "templates/bottle.png", height=Mm(10)),
36-
"desc": "Bottle is a fast, simple and lightweight WSGI micro web-framework for Python",
38+
"desc": "Bottle is a fast, simple and lightweight WSGI micro web-framework "
39+
"for Python",
3740
},
3841
{
3942
"image": InlineImage(tpl, "templates/tornado.png", height=Mm(10)),
40-
"desc": "Tornado is a Python web framework and asynchronous networking library.",
43+
"desc": "Tornado is a Python web framework and asynchronous networking "
44+
"library.",
4145
},
4246
],
4347
}

tests/richtextparagraph.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@
1111
rtp = RichTextParagraph()
1212
rt = RichText()
1313

14-
rtp.add("The rich text paragraph function allows paragraph styles to be added to text",parastyle="myrichparastyle")
14+
rtp.add(
15+
"The rich text paragraph function allows paragraph styles to be added to text",
16+
parastyle="myrichparastyle",
17+
)
1518
rtp.add("Any built in paragraph style can be used", parastyle="IntenseQuote")
16-
rtp.add("or you can add your own, unlocking all style options", parastyle="createdStyle")
17-
rtp.add("To use, just create a style in your template word doc with the formatting you want and call it in the code.", parastyle="normal")
18-
19-
rtp.add("This allows for the use of")
19+
rtp.add(
20+
"or you can add your own, unlocking all style options", parastyle="createdStyle"
21+
)
22+
rtp.add(
23+
"To use, just create a style in your template word doc with the formatting you want "
24+
"and call it in the code.",
25+
parastyle="normal",
26+
)
27+
28+
rtp.add("This allows for the use of")
2029
rtp.add("custom bullet\apoints", parastyle="SquareBullet")
2130
rtp.add("Numbered Bullet Points", parastyle="BasicNumbered")
2231
rtp.add("and Alpha Bullet Points.", parastyle="alphaBracketNumbering")
2332
rtp.add("You can", parastyle="normal")
2433
rtp.add("set the", parastyle="centerAlign")
2534
rtp.add("text alignment", parastyle="rightAlign")
26-
rtp.add("as well as the spacing between lines of text. Like this for example, this text has very tight spacing between the lines.\aIt also has no space between paragraphs of the same style.", parastyle="TightLineSpacing")
27-
rtp.add("Unlike this one, which has extra large spacing between lines for when you want to space things out a bit or just write a little less.", parastyle="WideLineSpacing")
28-
rtp.add("You can also set the background colour of a line.", parastyle="LineShadingGreen")
35+
rtp.add(
36+
"as well as the spacing between lines of text. Like this for example, "
37+
"this text has very tight spacing between the lines.\aIt also has no space between "
38+
"paragraphs of the same style.",
39+
parastyle="TightLineSpacing",
40+
)
41+
rtp.add(
42+
"Unlike this one, which has extra large spacing between lines for when you want to "
43+
"space things out a bit or just write a little less.",
44+
parastyle="WideLineSpacing",
45+
)
46+
rtp.add(
47+
"You can also set the background colour of a line.", parastyle="LineShadingGreen"
48+
)
2949

3050
rt.add("This works with ")
3151
rt.add("Rich ", bold=True)
@@ -40,4 +60,4 @@
4060
}
4161

4262
tpl.render(context)
43-
tpl.save("output/richtext_paragraph.docx")
63+
tpl.save("output/richtext_paragraph.docx")

0 commit comments

Comments
 (0)