Skip to content

Commit a3a4593

Browse files
verawielemanscannyeupharisondrej-111brnstz
authored
Python openxml master (#11)
* pep8: fixes for latest version of flake8 * Also take care of a pesky warning from pytest when getting style by id. * test: upgrade mock helpers to autospec by default * docs: update header/footer analysis * docs: add user docs for header/footer * build: remove 2.6 testing on travis Python 2.6 seems to be no longer supported on travis.ci so we're letting it drop here. We're retaining testing on 2.6 in tox for now though. * rfctr: blacken selected items In preparation for moving to Python Black for standardized code layout, get the custom element mappings closer to Black style layout. * rfctr: modernize formatting * acpt: add scenarios for headers and footers * rfctr: Sections gets document_part To access header and footer parts, Section will need the document part and the source for that will be its Sections parent proxy. Add document_part as construction parameter for Sections and modify tests to suit. * rfctr: Section gets document_part * Modernize section unit test fixtures while in there. * sect: add Section.footer * sect: add Section.header * hdr: add _Header.is_linked_to_previous * hdr: add _Header._has_header_part * hdr: add _Header.is_linked_to_previous setter * hdr: add _Header._drop_header_part() * hdr: add DocumentPart.drop_header_part() * hdr: add _Header._add_header_part() * hdr: add DocumentPart.add_header_part() * hdr: add HeaderPart.new() * pkg: add OpcPackage.next_partname() * hdr: add HeaderPart._default_header_xml() * hdr: add _Header._element * hdr: add _Header._get_or_add_header_part() * hdr: add _Header._prior_header * hdr: add _Header._header_part * hdr: add DocumentPart.header_part() * hdr: add PartFactory loads HeaderPart * hdr: extract _BaseHeaderFooter Extract _BaseHeaderFooter as a common base class for _Header and _Footer to which common behaviors can be abstracted. * hdr: add _BaseHeaderFooter.is_linked_to_p.. getter * hdr: add _Footer._has_definition * hdr: add _BaseHeaderFooter.is_linked_to_p.. setter * hdr: extract _Header.is_linked_to_previous _Header can now rely on _BaseHeaderFooter for this behavior. * hdr: add _Footer._drop_definition() * hdr: add _Footer._add_definition() * hdr: add DocumentPart.add_footer_part() * hdr: add FooterPart.new() * hdr: add FooterPart._default_footer_xml() * hdr: add _BaseHeaderFooter._element * hdr: add _BaseHeaderFooter._get_or_add_definition() * hdr: add _Footer._prior_headerfooter * hdr: add _Footer._definition * hdr: add DocumentPart.footer_part() * hdr: add PartFactory loads FooterPart * acpt: add header /footer content insert scenarios * hdr: add _BaseHeaderFooter.part * hdr: add BaseStoryPart.get_style_id() * hdr: add BaseStoryPart._document_part * hdr: add BaseStoryPart.get_style() * hdr: add BaseStoryPart.new_pic_inline() This is essentially migrated "up" from DocumentPart, which now subclasses BaseStoryPart. * hdr: add BaseStoryPart.get_or_add_image() Also extract Package.get_or_add_image_part() to avoid BaseStoryPart and others having to know about ImageParts. * hdr: add BaseStoryPart.next_id * acpt: add odd-even-page-headers scenarios * hdr: add Settings.odd_and_even_pages_header_footer Getter side. * hdr: add Settings.odd_and_even_pages_head.. setter Add some namespace-prefix mappings that arise for the first time in headers. * acpt: add scenarios for Section.diff_first_page.. Add scenarios for Section.different_first_page_header_footer. * hdr: add Section.different_first_page_header_footr * hdr: add Section.different_first_page_hea.. setter * acpt: add scenarios for first/even header/footer * rfctr: _Header and _Footer take header/footer type In preparation for adding even-page and first-page header and footer properties, pass the WD_HEADER_FOOTER_INDEX member identifying the header or footer type (primary, first, even) to _Header and _Footer on construction. This will allow each of these classes to serve for all three header/footer types. * hdr: add Section.even_page_footer * hdr: add Section.even_page_header * hdr: add Section.first_page_footer * hdr: add Section.first_page_header * docs: add API docs for header/footer * doc: Document.add_section() strips hdr/ftr refs The implementation of `Document.add_section()` "clones" the previously last `w:sectPr` element to produce the `w:sectPr` for the new section. This has the effect of duplicating the header and footer references along with the rIds used to link them to their header or footer part. There have been no reports that this causes a problem, but in any case the correct behavior is to add a new section without any header or footer definitions, such that the new section "inherits" all header/footer definitions (and header/footer parts are not "reused"). Add code to remove all `w:headerReference` and `w:footerReference` elements from a "cloned" `w:sectPr` element when adding a section. * rfctr: extract default .docx template to directory Maintaining the default document template as a directory allows its individual parts (XML files) to be curated like code, with line-changes tracked by Git. Extract the default template to a directory and load that directory as the default when no template document is specified to the `Document()` constructor. Also add Header and Footer styles. * release: prepare v0.8.8 release * release: prepare v0.8.9 release * release: prepare v0.8.10 release * fix: tweak setup.py handling of template directory Also some pending documentation updates and some Black changes. * fix: miscellaneous small Python 3 build-time fixes * Add 'zip_safe' == False to setup.py * fix: documentation fixes * black: blacken setup.py This produces a lot of line changes for single to double quotes, but no logic changes were made. * release: prepare v0.8.11 release Co-authored-by: Steve Canny <stcanny@gmail.com> Co-authored-by: eupharis <dan@highwaterlabs.com> Co-authored-by: Ondrej Zoričák <1ondrej.zoricak@gmail.com> Co-authored-by: Brian Seitz <brnstz@gmail.com>
1 parent 40f5aef commit a3a4593

103 files changed

Lines changed: 28029 additions & 1398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/docs/.build/
44
/*.egg-info
55
*.pyc
6+
.pytest_cache/
67
_scratch/
78
Session.vim
89
/.tox/

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: python
22
python:
3+
- "3.8"
34
- "3.6"
4-
- "3.5"
55
- "2.7"
6-
- "2.6"
76
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
87
install: pip install -r requirements.txt
98
# command to run tests, e.g. python setup.py test

HISTORY.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
Release History
44
---------------
55

6+
0.8.11 (2021-05-15)
7+
+++++++++++++++++++
8+
9+
- Small build changes and Python 3.8 version changes like collections.abc location.
10+
11+
12+
0.8.10 (2019-01-08)
13+
+++++++++++++++++++
14+
15+
- Revert use of expanded package directory for default.docx to work around setup.py
16+
problem with filenames containing square brackets.
17+
18+
19+
0.8.9 (2019-01-08)
20+
++++++++++++++++++
21+
22+
- Fix gap in MANIFEST.in that excluded default document template directory
23+
24+
25+
0.8.8 (2019-01-07)
26+
++++++++++++++++++
27+
28+
- Add support for headers and footers
29+
30+
631
0.8.7 (2018-08-18)
732
++++++++++++++++++
833

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include HISTORY.rst LICENSE README.rst tox.ini
2-
graft docx/templates *
2+
graft docx/templates
33
graft features
44
graft tests
55
graft docs

docs/_static/img/hdrftr-01.png

55.4 KB
Loading

docs/_static/img/hdrftr-02.png

15.8 KB
Loading

docs/api/enum/WdLineSpacing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Example::
1010
from docx.enum.text import WD_LINE_SPACING
1111

1212
paragraph = document.add_paragraph()
13-
paragraph.line_spacing_rule = WD_LINE_SPACING.EXACTLY
13+
paragraph.paragraph_format.line_spacing_rule = WD_LINE_SPACING.EXACTLY
1414

1515
----
1616

docs/api/section.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ Provides access to section properties such as margins and page orientation.
2222

2323

2424
.. autoclass:: Section
25-
:members:
25+
:members:
26+
27+
28+
|_Header| and |_Footer| objects
29+
-------------------------------
30+
31+
32+
.. autoclass:: _Header()
33+
:inherited-members:
34+
:members:
35+
:exclude-members: part
36+
37+
38+
.. autoclass:: _Footer()
39+
:inherited-members:
40+
:members:
41+
:exclude-members: part

docs/api/style.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Style-related objects
66

77
A style is used to collect a set of formatting properties under a single name
88
and apply those properties to a content object all at once. This promotes
9-
formatting consistency thoroughout a document and across related documents
9+
formatting consistency throughout a document and across related documents
1010
and allows formatting changes to be made globally by changing the definition
1111
in the appropriate style.
1212

docs/conf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# documentation root, use os.path.abspath to make it absolute, like shown here.
2121
sys.path.insert(0, os.path.abspath('..'))
2222

23-
from docx import __version__
23+
from docx import __version__ # noqa
2424

2525

2626
# -- General configuration ---------------------------------------------------
@@ -107,6 +107,16 @@
107107
108108
.. |Font| replace:: :class:`.Font`
109109
110+
.. |_Footer| replace:: :class:`._Footer`
111+
112+
.. |FooterPart| replace:: :class:`.FooterPart`
113+
114+
.. |_Header| replace:: :class:`._Header`
115+
116+
.. |HeaderPart| replace:: :class:`.HeaderPart`
117+
118+
.. |ImageParts| replace:: :class:`.ImageParts`
119+
110120
.. |Inches| replace:: :class:`.Inches`
111121
112122
.. |InlineShape| replace:: :class:`.InlineShape`

0 commit comments

Comments
 (0)