Skip to content

Commit

Permalink
Merge pull request #28 from mherkazandjian/develop
Browse files Browse the repository at this point in the history
Merge develop into master in order to remove develop
  • Loading branch information
mherkazandjian authored Nov 17, 2020
2 parents aa8c0c6 + 38ecf1b commit 6fcb642
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ To debug the build process

python -m pdb $(which sphinx-build) -b docx /path/to/src/dir /path/to/build/dir OTHER_SPHINX_OPTIONS_IF_ANY

To produce the ``.docx`` of any of the example files using the current
development docxsphinx source, e.g. the sphixn project ``sample_2``:

cd examples/sample_2
PYTHONPATH=../../src:$PYTHONPATH make docx -B

To profile e.g. ``sample_2``. Profiling is useful to see which sections
of the code are visited in the module ``src/docxsphinx/writer.py``

PYTHONPATH=../../src:$PYTHONPATH python3 -m cProfile -s calls \
$(which sphinx-build) -M docx \
source build/docx/ | grep writer.py | awk '{print $6}' \
| sort > calls

API
===
see also
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@
test_suite='nose.collector',
tests_require=['Nose'],
zip_safe=False,
entry_points={
'sphinx.builders': [
'docx=docxsphinx',
],
}
)
28 changes: 6 additions & 22 deletions src/docxsphinx/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

def dprint(_func=None, **kw):
"""Print debug information."""
logger.info('-'*50)
# noinspection PyProtectedMember
f = sys._getframe(1)
if kw:
Expand All @@ -47,7 +46,10 @@ def dprint(_func=None, **kw):
if _func is None:
_func = f.f_code.co_name

logger.info(' '.join([_func, text]))
# It would be nice to have the non-kw dprints to be debug-level' issues,
# but that does not seem to work.
if kw:
logger.info(' '.join([_func, text]))


# noinspection PyUnusedLocal
Expand Down Expand Up @@ -162,12 +164,10 @@ def new_state(self, location):
dprint()
self.old_states.append(self.current_state)
self.current_state = DocxState(location=location)
print("HB new_state: {}".format(len(self.old_states)))

def end_state(self, first=None):
dprint()
self.current_state = self.old_states.pop()
print("HB old_state: {}".format(len(self.old_states)))

def visit_start_of_file(self, node):
dprint()
Expand Down Expand Up @@ -533,8 +533,6 @@ def visit_tgroup(self, node):
dprint()
colspecs = [c for c in node.children if isinstance(c, nodes.colspec)]
self.current_state.ncolumns = len(colspecs)
print("HB VT {} {} {}".format(
self.current_state.ncolumns, len(node.children), [type(c) for c in node.children]))

def depart_tgroup(self, node):
dprint()
Expand Down Expand Up @@ -638,8 +636,8 @@ def visit_image(self, node):
dprint()
uri = node.attributes['uri']
file_path = os.path.join(self.builder.env.srcdir, uri)
# TODO implement this.
return
self.docx_container.add_picture(file_path) # width=Inches(1.25))
# .. todo:: 'width' keyword is not supported

def depart_image(self, node):
dprint()
Expand Down Expand Up @@ -703,21 +701,15 @@ def visit_list_item(self, node):
if not curloc.paragraphs[0].text:
# An empty paragraph is created when a Cell is created.
# Reuse this paragraph.
print("HB VLI reuse {}".format(style))
self.current_paragraph = curloc.paragraphs[0]
self.current_paragraph.style = style
else:
print("HB VLI create 1 {}".format(style))
self.current_paragraph = curloc.add_paragraph(style=style)
else:
print("HB VLI create 2 {}".format(style))
self.current_paragraph = curloc.add_paragraph(style=style)
else:
print("HB VLI create 3 {}".format(style))
self.current_paragraph = curloc.add_paragraph(style=style)

print("HB VLI end {}".format(self.current_paragraph.style))

def depart_list_item(self, node):
dprint()

Expand Down Expand Up @@ -922,7 +914,6 @@ def visit_paragraph(self, node):
curloc = self.current_state.location

if 'List' in self.current_paragraph.style.name and not self.current_paragraph.text:
print("HB VP List")
# This is the first paragraph in a list item, so do not create another one.
pass
elif isinstance(curloc, _Cell):
Expand All @@ -931,22 +922,16 @@ def visit_paragraph(self, node):
# An empty paragraph is created when a Cell is created.
# Reuse this paragraph.
self.current_paragraph = curloc.paragraphs[0]
print("HB VP cell reuse")
else:
self.current_paragraph = curloc.add_paragraph()
print("HB VP cell create 1")
else:
self.current_paragraph = curloc.add_paragraph()
print("HB VP cell create 2")
# HACK because the style is messed up, TODO FIX
self.current_paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.LEFT
self.current_paragraph.paragraph_format.left_indent = 0
else:
print("HB VP normal")
self.current_paragraph = curloc.add_paragraph()

print("HB VP end {}".format(self.current_paragraph.style))

def depart_paragraph(self, node):
dprint()

Expand Down Expand Up @@ -1121,7 +1106,6 @@ def visit_comment(self, node):
comment = node[0]
if 'DocxTableStyle' in comment:
self.current_state.table_style = comment.split('DocxTableStyle')[-1].strip()
print("HB tablestyle {}".format(self.current_state.table_style))
raise nodes.SkipNode

def visit_meta(self, node):
Expand Down

0 comments on commit 6fcb642

Please sign in to comment.