Skip to content

Commit bdba970

Browse files
committed
Move nbconvert templates setup from core to server
1 parent ff237e4 commit bdba970

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

pytest_jupyter/jupyter_core.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import jupyter_core.paths
55
import os
66
import pytest
7-
import shutil
87
import sys
98

109
from .utils import mkdir
@@ -74,18 +73,6 @@ def jp_environ(
7473
"""Configures a temporary environment based on Jupyter-specific environment variables. """
7574
monkeypatch.setenv("HOME", str(jp_home_dir))
7675
monkeypatch.setenv("PYTHONPATH", os.pathsep.join(sys.path))
77-
78-
# Get path to nbconvert template directory *before*
79-
# monkeypatching the paths env variable.
80-
possible_paths = jupyter_core.paths.jupyter_path('nbconvert', 'templates')
81-
nbconvert_path = None
82-
for path in possible_paths:
83-
if os.path.exists(path):
84-
nbconvert_path = path
85-
break
86-
87-
nbconvert_target = jp_data_dir / 'nbconvert' / 'templates'
88-
8976
# monkeypatch.setenv("JUPYTER_NO_CONFIG", "1")
9077
monkeypatch.setenv("JUPYTER_CONFIG_DIR", str(jp_config_dir))
9178
monkeypatch.setenv("JUPYTER_DATA_DIR", str(jp_data_dir))
@@ -98,7 +85,3 @@ def jp_environ(
9885
jupyter_core.paths, "SYSTEM_CONFIG_PATH", [str(jp_system_config_path)]
9986
)
10087
monkeypatch.setattr(jupyter_core.paths, "ENV_CONFIG_PATH", [str(jp_env_config_path)])
101-
102-
# copy nbconvert templates to new tmp data_dir.
103-
if nbconvert_path:
104-
shutil.copytree(nbconvert_path, str(nbconvert_target))

pytest_jupyter/jupyter_server.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
import jupyter_core.paths
45
import nbformat
56
import os
67
import json
78
import pytest
8-
9-
from binascii import hexlify
10-
11-
import urllib.parse
9+
import shutil
1210
import tornado
13-
from tornado.escape import url_escape
14-
15-
from traitlets.config import Config
11+
import urllib.parse
1612

13+
from binascii import hexlify
1714
from jupyter_server.extension import serverextension
1815
from jupyter_server.serverapp import ServerApp
1916
from jupyter_server.utils import url_path_join
2017
from jupyter_server.services.contents.filemanager import FileContentsManager
21-
18+
from tornado.escape import url_escape
19+
from traitlets.config import Config
2220

2321
from .utils import mkdir
2422

@@ -78,8 +76,29 @@ def jp_http_port(http_server_port):
7876
return http_server_port[-1]
7977

8078

79+
@pytest.fixture
80+
def jp_setup_templates(jp_data_dir):
81+
"""Setups up a temporary directory consisting of the nbconvert templates."""
82+
83+
# Get path to nbconvert template directory *before*
84+
# monkeypatching the paths env variable via the jp_environ fixture.
85+
possible_paths = jupyter_core.paths.jupyter_path('nbconvert', 'templates')
86+
nbconvert_path = None
87+
for path in possible_paths:
88+
if os.path.exists(path):
89+
nbconvert_path = path
90+
break
91+
92+
nbconvert_target = jp_data_dir / 'nbconvert' / 'templates'
93+
94+
# copy nbconvert templates to new tmp data_dir.
95+
if nbconvert_path:
96+
shutil.copytree(nbconvert_path, str(nbconvert_target))
97+
98+
8199
@pytest.fixture(scope='function')
82100
def jp_configurable_serverapp(
101+
jp_setup_templates, # this fixture must preceed jp_environ
83102
jp_environ,
84103
jp_server_config,
85104
jp_argv,

0 commit comments

Comments
 (0)