Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nbconflux for nbconvert>=6.0 #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions nbconflux/confluence.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- extends 'display_priority.tpl' -%}
{% from 'mathjax.tpl' import mathjax %}
{%- extends 'display_priority.j2' -%}
{% from 'mathjax.html.j2' import mathjax %}

{%- block header -%}
{%- if resources.generate_toc %}
Expand Down Expand Up @@ -202,28 +202,6 @@ unknown type {{ cell.type }}
<p><em>This page originated from the notebook <a href="{{ resources['attachments'][resources['notebook_filename']]['download_url'] }}">{{ resources['notebook_filename'] }}</a> which is attached to this page for safe keeping.</em></p>
{%- endif %}

<ac:structured-macro ac:macro-id="8250dedf-fcaa-48da-b12d-0f929c620dc4" ac:name="style" ac:schema-version="1">
<ac:parameter ac:name="import">https://nbviewer.jupyter.org/static/build/notebook.css</ac:parameter>
</ac:structured-macro>

<ac:structured-macro ac:macro-id="8250dedf-fcaa-48da-b12d-0f929c620dc4" ac:name="style" ac:schema-version="1">
<ac:plain-text-body><![CDATA[
a.anchor-link {
display: none !important;
}
body div.output_subarea {
max-width: none;
}
body.page-gadget #main {
width: auto;
}
body.page-gadget {
padding-top: 0;
}
]]>
</ac:plain-text-body>
</ac:structured-macro>

{%- if resources.enable_mathjax %}
<ac:structured-macro ac:macro-id="c5e95bac-43c5-4db4-abd0-af1dfcf97384" ac:name="html" ac:schema-version="1">
<ac:plain-text-body><![CDATA[
Expand Down
11 changes: 8 additions & 3 deletions nbconflux/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
XML storage format and posts it to an existing page.
"""
import os
import pathlib
import urllib.parse as urlparse

import requests
Expand Down Expand Up @@ -86,12 +87,16 @@ def __init__(self, config, **kwargs):
config.HTMLExporter.filters = {
'sanitize_html': sanitize_html,
}
tpfile = str(pathlib.Path(__file__).parent / 'confluence.tpl')
print(tpfile)
config.TemplateExporter.template_file = tpfile

super(ConfluenceExporter, self).__init__(config=config, **kwargs)
self._preprocessors[-1].exporter = self

self.template_path = [os.path.abspath(os.path.dirname(__file__))]
self.template_file = 'confluence'
for preprocessor in self._preprocessors:
if isinstance(preprocessor, ConfluencePreprocessor):
preprocessor.exporter = self

# Must be at least a single character, or the header generator produces
# an (invalid?) empty anchor tag that trips up bleach during
# sanitization
Expand Down
6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
bleach
html5lib
nbconvert>=5.3
requests
traitlets
-e .
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
author='Valassis Digital',
url='https://github.com/Valassis-Digital-Media/nbconflux',
url='https://github.com/vericast/nbconflux',
platforms=['Linux', 'Mac OSX', 'Windows'],
packages=find_packages(),
include_package_data = True,
Expand All @@ -28,7 +28,7 @@
},
install_requires=[
'bleach',
'nbconvert>=5.3',
'nbconvert>=6.0',
'requests',
'traitlets',
'html5lib',
Expand Down
3 changes: 3 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
log_cli=true
log_level=DEBUG
41 changes: 41 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import pathlib

from nbconflux import exporter
import traitlets.config

import pytest
import dotenv


def test_init():
c = traitlets.config.Config()
c.ConfluenceExporter.url = "https://confluence.test.com/pages/viewpage.action?pageId=314159"
exp = exporter.ConfluenceExporter(config=c)
assert exp.server == "https://confluence.test.com"
assert exp.page_id == 314159


@pytest.fixture
def config():
"""
This is a full integration test, against a confluence you have access to.

This should be populated for CI runs
"""
dotenv.load_dotenv()
c = traitlets.config.Config()

cpage = os.getenv("CONFLUENCE_TEST")
if not cpage:
pytest.skip("Requires $CONFLUENCE_TEST to be defined")
c.ConfluenceExporter.url = cpage

c.ConfluenceExporter.username = os.getenv("CONFLUENCE_USERNAME")
c.ConfluenceExporter.password = os.getenv("CONFLUENCE_PASSWORD")
return c


def test_upload(config):
exp = exporter.ConfluenceExporter(config=config)
exp.from_filename(pathlib.Path(__file__).parent / "notebooks/nbconflux-test.ipynb")